一、GlusterFS简介
GlusterFS是一款开源的分布式文件系统,实现标准的POSIX接口,并可通过fuse实现虚拟化,让使用者看起来就像是使用本地磁盘一样。而且程序想从本地磁盘切换到GlusterFS时是不用修改任何代码的,做到了无缝切换。可以让系统中的服务器共用同一块磁盘,简单且易操作。
常用:当你的本机磁盘空间不够时,使用GlusterFS可完美解决磁盘空间不足问题。
二、特点
1、能够处理上千数量级的客户端,可结合常用的物理的、虚拟的云资源来实现高可用的企业级性能存储。
2、GlusterFS可通过TCP/IP huozhe InfiniBand RDMA 网络链路来将客户端的存储资源收集在一起,使用单一的全局命令空间来管理数据,磁盘和内存资源。
3、GlusterFS可以运行在任何标准IP网络的客户端,使用全局统一命名的NFS/CIFS等标准协议来访问应用数据。
4、空间性堆叠设计,具有高扩展、高性能和高可用性能。
5、内部使用弹性hash算法,采用弹性卷管理,而且基于标准协议。
三、工作原理
实现原理详解:
1、对Client端来说,用户可以通过glusterfs中的 mount point 来读写数据,而且集群系统是用户来说是透明存在的,用户是完全感觉不到是在操作本地系统还是远端的集群系统。
2、用户的操作是由本地Linux系统的VFS来处理。
3、VFS将数据交给FUSE内核文件系统:当在启动 glusterfs 客户端之前,需要先在系统注册一个实际的文件FUSE,该文件系统与ext3在同一个层次上面,ext3 是对实际的磁盘进行处理,而FUSE文件系统则是将数据通过/dev/fuse 这个设备文件递交给了glusterfs client端。所以,我们可以将 fuse 文件系统理解为一个代理。
4、当数据被 fuse 递交给GlusterFS client后,client 对数据进行一些指定的处理(所谓的指定,实际是指按照client 配置文件来进行的一系列处理,我们在启动glusterfs client时需要指定这个文件)
5、在glusterfs client的处理末端,通过网络将数据递交给 GlusterFS Server,并且将数据写入到服务器所控制的存储设备上。
四、源码搭建
注:使用源码安装的原因主要是因为如果使用yum安装glusterfs服务端时,会出现一系列依赖库问题。
1、首先,准备3台glusterfs服务器【建议3台,防止发生脑裂。】
注:脑裂会引起数据的不完整性,导致集群中的节点同时访问同一共享资源,而且没有机制去协调控制。而且会导致对外提供的服务出现异常。
并在各个服务器的/etc/hosts下面添加如下内容(如使用DNS服务器,则在DNS中添加域名解析)
10.10.3.113 glusterfs-1.com
10.10.3.114 glusterfs-2.com
10.10.3.115 glusterfs-3.com
2、安装GlusterFS所依赖的库文件
yum install autoconf automake bison cmockery2-devel dos2unix flex fuse-devel glib2-devel libacl-devel libaio-devel libattr-devel libcurl-devel libibverbs-devel librdmacm-devel libtirpc-devel libtool libxml2-devel lvm2-devel make openssl-devel pkgconfig pyliblzma python-devel python-eventlet python-netifaces python-paste-deploy python-simplejson python-sphinx python-webob pyxattr readline-devel rpm-build sqlite-devel systemtap-sdt-devel tar userspace-rcu-devel
3、下载userspace-rcu-master并解压到/home/userspace-rcu-master
链接:https://github.com/urcu/userspace-rcu
下载glusterfs-xlators/master并解压到/home/glusterfs-xlators-master
链接:https://github.com/gluster/glusterfs-xlators
# 编译userspace-rcu
cd userspace-rcu-master
./bootstrap
./configure
make && make install
ldconfig
4、下载gluster源码包:【这里版本为5.7】
链接:https://download.gluster.org/pub/gluster/glusterfs/5/5.7/glusterfs-5.7.tar.gz
然后将glusterfs的lib复制到系统目录中(编译时会使用到)
cd /home/glusterfs-5.7
cp -r libglusterfs/src /usr/local/include/glusterfs
5、安装依赖库uuid、
yum install -y libuuid-devel
6、拷贝glupy(编译需要)
cp -r /home/glusterfs-xlators-master/xlators/glupy/ /home/glusterfs-5.7/xlators/features/
6、然后执行glusterfs安装步骤
cd /home/glusterfs-5.7
./autogen.sh
./configure --without-libtirpc
./configure --enable-gnfs
make
make install
这里如果在make的时候报错,报错内容为:
../../../../contrib/userspace-rcu/rculist-extra.h:33:6: error: redefinition of 'cds_list_add_tail_rcu'
void cds_list_add_tail_rcu(struct cds_list_head *newp,
^
In file included from glusterd-rcu.h:15:0,
from glusterd-sm.h:26,
from glusterd.h:28,
from glusterd.c:19:
/usr/local/include/urcu/rculist.h:44:6: note: previous definition of 'cds_list_add_tail_rcu' was here
void cds_list_add_tail_rcu(struct cds_list_head *newp,
解决方案:
给下述文件cds_list_add_tail_rcu函数加上条件编译即可
/usr/local/include/urcu/rculist.h
/home/glusterfs-5.7/contrib/userspace-rcu/rculist-extra.h
#ifndef CDS_LIST_ADD_TAIL_CRU
#define CDS_LIST_ADD_TAIL_CRU
static inline
void cds_list_add_tail_rcu(struct cds_list_head *newp,
struct cds_list_head *head)
{
newp->next = head;
newp->prev = head->prev;
rcu_assign_pointer(head->prev->next, newp);
head->prev = newp;
}
#endif
7、然后在3台服务器执行如下命令,格式化磁盘并挂载目录
mkfs.xfs -i size=512 /dev/vdb
mkdir -p /data/brick
echo '/dev/vdb /data/brick xfs defaults 1 2' >> /etc/fstab
mount -a && mount
8、在3台服务器执行如下命令,设置开机启动并启动glusterfs
chkconfig glusterd on
glusterd
9、在master1上执行如下命令,添加对端
gluster peer probe glusterfs-1.com
gluster peer probe glusterfs-2.com
gluster peer probe glusterfs-3.com
gluster peer status
10、在master1上创建并启动volume,大小为5G
gluster volume create volume-5G replica 3 glusterfs-1.com:/data/brick/glusterfs1 glusterfs-2.com:/data/brick/glusterfs2 glusterfs-3.com:/data/brick/glusterfs3
gluster volume start volume-5G
可使用如下命令查看volume
gluster volume status
gluster volume info
注:至此,Server端的GlusterFS搭建已经完成,接下来是Client端的搭建。
11、在客户端机器上安装glusterfs客户端
yum install glusterfs-client -y
在客户端挂载服务端volume,第一种方式为采用nfs挂载,第二种采用glusterfs命令行挂载
mount -t glusterfs glusterfs-1.com:/volume-5G /data/mounttest/
glusterfs --volfile-id=volume-5G --volfile-server=glusterfs-1.com /data/glusterfsclient
注:如果在删除volume时,再次进行添加时,可能报错:
"Error: /data/brick/glusterfs1 is already part"的错误
解决方式:
清理环境
rm -rf /data/brick/glusterfs1/.glusterfs/
setfattr -x trusted.glusterfs.volume-id /data/brick/glusterfs1/
OK~