设为首页 收藏本站
查看: 1205|回复: 0

[经验分享] GlusterFS分布式文件系统使用简介

[复制链接]
发表于 2019-2-1 12:18:45 | 显示全部楼层 |阅读模式
  0 术语简介
  GlusterFS是一个开源的分布式文件系统。更多特性介绍附录的参考文档。
  Brick:GFS中的存储单元,通过是一个受信存储池中的服务器的一个导出目录。可以通过主机名和目录名来标识,如'SERVER:EXPORT'
  Client: 挂载了GFS卷的设备
  Extended Attributes:xattr是一个文件系统的特性,其支持用户或程序关联文件/目录和元数据。
  FUSE:Filesystem Userspace是一个可加载的内核模块,其支持非特权用户创建自己的文件系统而不需要修改内核代码。通过在用户空间运行文件系统的代码通过FUSE代码与内核进行桥接。
  Geo-Replication
  GFID:GFS卷中的每个文件或目录都有一个唯一的128位的数据相关联,其用于模拟inode
  Namespace:每个Gluster卷都导出单个ns作为POSIX的挂载点
  Node:一个拥有若干brick的设备
  RDMA:远程直接内存访问,支持不通过双方的OS进行直接内存访问。
  RRDNS:round robin DNS是一种通过DNS轮转返回不同的设备以进行负载均衡的方法
  Self-heal:用于后台运行检测复本卷中文件和目录的不一致性并解决这些不一致。
  Split-brain:脑裂
  Translator:
  Volfile:glusterfs进程的配置文件,通常位于/var/lib/glusterd/vols/volname
  Volume:一组bricks的逻辑集合
  1 Gluster安装
  [plain] view plaincopyprint?

  •   #安装依赖工具
  •   yum install xfsprogs wget
  •   yum install fuse fuse-libs
  •   #格式化磁盘并创建GFS分区
  •   fdisk /dev/sdb
  •   mkfs.xfs -i size=512 /dev/sdb1
  •   mount /dev/sdb1 /mnt/sdb1
  •   #安装gluster
  •   wget http://download.gluster.org/pub/gluster/glusterfs/LATEST/CentOS/gluster-epel.repo -O /etc/yum.repo.d/glusterfs.repo
  •   yum install glusterfs{,-server,-fuse,-geo-replication}
  •   #启动glusterfs
  •   /etc/init.d/glusterd start
  •   /etc/init.d/glusterd stop
  •   #如果需要在系统启动时开启glusterd
  •   chkconfig glusterd on
  2 cluster管理
  在创建volume之前需要先将一组存储设备组成一个存储池,通过存储设备提供的bricks来组成卷。
  在设备上启动glusterd之后,可通过设备的主机名或IP地址,将设备加到存储池中。
  [plain] view plaincopyprint?

  •   $gluster peer probe host|ip
  •   $gluster peer status         #查看除本机外的其他设备状态
  •   $gluster peer detach host|ip #如果希望将某设备从存储池中删除
  gluster对于每个节点都会生成一个UUID来标识,因此如果节点的IP或主机名发生了变化,只需要重新执行peer probe即可。不过如果一个主机名曾经用过,想再改回去,则gluster会提示已经保存过。此时只能把节点detach掉,然后重新probe。
  3 Volume管理
  数据的传输协议支持tcp和infiniband rdma协议。
  3.1 卷的类型
  3.1.1 distributed volume

  分布卷可以将某个文件随机的存储在卷内的一个brick内,通常用于扩展存储能力,不支持数据的冗余。除非底层的brick使用RAID等外部的冗余措施。
  [plain] view plaincopyprint?

  •   $gluster volume create mamm-volume node1:/media node2:/media node3:/media ...
  3.1.2 replicated volume

  复本卷在创建时可指定复本的数量,复本在存储时会在卷的不同brick上,因此有几个复本就必须提供至少多个brick。
  [plain] view plaincopyprint?

  •   $gluster volume create mamm-volume repl 2  node1:/media node2:/media
  注意:在创建复本卷时,brick数量与复本个数必须相等;否则将会报错。
  另外如果同一个节点提供了多个brick,也可以在同一个结点上创建复本卷,但这并不安全,因为一台设备挂掉,其上面的所有brick就无法访问了。
  3.1.3 striped volume

  分片卷将单个文件分成小块(块大小支持配置,默认为128K),然后将小块存储在不同的brick上,以提升文件的访问性能。
  [plain] view plaincopyprint?

  •   $gluster volume create mamm-volume stripe 2 node1:/media node2:/media
  stripe后的参数指明切片的分布位置个数
  注意:brick的个数必须等于分布位置的个数
  3.1.4 distribute replication volume

  此类型卷是基本复本卷的扩展,可以指定若干brick组成一个复本卷,另外若干brick组成另个复本卷。单个文件在复本卷内数据保持复制,不同文件在不同复本卷之间进行分布。
  [plain] view plaincopyprint?

  •   $gluster volume create dr-volume repl 2 node1:/exp1 node2:/exp2 node3:/exp3 node4:/exp4
  注意:
  复本卷的组成依赖于指定brick的顺序
  brick必须为复本数K的N倍,brick列表将以K个为一组,形成N个复本卷
  3.1.5 distribute striped volume

  类似于分布式复本卷,
  若创建的卷的节点提供的bricks个数为stripe个数N倍时,将创建此类型的卷。
  [plain] view plaincopyprint?

  •   $gluster volume create ds-volume stripe 2 node1:/exp1 node1:/exp2 [&] node2:/exp3 node2:/exp4
  注意:
  切片卷的组成依赖于指定brick的顺序
  brick必须为复本数K的N倍,brick列表将以K个为一组,形成N个切片卷
  3.1.6 striped replicated volume

  数据将进行切片,切片在复本卷内进行复制,在不同卷间进行分布。
  [plain] view plaincopyprint?

  •   $gluster volume create test-volume stripe 2 replica 2 server1:/exp1 server2:/exp2 server3:/exp3 server4:/exp4
  exp1和exp2组成复本卷,exp3和exp4组成复本卷,两个复本卷组成分片卷。
  注意:brick数量必须和stripe个数N和repl参数M的积N*M相等。即对于brick列表,将以M为一组,形成N个切片卷。数据切片分布在N个切片卷上,在每个切片卷内部,切片数据复本M份。
  3.1.7 distributed striped replicated vlume

  [plain] view plaincopyprint?

  •   $gluster volume create test-volume stripe 2 replica 2 server1:/exp1 server2:/exp2 server3:/exp3 server4:/exp4 server5:/exp5 server6:/exp6 server7:/exp7 server8:/exp8
  注意:bricks数量为stripe个数N,和repl个数M的积N*M的整数倍
  exp1 exp2 exp3 exp4组成一个分布卷,exp1和exp2组成一个stripe卷,exp3和exp4组成另一个stripe卷,1和2,3和4互为复本卷
  exp4-exp8组成另一个分布卷,略。
  3.2 启/停/删除卷
  [plain] view plaincopyprint?

  •   $gluster volume start mamm-volume
  •   $gluster volume stop mamm-volume
  •   $gluster volume delete mamm-volume
  3.3 扩展收缩卷
  [plain] view plaincopyprint?

  •   $gluster volume add-brick mamm-volume [strip|repli ] brick1...
  •   $gluster volume remove-brick mamm-volume [repl ] brick1...
  扩展或收缩卷时,也要按照卷的类型,加入或减少的brick个数必须满足相应的要求。
  3.4 迁移卷
  主要完成数据在卷之间的在线迁移
  [plain] view plaincopyprint?

  •   gluster volume replace-brick mamm-volume old-brick new-brick [start|pause|abort|status|commit]
  •   #迁移需要完成一系列的事务,假如我们准备将mamm卷中的brick3替换为brick5
  •   #启动迁移过程
  •   $gluster volume replace-brick mamm-volume node3:/exp3 node5:/exp5 start
  •   #暂停迁移过程
  •   $gluster volume replace-brick mamm-volume node3:/exp3 node5:/exp5 pause
  •   #中止迁移过程
  •   $gluster volume replace-brick mamm-volume node3:/exp3 node5:/exp5 abort
  •   #查看迁移状态
  •   $gluster volume replace-brick mamm-volume node3:/exp3 node5:/exp5 status
  •   #迁移完成后提交完成
  •   $gluster volume replace-brick mamm-volume node3:/exp3 node5:/exp5 commit
  3.5 均衡卷
  当对卷进行了扩展或收缩后,需要对卷的数据进行重新均衡。
  [plain] view plaincopyprint?

  •   $gluster volume rebalane mamm-volume start|stop|status
  3.6 触发副本自愈
  [plain] view plaincopyprint?

  •   $gluster volume heal mamm-volume #只修复有问题的文件
  •   $gluster volume heal mamm-volume full #修复所有文件
  •   $gluster volume heal mamm-volume info#查看自愈详情
  •   $gluster volume heal mamm-volume info healed|heal-failed|split-brain
  3.7 选项配置
  [plain] view plaincopyprint?

  •   $gluster volume set mamm-volume key value
  详细的可设置选项:
  https://github.com/gluster/glusterfs/blob/master/doc/admin-guide/en-US/markdown/admin_managing_volumes.md
  4 排错
  4.1 错误
  gluster使用了若干端口,如果出现probe peer或数据无法同步,考虑iptables对应用的影响。
  
  4.2 日志
  $gluster volume log rotate mamm-vol  #实现日志rotate
  4.3 添加卷提示已经路径已在卷中的错误
  执行下面的脚本,清除历史数据及属性信息
  [plain] view plaincopyprint?

  •   path=$1 #参数为待添加目录绝对路径
  •   rm -rf $path/.glu*
  •   setfattr -x trusted.glusterfs.volume-id $path
  •   setfattr -x trusted.gfid $path
  4.4 添加卷连接失败
  每次向卷中添加brick后,远端的glusterd进程可能会连接关闭一段时间。此时现次执行操作会提示连接失败。等一会再执行即可。
  5 客户端设置
  客户端使用GFS有多种方式,性能最高的方式是使用gluster的native接口,此外还有NFS和CIFS方式。
  5.1 native方式
  1 安装gluserfs-fuse安装包,
  2 挂载卷:mount -t glusterfs host/ip:path mnt-point
  注意,这里提供的IP和主机只用来为客户提供volfile信息,后续客户便直接和需要的服务器通信了。
  3 设置自动挂载
  echo "localhost:/mamm-vol /mnt/glusterfs glusterfs defaults,_netdev 0 0" >>/etc/fstab
  5.2 NFS方式
  Gluster提供了内置的NFS服务,支持其他实现了NFSv3的客户端直接访问。
  [plain] view plaincopyprint?

  •   #service nfs stop       # 关闭Linux内核自带的NFS服务
  •   #service rpcbind start  # 启动rpc端口映射管理
  •   #rpc.statd
  然后客户端挂载
  [plain] view plaincopyprint?

  •   mount -t nfs -o vers=3 host/ip:/path mnt-port
  window7客户端
  程序和功能->打开或关闭windows功能,安装NFS客户端功能,即可使用mount/showmount功能。
  5.3 CIFS方式
  cifs可以提供给WIN及samba客户端访问,对于windows程序,可以使用//ip/path通过SMB协议来方便的使用远程资源
  1 在服务器将glusterfs挂载到/mnt/gfs
  2 服务器通过samba配置将/mnt/gfs导出服务,启动smb服务
  3 在win客户端上挂载samber服务器导出共享mount -t cifs //ip/path  /mnt-point
  6 性能监控
  6.1  性能profile
  [plain] view plaincopyprint?

  •   gluster volume profile mamm-vol start
  •   gluster volume profile info
  •   gluster volume profile mamm-vol stop
  6.2 实时top
  显示当前某个brick或NFS文件打开/读/写/打开目录/读目录的计数
  [plain] view plaincopyprint?

  •   gluster volume top mamm-vol {open|read|write|opendir|readdir} brick node1:/exp1 list-cnt 1
  显示当前某个brick或NFS路径读文件或写文件数据的性能
  [plain] view plaincopyprint?

  •   gluster volume top mamm-vol read-perf|write-perf bs 256 count 10 brick node1:/exp1 list-cnt 1
  6.3 内部计数导出
  [plain] view plaincopyprint?

  •   gluster volume statedump mamm-vol
  设置导出路径
  [plain] view plaincopyprint?

  •   gluster volume set server.statedump-path /var/log/
  查看导出数据
  [plain] view plaincopyprint?

  •   gluster volume info dumpfile
  6.4 卷状态查看
  [plain] view plaincopyprint?

  •   gluster volume status [all|volname] [detail|clients|mem|fd|inode|callpoll]
  7 参考资料
  官方文档地址:https://github.com/gluster/glusterfs/tree/master/doc/admin-guide/en-US/markdown
  Gluster集群文件系统研究:http://blog.csdn.net/liuaigui/article/details/6284551
  Gluster管理入门:http://www.slashroot.in/gfs-gluster-file-system-complete-tutorial-guide-for-an-administrator
  Gluster原理视频介绍:http://edu.运维网.com/lesson/id-35359.html
  Gluster运维视频介绍:http://edu.运维网.com/course/course_id-1930-page-2.html
  Infiniband介绍与配置:http://www.ibm.com/developerworks/cn/linux/l-cn-infiniband/


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-670444-1-1.html 上篇帖子: ESXI GLusterFS ISCSI 构建低端虚拟化解决方案 下篇帖子: 关于CentOS/RHEL中GlusterFS版本说明
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表