I already have a public subnet on my geeklab so the first step is to create a new VM for Nextcloud and install a LAMP stack (Linux, Apache, MariaDB, PHP) ready to deploy the Nextcloud application.
This is pretty much a standard Ubuntu Server 20.04 LTS installation on a ESXi 7 virtual machine. I'm using dedicated disks for the the MariaDB database filesystem and also for the Nextcloud server filesystem which need to be provisioned during the VM build.
Contents
- Virtual Machine Definition
- Ubuntu Installation
- Initial Network Configuration
- Standard playbooks and initial backup
Virtual Machine Definition
This is a small installation. I'm expecting 4 users initially, maybe growing to 12-14 if related groups also want to make use of it. At least to start with I'm not expecting to implement the really big modules like Office or Talk - and they might be better on dedicated servers if the need ever arises - and I'll be surprised if there's ever more than two concurrent users.
On that basis a sizing of 1 vCPU and 700GB of RAM should be sufficient and it's easy enough to add more if needed. Current CPU utilisation on the host is minimal and RAM, while not abundant, is not yet at a utilisation level that is going to be a concern.
The only remaining question is the hostname and I've decided I'll use my own names for the OS and a logical hostname for the application so I can get started sooner.
The public subnet is already defined in ESXi, and I also have an existing datastore for virtual machines which is a pair of mirrored disks so we should be reasonably resilient.
| Item | Value | ||||||||||||||||||||
| VM Name | Proj_TestNextcloud | ||||||||||||||||||||
| Compatibility | ESXi 7.0 U2 | ||||||||||||||||||||
| OS Family | Ubuntu Linux (64 bit) | ||||||||||||||||||||
| VM Storage | VM Datastore 1 | ||||||||||||||||||||
| vCPU | 1 | ||||||||||||||||||||
| RAM | 1024 MB | ||||||||||||||||||||
| Disks |
|
||||||||||||||||||||
| SCSI | VMware Paravirtual | ||||||||||||||||||||
| Network 1 | VMXNET 3 on Public subnet |
A DVD is also provisioned for the duration of build to access the Ubuntu installation .iso file in the media datastore.
Ubuntu Installation
I'm still using Ubuntu 20.04 LTS as the default base install. It'll be in support untill 2025 although some of the applications in the universe repository are very out of date already. Which is ironic given was the dropping of Bacula from Ubuntu 22.04 LTS that is causing the issue. Given that Bacula is back in the non-LTS releases I can't see why they couldn't reinstate it for 22.04.01 LTS but that's a discussion for another day.
The basic installation steps for Ubuntu are the same as always:
- Language = English (UK)
- Use the original installer - although I should have an look at the updated one really.
- Keyboard = English (UK)
- Network = DHCPv4. I may change this later.
- Proxy = Unconfigured as I don't use one for outbound access (yet)
- Storage = Custom Storage Layout, see below
- Profile = Create my standard initial user for my basic config playbooks.
- SSH = Install OpenSSH server but don't import keys (my playbooks do that)
- Stop the automatic patch deployment
I'll apply all the patches later once initial config is complete. In practice I find it never actually stops patch deployment so I hard-reset the VM from the ESXi console and reboot. It's a bit harsh, but it's only ever killed it once. The alternative is waiting for quite some time for patches to be applied, and then hoping that my initial setup playbooks still work. Yuk.
The final step of the installation is to remove the swap file that's created by the installer even though we have a dedicated swap partition. As root edit the /etc/fstab file and either edit or comment out the line for the swap file. The line will refer to /swap.img. Either reboot again and then delete the /swap.img file, or use the swapoff command to disable swap, delete /swap.img file and then use swapon to re-enable swap. Personally I prefer the reboot method just to make confirm you've not messed up /etc/fstab. Maybe one day I'll add this to my automation playbooks.
[Skip to Network config]
Custom Storage Configuration for Nextcloud
While Ubuntu 20.04 LTS offers btrfs for the root filesystem it doesn't use subvolumes and changing that after installation is a bit of a pain (or to tell the truth, I ran out of patience trying to make it work) so I'm going back to using ext4 for since that allows the option to shrink the filesystem if needed. I also use separate root and /boot filesystems so that should the root filesystem fill completely it should still be possible to boot the server after the inevitable crash. I also use a dedicated disk for swap since it's reportedly faster than a swap file and with virtual disks it's easy to expand if ever needed and also reduces the risk of exhausting the root filesystem. Some swap is always worthwhile in case you ever have a runaway application - it can make the difference between slow performance or application failure.
MariaDB gets its own filesystem, which is formatted to XFS as that's a bit faster and that's inside an LVM2 volume group to allow the possibility of disk snapshots if ever needed. From prior experience using btrfs for a Nextcloud MariaDB database gives extremely poor performance so that's not an option.
Nextcloud itself is on a btrfs subvolume as not only is it fast it also means I can create snapshots for backup purposes so I'm not tying up the server for hour or risking application inconsistency.
At the Guided Storage Configuration screen select Custom storage layout

