Hello, welcome to NETVN channel
This video will show you how to create a backup server for your Nextcloud private storage cloud
With this approach, if the main Nextcloud server fails, the backup server will be replaced immediately
And so you can still connect to your cloud data
Until the main server is fixed, the cloud data is automatically synchronized
So your work is not interrupted even though one of the two servers is down
The data between the two servers is always synchronized in real time
In this video I use two servers using Ubuntu operating system
In this example the ip address of the primary cloud host is 10.11.32.129
The ip address of the backup Nextcloud server is 10.11.32.130
The virtual ip address for the two cloud servers is 10.11.32.202
First you create virtual ip address 10.11.32.202 for two servers with keepalived
You install keepalived on both primary and backup servers
After the installation is complete, create a new keepalived configuration file on both servers
Then you add the lines as above
You notice there is a difference between the two servers
One server is Master and one server is Backup
Priority is different, here main server has higher priority
You configure the virtual ip address on both servers to be the same 10.11.32.202
The main server has higher priorityaddress
so under normal conditions it will own a virtual ip address
Also you configure the same password on both servers
You use the key combination ctrl x then select Y to save and close the keepalived configuration file
One more thing you need to keep in mind is to select the interface that you want to assign a virtual ip address to it
Then you start the keepalived service on both servers
As I check, main server is using virtual ip address 10.11.32.202
I would check if the ip address is automatically assigned to the backup server by stopping the keepalived service on the primary server
You will see that the virtual ip address will be immediately assigned to the backup server
After checking, remember to start the keepalived service on the main server to return the virtual address to the main server
The next step is to install and configure the database on the two servers
You install the mariadb database software on both servers
Once mariadb is installed, open the configuration files on both servers and edit them as above
By default mariadb only allows use on the server itself, so you need to allow remote access to the database by removing the bind address configuration
You identify the database to distinguish between the two servers
Here I identify the database on the main server as 1
And the database identifier on the backup server is 2
Also you enable logging on both databases of the two servers
Don't forget to save your changes before closing the database configuration files
Next, I will show you how to synchronize the database between two servers
First you assume the database on the main server is primary and the database on the backup server is the server
On the main server you create a rep user account and grant replication permission
The backup server will use this repuser account to sync the database with the primary server
In addition, you need to add information about the database on the main server such as ip address,
username, password, log and position
Then you start the slave on the backup server and check the database slave status
If you see a message with the word Yes as above, you did it right
But so you can only synchronize the database from the main server to the backup server and not synchronize the database from the backup server to the main server
That is, treat the database on the backup server as the master and treat the database on the primary server as the slave
You just need to perform the same steps as in the previous step, but you need to update the ip address to 10.11.32.130
10.11.32.130
After the configuration is done, you start the slave mode on the main server and check the status
Just like the backup server, if the above appears on the main server, you did it right
At this point, the databases of the two servers are synchronized in real time
Any database changes on one server will be synced on the other
Next on any server you create a database for your cloud storage
Here I create a new database and name it nextcloud
Then create a new username ncuser, then grant permissions to the newly created nextcloud database
You can check on the other server and see that the database changes have been synced between the two servers
At this point I have finished the instructions on installing and configuring the database
Next step I will guide you to use Gluster to sync nextcloud folder between two servers
You install gluster on both primary and backup servers
After the installation is complete, start the gluster service
Next you enable the gluster service to make sure it still works when the server restarts
Before synchronizing folders together you need to peer-to-peer using gluster
You are peer-to-peer using the remote server's ip address
On the primary server you use the backup server's ip address for peer-to-peer connection
Here the ip address of the backup server is 10.11.32.130
After successful peer-to-peer connection, create a shared folder for both servers
The shared folder here I named vol1
After configuring the shared folder, you should check if it was successful or not on the backup server
Once you have a shared folder for the two servers, mount it where you will store nextcloud
To prevent the mount from being aborted if the server reboots, you update the mount with the file fstab
You update the ip address corresponding to each server
As in this example ip address of primary server is 10.11.32.129
and ip address of backup server is 10.11.32.130
After you have completed the fstab configuration, the mounts are maintained even if the server is restarted
Next you install PHP on both primary and backup servers
In addition, nextcloud also uses a lot of php modules, so you need to install it fully
Otherwise, error will occur when you use nextcloud storage cloud
You install php and php module packages on both servers
After installing PHP, download the latest Nextcloud file to the directory /var/www
To know which is the latest Nextcloud file, visit Nextcloud's homepage
As at the time of this video the latest version is 23.0.3
Because the two servers are peer-to-peer, the compressed Nextcloud file will appear on both servers
Next you extract the Nextcloud file and copy it to the current directory
After waiting for a while both servers will appear a new folder named Nextcloud
Don't forget to grant permissions to these folders
You would create a config file called nextcloud on both servers to tell apache where to store the nextcloud folder
Two nextcloud files on two servers with the same configuration
You update the virtual ip address for the config file
In this example, the virtual ip address is 10.11.32.202
Don't forget to save and close the config file you just created
To the last steps of the video when you want to access the cloud storage from the internet you will replace the virtual ip address with the domain name
Then enable the newly created configuration file on both servers
For the changes to take effect, restart apache2
Next, use any web browser and access the nextcloud storage cloud with a virtual ip address 10.11.32.202
Here you create a new admin account for your nextcloud
Then find the information about the previously created database to complete the nextcloud configuration
In the previous step I created a database named nextcloud, username is ncuser and password is 123456
123456
You use the above information so that nextcloud can connect to the database
You need a few minutes to wait for nextcloud to initialize the new storage cloud
I will delete all the data available on the cloud storage, then upload a new file for you to observe the data synchronization between the two servers
Like here I will upload an image file of a cat and we will see if it syncs with the backup server.
I will power off the main server, so the virtual ip address will be assigned to the backup server
When the main server is down, the backup server will be replaced immediately
As you can see your data has synced to the backup server
I will upload another photo file of the penguins
Will the data be synchronized when the main server is powered on?
Before testing that I would open the port on the router and use the domain name to access the private cloud hosting anywhere over the internet
You open port 80 and 443 on your router
The ip address to configure the port opening is a virtual ip address 10.11.32.202
Opening this port is very familiar on my YouTube channel NETVN, if you do not know, you can review the previous videos
Next, to get a domain name I use Duck DNS service
Also I have updated my public ip address for that domain
You watch the previous videos to know how to install duckdns on Ubuntu or refer to Duck DNS homepage for how to do it
Currently, I have prepared a domain name netvncloud.duckdns.org
By default, nextcloud only allows access from virtual ip addresses, so you need to add trusted domains
Here I allow access to cloud hosting from any domain name or ip address
You can also configure each domain name or each ip address if you want
As mentioned in the previous section, if you want to access your cloud storage from the internet you need to modify the nextcloud configuration file on both servers
You replace the virtual ip address with your domain name
You update the nextcloud configuration file on both primary and backup servers because this configuration file is not synchronized with each other
You save the changes, then restart apache2 for the changes to take effect
You open any web browser and access your private cloud hosting with your domain name
That way you can access your own cloud storage from anywhere over the internet
As you can see the image file of the penguin has appeared and so the data has been synchronized two-way between the two main servers and the backup server
Here I have started the main server and checked if the new data is synced or not
Data is important to you so you will encrypt communications by enabling https
If you have watched my previous videos you will be very familiar with how to enable https with letsencypt
After you have installed let's encrypt on both servers you configure them
First you configure on the main server, to avoid errors, you turn off the backup server
To configure encryption, update the domain name then fill in the requested information
You will be asked to enter your email address and then choose as I am doing to complete the communication encryption configuration
When you receive the congratulatory message, you have succeeded
Once you access your cloud storage, there will be a lock icon next to the address bar
But you only configured encryption on the primary server, now you configure it on the backup server
To avoid errors, turn off the main server and enable https on the backup server
You use the same command to configure on both servers
That's it, I have finished showing you how to build your own storage cloud with nextcloud
This way you will have a primary server and a backup server
If something goes wrong with one of the two servers, the other is replaced immediately, and data is synchronized in real time
Thus, your work is maintained continuously even though there is a problem
Thank you for watching, good luck
Don't forget to like and subscribe to NETVN channel
Once you've built your private cloud server, use nextcloud clients on your computer or smartphone to access the cloud from anywhere
With Nextcloud, in addition to cloud data storage, you can also add good applications to use