GlusterFS, is a multi-scalable file system for NAS initially developed by Gluster Inc. A Gluster would allow us to connect two machines that will write simultaneously on the same disc, agreeing on the writer.
Most of the GlusterFS functionalities are implemented as translators, including:
- Mirroring and file replication.
- Fragmentation of the files or Data striping.
- Load balancing for reading and writing files.
- Fault tolerant volumes.
- I/O planning and disk caching.
- The storage quotas.
In this tutorial, we will cluster using GlusterFS between two server machines that are using CentOS 7
0.- Requeriments
To make this turtorial we will use three computers with GNU/LINUX systems, must have at least 1gb of ram and use 64bits systems, also a separate hard disk in /dev/sdb.
Server 1:
- Hostname: gluster1.osradar.local
- O.S:Â CentOS 7
- Memory: 1gb
- Ip Address: 192.168.1.9
- Disk: 8gb /dev/sdb
Server 2:
- Hostname: gluster2.osradar.local
- O.S:Â CentOS 7
- Memory: 1gb
- Ip Address: 192.168.1.10
- Disk: 8gb /dev/sdb
1.- Configuring DNS (both nodes)
This first step is vital because GlusterFS uses name resolution to communicate between servers and clients. As root user you write to a terminal:
:~# nano /etc/hosts
And in the file it places the information of the nodes in the following way:
192.168.1.9 gluster1.osradar.local gluster1 192.168.1.10 gluster2.osradar.local gluster2
2.- Installing GlusterFS (both nodes)
To install Gluster we need to add its repository first, to do this, in a terminal we must write:
:~# yum install centos-release-gluster
When the package installation is complete, the repository will be added and we can now install GlusterFS.
:~# yum install glusterfs-server
Once the installation is complete, we can start the service:
:~# systemctl start glusterd :~# systemctl enable glusterd
The next thing to do is to modify the firewall settings:
:~# firewall-cmd --zone=public --add-rich-rule='rule family="ipv4" source address="IP_ADDRESS_HERE" accept' :~# firewall-cmd --reload
3.-Add a storage (both nodes)
Now we must prepare the second hard disk (/dev/sdb) to be used as a brick (basic storage unit in Gluster). We’ll do a partition there.
:~# fdisk /dev/sdb
To perform the process properly, write the options in this order
Command (m for help): n Select (default p): p Partition number (1-4, default 1): 1 press enter press enter Command (m for help): p Command (m for help): w
now we proceed to format the partition:
:~# mkfs.ext4 /dev/sdb1
Then we create a folder and mount the partition on it.
:~# mkdir -p /data/glusterfs :~# mount /dev/sdb1 /data/glusterfs
We make sure that the partition is automatically mounted at system boot:
:~# echo "/dev/sdb1 /data/glusterfs ext4 defaults 0 0" | tee --append /etc/fstab
4.-Configuring GlusterFS
The next step will be on node 1. tell Gluster that node 2 is trustworthy to build the cluster itself. To do this we must execute the following command:
:~# gluster peer probe gluster2.osradar.local
And then we verify that the other node has been added correctly with these commands:
:~# gluster peer status :~# gluster pool list
5.- Creating GlusterFS Volume
We create a folder on both nodes that will serve as the volume folder:
:~# mkdir -p /data/glusterfs/glustervolume
We now proceed to create the volume by indicating that you will use two mirrors in this case:
:~# gluster volume create glusterfsvolumne replica 2 gluster1.osradar.local:/data/glusterfs/glustervolume gluster2.osradar.local:/data/glusterfs/glustervolume
We start the volume:
:~# gluster volume start glusterfsvolumne
The installation and configuration of glusterfs on a server is now complete. We proceed to install the client on another machine.
GlusterFS client
Now it is the customer’s turn to use another CentOS 7 device with an IP address of 192.168.1.7. The other features of the device do not influence the use of the device.
We proceed to install the glusterfs-client package:
:~# yum install glusterfs-client
Once the installation is finished, we will create a folder to mount the volume.
:~# mkdir -p /mnt/glusterfsvolumne
we set up the firewall:
:~# firewall-cmd --zone=public --add-rich-rule='rule family="ipv4" source address="192.168.1.7" accept' :~# ffirewall-cmd --reload
And we mount the previously created glusterFs volume.
:~# mount -t glusterfs gluster1.osradar.local:/glusterfsvolumne /mnt/glusterfsvolumne
We checked the mounting:
df -hP /mnt/glusterfsvolumne/
we add the entry in fstab so that it is automatically mounted:
:~# echo "gluster1.osradar.local:/glusterfsvolumne /mnt/glusterfsvolumne/ glusterfs defaults,_netdev 0 0" | tee --append /etc/fstab
Testing the replication
First of all, in the server nodes, we execute the following commands:
On the first node (gluster1.osradar.local):
:~# mount -t glusterfs gluster2.osradar.local:/glusterfsvolumne /mnt
On second node (gluster2.osradar.local):
:~# mount -t glusterfs gluster1.osradar.local:/glusterfsvolumne /mnt
On client machine:
First we create the files, and verify
:~# touch /mnt/glusterfsvolumne/filetest{1..4} :~# ls /mnt/glusterfsvolumne
Now from node 1 we show the files created from the client.
:~# ls -l /mnt/
That concludes the article and I hope it has served you well. Remember that for everything to work, you have to be careful with the firewall and define its rules correctly.
Please share this article through your social networks-