源码编译安装使用glusterfs

注:使用源码安装的原因主要是使用yum安装glusterfs服务端时出现一些依赖库问题

  • 准备3台glusterfs服务器(官方也建议至少3台,防止发生脑裂),并在各个服务器的/etc/hosts下面添加如下内容(如使用DNS服务器,则在DNS中添加域名解析)
10.85.3.113 glusterfs-1.example.com
10.85.3.114 glusterfs-2.example.com
10.85.3.115 glusterfs-3.example.com
# 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
# cd userspace-rcu-master
# ./bootstrap
# ./configure
# make && make install
# ldconfig
  • 下载glusterfs源码并解压到/home/glusterfs-5.7,本次版本为5.7
  •  将glusterfs的lib拷贝到系统目录(编译gluster的时候会用到)
# cd /home/glusterfs-5.7 
# cp
-r libglusterfs/src /usr/local/include/glusterfs
  • 安装依赖库uuid,yum install -y libuuid-devel
  • 拷贝glupy(编译gluster的时候会用到)
# cp -r /home/glusterfs-xlators-master/xlators/glupy/ /home/glusterfs-5.7/xlators/features/
  • 按照官方文档在执行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
  • 在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
  • 在3台服务器执行如下命令,设置开机启动并启动glusterfs
# chkconfig glusterd on
# glusterd
  • 在master1上执行如下命令,添加对端
# gluster peer probe glusterfs-1.example.com
# gluster peer probe glusterfs-2.example.com
# gluster peer probe glusterfs-3.example.com # gluster peer status
  • 在master1上创建并启动volume,大小为5G
gluster volume create volume-5G replica 3  glusterfs-1.example.com:/data/brick/glusterfs1 glusterfs-2.example.com:/data/brick/glusterfs2 glusterfs-3.example.com:/data/brick/glusterfs3
gluster volume start volume-5G

使用如下命令查看volume

gluster volume status
gluster volume info

容器环境下推荐Replicated 模式,更多信息参见官方文档,注意部分模式已经废弃

  • 在客户端机器上安装glusterfs客户端
# yum install glusterfs-client -y
  • 在客户端挂载服务端volume,第一种方式为采用nfs挂载,第二种采用glusterfs命令行挂载,效果一样
mount -t glusterfs glusterfs-1.example.com:/volume-5G /data/mounttest/
glusterfs --volfile-id=volume-5G --volfile-server=glusterfs-1.example.com /data/glusterfsclient

PS:

  • gluster命令行可以参见官方文档
  • 在删除volume再添加时可能会出现如"Error: /data/brick/glusterfs1 is already part"的错误,使用如下方式清理环境即可
# rm -rf /data/brick/glusterfs1/.glusterfs/
# setfattr -x trusted.glusterfs.volume-id /data/brick/glusterfs1/ 

参考:

https://www.cnblogs.com/jicki/p/5801712.html

https://www.ibm.com/developerworks/cn/opensource/os-cn-glusterfs-docker-volume/index.html

https://jimmysong.io/kubernetes-handbook/practice/using-glusterfs-for-persistent-storage.html

猜你喜欢

转载自www.cnblogs.com/charlieroro/p/11204250.html