所谓覅破解 发表于 2019-2-1 12:18:45

GlusterFS分布式文件系统使用简介

  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安装
   view plaincopyprint?https://code.csdn.net/assets/CODE_ico.pnghttps://code.csdn.net/assets/ico_fork.svg

[*]  #安装依赖工具
[*]  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地址,将设备加到存储池中。
   view plaincopyprint?https://code.csdn.net/assets/CODE_ico.pnghttps://code.csdn.net/assets/ico_fork.svg

[*]  $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
http://img.blog.csdn.net/20140924194558625?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvenp1bHA=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast
  分布卷可以将某个文件随机的存储在卷内的一个brick内,通常用于扩展存储能力,不支持数据的冗余。除非底层的brick使用RAID等外部的冗余措施。
   view plaincopyprint?https://code.csdn.net/assets/CODE_ico.pnghttps://code.csdn.net/assets/ico_fork.svg

[*]  $gluster volume create mamm-volume node1:/media node2:/media node3:/media ...
  3.1.2 replicated volume
http://img.blog.csdn.net/20140924194814636?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvenp1bHA=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast
  复本卷在创建时可指定复本的数量,复本在存储时会在卷的不同brick上,因此有几个复本就必须提供至少多个brick。
   view plaincopyprint?https://code.csdn.net/assets/CODE_ico.pnghttps://code.csdn.net/assets/ico_fork.svg

[*]  $gluster volume create mamm-volume repl 2node1:/media node2:/media
  注意:在创建复本卷时,brick数量与复本个数必须相等;否则将会报错。
  另外如果同一个节点提供了多个brick,也可以在同一个结点上创建复本卷,但这并不安全,因为一台设备挂掉,其上面的所有brick就无法访问了。
  3.1.3 striped volume
http://img.blog.csdn.net/20140924194842076?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvenp1bHA=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast
  分片卷将单个文件分成小块(块大小支持配置,默认为128K),然后将小块存储在不同的brick上,以提升文件的访问性能。
   view plaincopyprint?https://code.csdn.net/assets/CODE_ico.pnghttps://code.csdn.net/assets/ico_fork.svg

[*]  $gluster volume create mamm-volume stripe 2 node1:/media node2:/media
  stripe后的参数指明切片的分布位置个数
  注意:brick的个数必须等于分布位置的个数
  3.1.4 distribute replication volume
http://img.blog.csdn.net/20140924194912262?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvenp1bHA=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast
  此类型卷是基本复本卷的扩展,可以指定若干brick组成一个复本卷,另外若干brick组成另个复本卷。单个文件在复本卷内数据保持复制,不同文件在不同复本卷之间进行分布。
   view plaincopyprint?https://code.csdn.net/assets/CODE_ico.pnghttps://code.csdn.net/assets/ico_fork.svg

[*]  $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
http://img.blog.csdn.net/20140924194947285?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvenp1bHA=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast
  类似于分布式复本卷,
  若创建的卷的节点提供的bricks个数为stripe个数N倍时,将创建此类型的卷。
   view plaincopyprint?https://code.csdn.net/assets/CODE_ico.pnghttps://code.csdn.net/assets/ico_fork.svg

[*]  $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
http://img.blog.csdn.net/20140924194834093?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvenp1bHA=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast
  数据将进行切片,切片在复本卷内进行复制,在不同卷间进行分布。
   view plaincopyprint?https://code.csdn.net/assets/CODE_ico.pnghttps://code.csdn.net/assets/ico_fork.svg

[*]  $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
http://img.blog.csdn.net/20140924195045941?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvenp1bHA=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast
   view plaincopyprint?https://code.csdn.net/assets/CODE_ico.pnghttps://code.csdn.net/assets/ico_fork.svg

[*]  $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 启/停/删除卷
   view plaincopyprint?https://code.csdn.net/assets/CODE_ico.pnghttps://code.csdn.net/assets/ico_fork.svg

[*]  $gluster volume start mamm-volume
[*]  $gluster volume stop mamm-volume
[*]  $gluster volume delete mamm-volume
  3.3 扩展收缩卷
   view plaincopyprint?https://code.csdn.net/assets/CODE_ico.pnghttps://code.csdn.net/assets/ico_fork.svg

