Saturday, 10 May 2014

Set up GlusterFS with a volume replicated over 2 nodes

The servers setup:

To install the required packages run on both servers:
sudo apt-get install glusterfs-server
If you want a more up to date version of GlusterFS you can add the following repo:
sudo add-apt-repository ppa:semiosis/ubuntu-glusterfs-3.4
Now from one of the servers you must connect to the other:
sudo gluster peer probe <ip_of_the_other_server>
You should see the following output:
peer probe: success
You can check the status from any of the hosts with:
sudo gluster peer status
Now we need to create the volume where the data will reside. For this run the following comand:
sudo gluster volume create datastore1 replica 2 transport tcp <server1_IP>:/mnt/gfs_block <server2_IP>:/mnt/gfs_block
Where /mnt/gfs_block is the mount point where the data will be on each node and datastore1 is the name of the volume you are creating.

If this has been sucessful, you should see:
Creation of volume datastore1 has been successful. Please start the volume to access data.
As the message indicates, we now need to start the volume:
sudo gluster volume start datastore1
As a final test, to make sure the volume is available, run gluster volume info.
sudo gluster volume info 
Your GlusterFS volume is ready and will maintain replication across two nodes.
If you want to Restrict Access to the Volume, you can use the following command:
sudo gluster volume set datastore1 auth.allow gluster_client1_ip,gluster_client2_ip
If you need to remove the restriction at any point, you can type:
sudo gluster volume set volume1 auth.allow *

Setup the clients:

Install the needed packages with:
sudo apt-get install glusterfs-client
To mount the volume you must edit the fstab file:
sudo vi /etc/fstab
And append the following to it:
[HOST1]:/[VOLUME]    /[MOUNT] glusterfs defaults,_netdev,backupvolfile-server=[HOST2] 0 0
Where [HOST1] is the IP address of one of the servers and [HOST2] is the IP of the other server. [VOLUME] is the Volume name, in our case datastore1 and [MOUNT] is the path where you whant the files on the client.

Or, you can also mount the volume using a volume config file:

Create a volume config file for your GlusterFS client.
vi /etc/glusterfs/datastore.vol
Create the above file and replace [HOST1] with your GlusterFS server 1, [HOST2] with your GlusterFS server 2 and [VOLNAME] with the Gluster FS volume to mount.
 volume remote1
 type protocol/client
 option transport-type tcp
 option remote-host [HOST1]
 option remote-subvolume [VOLNAME]

 volume remote2
 type protocol/client
 option transport-type tcp
 option remote-host [HOST2]
 option remote-subvolume [VOLNAME]

 volume replicate
 type cluster/replicate
 subvolumes remote1 remote2

 volume writebehind
 type performance/write-behind
 option window-size 1MB
 subvolumes replicate

 volume cache
 type performance/io-cache
 option cache-size 512MB
 subvolumes writebehind
Finally, edit fstab to add this config file and it's mount point. Replace [MOUNT] with the location to mount the storage to.
/etc/glusterfs/datastore.vol [MOUNT] glusterfs rw,allow_other,default_permissions,max_read=131072 0 0

Possibly Related Posts

Create LVM volume from multiple disks

Recently I had to crate an Amazon EC2 Instance with a storage capacity of 5Tb, unfortunately, Amazon only allows us to create 1Tb volumes so I had to create 5 volumes, attach them to the instance and create a 5Tb LVM device.

My instance was running Ubuntu and I hat to install the lvm2 package:
apt-get install lvm2 
The volumes attached to my instance where named from /dev/xvdg to /dev/xvdk

to find the names you can use the command:
fdisk -l
First we have to prepare our volumes for LVM with:
pvcreate /dev/xvdg /dev/xvdh /dev/xvdi /dev/xvdj /dev/xvdk
You can run the following command to check the result:
The next step is to create a volume group, I used the command:
vgcreate storage /dev/xvdg /dev/xvdh /dev/xvdi /dev/xvdj /dev/xvdk 
And used the command:
to check the result, you can also use:
Now we need to create the logical volume, in this case I wanted to use the entire available space so, I used the command:
lvcreate -n data -l 100%free storage
to check the new volume if every thing goes well it should be on /dev/storage/data 

you can also use the command 
Now you just have to format the new device, you can use:
mkft -t ext4 /dev/storage/data
When ready you can mount it with:
mout /dev/storage/data /mnt

Possibly Related Posts