What is GlusterFS?
GlusterFS is an open-source network/cluster filesystem and is based on a stackable user-space design. In this tutorial, we will achieve high availability of storage(i.e real-time replication of files) across two Linux machines using GlusterFS. Although glusterfs found its application in different areas like cloud computing, streaming media services, and content delivery networks. In this tutorial, we will use the term brick (It is the storage filesystem that has been assigned to a volume).
In Our case, we are using two Centos 6.2 Machines, and Using glusterfs static files of Apache document root (/var/www/html) will be replicated across these machines. Follow the below steps to achieve this.
Step 1: Enable the epel repository on both the nodes:
# yum -y install http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
Step 2: Enable GlusterFS repository on both the nodes:
# wget -P /etc/yum.repos.d http://download.gluster.org/pub/gluster/glusterfs/LATEST/EPEL.repo/glusterfs-epel.repo
Step 3: Install all the necessary packages using yum on both the nodes:
# yum -y install pyxattr python-webob1.0 python-paste-deploy1.5 python-sphinx10 git autoconf automake bison dos2unix flex fuse-devel libaio-devel libibverbs-devel libtool libxml2-devel lvm2-devel make openssl-devel pkgconfig python-devel python-eventlet python-netifaces python-paste-deploy python-simplejson python-sphinx python-webob readline-devel rpm-build systemtap-sdt-devel tar
Step 4: Install the GlusterFS software on both the nodes:
# yum install glusterfs{-fuse,-server} # yum install xfsdump xfsprogs
Step 5: Start GlusterFS service on both the nodes:
# /etc/init.d/glusterd start ; chkconfig glusterd on
Step 6: Add fuse module to Linux core for GlusterFS client on both the nodes:
# /sbin/modprobe fuse
To make it work after restart of server:
# echo "modprobe fuse" > /etc/sysconfig/modules/fuse.modules # chmod +x /etc/sysconfig/modules/fuse.modules
Step 7: Add both nodes on trusted storage:
– On ‘site1.thegeekdiary.com’, run below command:
# gluster peer probe site2.thegeekdiary.com
On ‘Site2.thegeekdiary.com’, run below command:
# gluster peer probe site1.thegeekdiary.com
To Check status of trusted storage, use below command:
# glusterfs peer status
Step 8: Create the below directory on both nodes.
# mkdir -p /opt/gfs-data
On Master Node, site1.thegeekdiary.com, run below command:
# gluster volume create apache replica 2 site1.thegeekdiary.com:/opt/gfs-data site2.thegeekdiary.com:/opt/gfs-data
Step 9: Now start the volume on both the nodes.
# gluster volume start apache
Now Mount volumes on site1.thegeekdiary.com:
# mount.glusterfs site1.thegeekdiary.com:/apache /var/www/html
Also Mount the Volume on site2.thegeekdiary.com:
# mount.glusterfs site2.thegeekdiary:/apache /var/www/html
For the Permanent Mount add below entry in the /etc/fstab file.
site1.thegeekdiary.com:/apache /var/www/html glusterfs defaults,_netdev 0 0
Step 10: Testing of file replications.
Go To /var/www/html folders, modify the files from ‘site1.thegeekdiary.com’ check whether the changes are reflected on another node ‘site2.thegeekdiary.com’.