Actually, what is the text about?
How often do our expectations diverge in harsh reality?
So I, entering the
best technical university of the country in the department of information security, was counting on an exciting learning, a fun student life and, of course, an interesting practice. However, instead of deciphering ciphers (hello, Alan) and opening cryptexes (good evening, Robert), I had to tune the Nextcloud cloud on several servers combined into a cluster. And it turned out to be interesting!
“So what's the big deal?” You thought. Indeed, the problem is very, very trivial. However, when I searched the web for information on this issue, I still could not find a tutorial that would unite all parts of the setup together. Therefore, in order to save the time of the same network administration dummies, I am writing this article with your permission.
')
So, what we will get at the end is a small cloud of Nextcloud, which is based on a master server (yes, yes, of course we need a proxy. And several master servers. And a skill. If you are waiting for all of this, I apologize.) (in this case, 2) servers playing the role of a united, fault-tolerant storage, database.
A nice little cloud for such a small company.
Let's go
Initial conditions
First of all, we have to prepare the equipment (in my case VirtualBox, with three machines created in it).
Master - 192.168.0.105
Server1 - 192.168.0.108
Server2 - 192.168.0.109
1. Operating system - Ubuntu Server 16.04.
Machine parameters do not play a special role - to deploy our small cloud, the power of an average (very average) computer is sufficient. The inflated parameters of virtual machines can play a cruel joke with you - when I showed the practice on a university computer with four gigabytes of OP, the launch of the third machine led to the fall of the computer. Although, maybe this is the fault of the next custom Unix-system, which stood on it?
2. A working network.
If you, like me, are using VirtualBox, I advise you to specify “Network Bridge” in the network settings as the connection type. Thus, you can ping the server in the box from the main system and from other machines.
3. Good playlist (optional)
After the nth hour of dancing with a tambourine in search of the optimal solution (perhaps, I am still in the process), it became completely unbearable.
Cluster Setup
To get a fault-tolerant storage consisting of several servers, we need a cluster. I chose Gluster because I could find
excellent mana in Russian (!!) language.
Let's start with the installation.
Open the console of our server and enter the following:
sudo apt-get install python-software-properties
Then, connect to the repository:
sudo add-apt-repository ppa:gluster/glusterfs-3.8 sudo apt-get update
And finally, install:
sudo apt-get install glusterfs-server
We perform the same actions on the second (n-th) server.
Tip! (for Dummies)When I first encountered the configuration of servers in the VM, I was unpleasantly surprised by the lack of a common buffer between the guest and the main OS (although this was expected). Therefore, I used
Putti to communicate with the machines. Download, run putti.ekze. Before use, we do not forget to install openssh-server on the machines we are going to access:
sudo apt-get install openssh-server
I think the same client can be used when communicating with real machines. Or maybe it is better to eat?
So, Gluster is installed. Now, create a connection. But first, let's find out the ip-addresses of our servers:
ifconfig
Now we create, registering the following from the first server (before, having logged in as root):
gluster peer probe 192.168.0.109
peer probe: success.
Great, now we have 2 servers in a cluster. We perform this operation as many times as we want to combine the servers in a cluster, changing only the ip-address of the server.
The storage we create using Glusterfs has several types of content storage (for more information, see the link above). We are interested in replicated - the content is mirrored to all servers in the cluster.
So far, we have nowhere to store data, so create folders on our servers:
on the first:
mkdir /mnt/server1
and on the second:
mkdir /mnt/server2
The final part of the cluster - create storage:
gluster volume create nextcloud replica 2 transport tcp 192.168.0.108:/mnt/server1 192.168.0.109:/mnt/server2 force
where nextcloud is the name of our repository, and 2 is the number of servers in the cluster.
Do not forget about the word force at the end - you can get an error and long to puzzle, what's wrong?
Run:
gluster volume start nextcloud
Work with the cluster is almost complete. The rest is after installing the cloud.
Install Nextcloud
For this we need our master server. We go under the root of the rights and enjoy.
For installation you can use
this article. We reach Step 5. We stop.
Download the cloud archive:
cd ~ wget --no-check-certificate https://download.nextcloud.com/server/releases/nextcloud-11.0.0.tar.bz2 sudo tar -C /var/www -xvjf ~/nextcloud-11.0.0.tar.bz2 rm ~/nextcloud-11.0.0.tar.bz2
Create a couple of folders:
sudo mkdir /var/www/nextcloud/data sudo mkdir /var/www/nextcloud/assets
The most crucial moment. We recall our cluster and connect it to the master server:
mount.glusterfs 192.168.0.108:/nextcloud /var/www/nextcloud/data/
Now all files that fall into our cloud will be copied to all servers.
Finish the installation, following the tips from the article.
What is the result?
Well, what did we do? And it turned out a small cloud, which is fail-safe to crash the servers that store data - try to drop one of them specifically - the wizard will think a little and everything will work again. When the fallen server is restored, the data on it will automatically be updated.
Of course, the bottleneck is the master server. The presence of several wizards working with one database, running, for example, Galera and a proxy server responsible for distributing traffic between them, would significantly increase the fault tolerance of the system (although it is unlikely now you can call it that). Maybe in the next article?
If you have read up to this point
you are a hero - thank you very much for your attention.
For a nice community - nice to write.