[*]  $gluster volume add-brick mamm-volume brick1...
[*]  $gluster volume remove-brick mamm-volume brick1...
  扩展或收缩卷时,也要按照卷的类型,加入或减少的brick个数必须满足相应的要求。
  3.4 迁移卷
  主要完成数据在卷之间的在线迁移
   view plaincopyprint?https://code.csdn.net/assets/CODE_ico.pnghttps://code.csdn.net/assets/ico_fork.svg

[*]  gluster volume replace-brick mamm-volume old-brick new-brick
[*]  #迁移需要完成一系列的事务,假如我们准备将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 均衡卷
  当对卷进行了扩展或收缩后,需要对卷的数据进行重新均衡。
   view plaincopyprint?https://code.csdn.net/assets/CODE_ico.pnghttps://code.csdn.net/assets/ico_fork.svg

[*]  $gluster volume rebalane mamm-volume start|stop|status
  3.6 触发副本自愈
   view plaincopyprint?https://code.csdn.net/assets/CODE_ico.pnghttps://code.csdn.net/assets/ico_fork.svg

[*]  $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 选项配置
   view plaincopyprint?https://code.csdn.net/assets/CODE_ico.pnghttps://code.csdn.net/assets/ico_fork.svg

[*]  $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 添加卷提示已经路径已在卷中的错误
  执行下面的脚本,清除历史数据及属性信息
   view plaincopyprint?https://code.csdn.net/assets/CODE_ico.pnghttps://code.csdn.net/assets/ico_fork.svg

[*]  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的客户端直接访问。
   view plaincopyprint?https://code.csdn.net/assets/CODE_ico.pnghttps://code.csdn.net/assets/ico_fork.svg

[*]  #service nfs stop       # 关闭Linux内核自带的NFS服务
[*]  #service rpcbind start# 启动rpc端口映射管理
[*]  #rpc.statd
  然后客户端挂载
   view plaincopyprint?https://code.csdn.net/assets/CODE_ico.pnghttps://code.csdn.net/assets/ico_fork.svg

[*]  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
   view plaincopyprint?https://code.csdn.net/assets/CODE_ico.pnghttps://code.csdn.net/assets/ico_fork.svg

[*]  gluster volume profile mamm-vol start
[*]  gluster volume profile info
[*]  gluster volume profile mamm-vol stop
  6.2 实时top
  显示当前某个brick或NFS文件打开/读/写/打开目录/读目录的计数
   view plaincopyprint?https://code.csdn.net/assets/CODE_ico.pnghttps://code.csdn.net/assets/ico_fork.svg

[*]  gluster volume top mamm-vol {open|read|write|opendir|readdir} brick node1:/exp1 list-cnt 1
  显示当前某个brick或NFS路径读文件或写文件数据的性能
   view plaincopyprint?https://code.csdn.net/assets/CODE_ico.pnghttps://code.csdn.net/assets/ico_fork.svg

[*]  gluster volume top mamm-vol read-perf|write-perf bs 256 count 10 brick node1:/exp1 list-cnt 1
  6.3 内部计数导出
   view plaincopyprint?https://code.csdn.net/assets/CODE_ico.pnghttps://code.csdn.net/assets/ico_fork.svg

[*]  gluster volume statedump mamm-vol
  设置导出路径
   view plaincopyprint?https://code.csdn.net/assets/CODE_ico.pnghttps://code.csdn.net/assets/ico_fork.svg

[*]  gluster volume set server.statedump-path /var/log/
  查看导出数据
   view plaincopyprint?https://code.csdn.net/assets/CODE_ico.pnghttps://code.csdn.net/assets/ico_fork.svg

[*]  gluster volume info dumpfile
  6.4 卷状态查看
   view plaincopyprint?https://code.csdn.net/assets/CODE_ico.pnghttps://code.csdn.net/assets/ico_fork.svg

[*]  gluster volume status
  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]
查看完整版本: GlusterFS分布式文件系统使用简介