You will then be presented with a list of all four disks that were created during VM Definition.

Move to the /dev/sda device and select Add GPT Partition.

The first partition will be for the boot filesystem. Set the size to 512 MB and format as ext4 and set the mountpoint to /boot. When ready click Create. The installer will actually create this as the second partition /dev/sda2. The first partition will be a 1 MB bios_grub partition needed for the grub bootloader since the VMs are seen as BIOS based.
The second partition we need to create here (which will actually be the third) is the root partition so select Add GPT Partition again

but don't set a size as we want it to take all that's remaining. Set the format as ext4 and mount as / (root). Click Create
Now move to the /dev/sdb device and again select Add GPT Partition.

Leave the size blank to assign the entire disk and set the format to swap. Click Create to apply this.
For the next device /dev/sdc instead of formatting here go to Create volume group (LVM) instead. This will let us format /dev/sdc as an LVM2 physical volume (PV), create and assign it to an LVM volume group (vg) and then finally create an LVM logical volume (LV) where we'll create the actual filesystem. Saves a lot of mucking about manually configuring at the command line.

Give it a name such as vg_mysql and select /dev/sdc as the device to use and since we don't want to encrypt this so just click on Create.

We can then create our logical volme which I called lv_mysql. Leave the size blank to assign all the space in volume group. Set the format to XFS and set the mount to Other and give the path /var/lib/mysql which is the default location for mysql databases. Click Create when ready.
If I decide to enable disk-based snapshots later I'll need to expand the /dev/sdc device and the vg_mysql volume group to allow space for snaphot delta, otherwise I would have set the LV size to be about 80% to 90% of the volume.
For the last disk /dev/sdd select Format instead of Add GPT Partition.

Despite what Ubuntu says, directly formatting for btrfs is now considered the way to do it by many, and even Ubuntu formats the entire disk as an LVM2 volume instead of creating a partition first so it's not that unusual.
Set the format to btrfs and mount to Other and set the actual path as /srv/nextcloud. We will have to make a small adjustment to this later to create a root subvolume. Click Done when ready.
At this point we should now have five filesystems defined, plus the hidden bios_grub.


Click Continue to format the disks, and again on the confirm screen to apply the disk formatting and complete the rest of the installation.
Network Configuration
The public subnet is a bit special since the VMs here have exposure to the internet which carries some particular risks and the router itself is the default gateway and also handles DHCP and internal access via split-horizon DNS - more on that later.
I'm using a Draytek Vigor router on my home lab, which offers many more features than the standard ISP offerings. For the initial configuration I need to add the internal hostname to DNS, which in turn relies on a constant IP address.
So having logged into the router with admin rights we need to apply a first round of configuration.
IP Reservation
The server is using DHCP so this is simply a case of going into LAN > Bind IP to MAC, selecting the host from all the ones known in the ARP Table and picking a free address from the range assigned to the public subnet and clicking Update.
On the server itself either restart the DHCP client with sudo dhclient -r; dhclient or just reboot it.
Or of course configure a static IP on the host itself but then it won't pick up and DHCP options and especially with test machines that might come and go there is a risk is you might end up with the same IP on two machines which will cause a problem when the second one is started.
Internal DNS
At this point we hadn't settled on the full DNS name for the Nextcloud instance. This isn't critical (yet) as we can - and really should - use separate names for the host as this gives me the capability to create a new VM and Nextcloud installation and move the data across without impacting the users should the need arise.
Under Applications > LAN DNS / DNS Forwarding create a new entry for the host. Set the Type to LAN DNS and set the domain name to the full domain name of the host as you would see it internally. Finally add the IP address we reserved in Bind IP to MAC and click OK.
We don't need to worry about Alias Domain Names yet, and unless you've done something really complex no need to worry about same subnet reply or having multiple IPs.
Since I already have firewall rules in place to allow access for ping, SSH and HTTP/S from my house subnet to the public subnet at this point it should be possible to ping the host from my desktop and also connect using the hostname over SSH.
Standard Server Playbooks
As I've mentioned previously I've created an Ansible playbook [future article!] to do the routine post-installation tasks for my geeklab servers such as deploying signed SSH host keys, configuring SSH user keys, installing applications such as apcupsd so I get a graceful shutdown when the power goes off and also installing the Bacula client and deploying the server config so I can backup the data and configuration, default firewall rules etc.
Once these are complete - 2 hours manual effort in about 3 minutes - kick off a general update using sudo apt upgrade and go grab a coffee as there's now over 230 updates to apply. A reboot is required once they're deployed too.
Initial Backup
The final step is to take an initial OS backup now the server is built just in case I have an oops moment during configuration. Maybe even take an offline VM snapshot too.
Once that's done we're ready start installing Nextcloud itself in Test Nextcloud 26 Installation.