美文网首页
GlusterFS分布式文件实战应用

GlusterFS分布式文件实战应用

作者: OPS_Joy | 来源:发表于2020-09-05 11:43 被阅读0次
  • 环境准备以及搭建
    系统环境:centos7.5,双网卡,双磁盘【客户机除外】
    Glusterfs版本:7.5
    Glusterfs服务端四台
    192.168.136.129 node1
    192.168.136.130 node2
    192.168.136.131 node3
    192.168.136.132 node4
    客户端一台
    192.168.136.133 client
    础环境准备:关闭防火墙和selinux,时间同步,host解析


    8.png
  • 四台服务端操作
    对新磁盘操作:fdisk /dev/sdb-->n--->p-->默认-->w
    格式化磁盘:mkfs.xfs -i size=512 /dev/sdb1
    新建目录:mkdir /brick1
    挂载磁盘:mount /dev/sdb1 /brick1
    四台服务器都要看到挂载成功


    9.png

    可加入到启动挂载中 vi /etc/fstab
    /dev/sdb1 /brick1 xfs defaults 0 0
    安装GlusterFS
    yum -y install centos-release-gluster
    yum install -y glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma
    启动服务:systemctl start glusterd.service
    查看glusterfs版本:


    10.png
  • 客户端操作
    yum -y install centos-release-gluster glusterfs glusterfs-fuse
  • 再服务端其中一台上操作
    [root@node1 ~]# gluster peer status
    Number of Peers: 0
    将node2,node3加入集群
    [root@node1 ~]# gluster peer probe node2
    peer probe: success.
    [root@node1 ~]# gluster peer probe node3
    peer probe: success.
    再次查看集群信息
    [root@node1 testv1]# gluster peer status
    11.png
    测试删除node3节点
    [root@node1 testv1]# gluster peer detach node3
    提示信息会同步到其他已经加入的服务器
    12.png
    在node2上查看
    [root@node2 brick1]# gluster peer status
    Number of Peers: 1
    Hostname: node1
    Uuid: bd21e584-ea99-4873-b5d6-ffc336bcc6fe
    State: Peer in Cluster (Connected)
    在node3上查看
    [root@node3 ~]# gluster peer status
    Number of Peers: 0
    该文章主要测试(分布式卷)和(复制卷)以及(混合模式分布式复制卷)
    创建分布式卷【用node1 node2两台服务器就可以】,命名为testv1
    [root@node1 ~]# gluster volume create testv1 node1:/brick1/test1
    启动卷
    [root@node1 ~]# gluster volume start testv1
    在客户端上挂载
    [root@client ~]# mount -t glusterfs node1:/testv1 /mnt
    13.png
    在node1上继续操作,把node2也加入到卷中
    [root@node1 mnt]# gluster volume add-brick testv1 node2:/brick1/test1
    查看卷的信息
    [root@node1 ~]# gluster volume info
    14.png
    回到客户端可以查看到之前的挂载盘,已经自动扩容了
    15.png
    在挂载的mnt目录新建文件
    [root@localhost ~]# cd /mnt
    [root@localhost mnt]# touch {1..10}.txt
    [root@localhost mnt]# ls
    10.txt 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt
    在node1和node2的brick1下的test1中查看,文件已经自动分发两台服务器中
    [root@node1 ~]# ls /brick1/test1/
    10.txt 1.txt 2.txt 3.txt 5.txt 6.txt 7.txt
    [root@node2 ~]# ls /brick1/test1
    4.txt 8.txt 9.txt
    删除node2中的brick,模拟扩容
    开始移除
    [root@node1 mnt]# gluster volume remove-brick testv1 node2:/brick1/test1 start
    查看移除状态
    [root@node1 ~]# gluster volume remove-brick testv1 node2:/brick1/test1 status
    16.png
    查看volume信息
    17.png
    node2中的brick下面文件已经转移到node1中
    [root@node1 ~]# ls /brick1/test1/
    10.txt 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt
    重新把node2加入,模拟新服务器加入,需要把之前node2下的test1目录删除,不然会提示如下错误【也可以重新命名目录,为了统一还是删除】
    18.png
    在node2上查看,已经有文件转移过去
    [root@node2 brick1]# ls test1/
    4.txt 8.txt 9.txt
    在node1和node2上创建复制卷,复制份数为2
    gluster volume create testv2 replica 2 node1:/brick1/test2 node2:/brick1/test2
    [root@node1 ~]# gluster volume start testv2
    [root@node1 ~]# gluster volume info testv2
    19.png
    客户端进行挂载,容量只有一半
    [root@client ~]# mount -t glusterfs node1:/testv2 /repdata
    20.png
    在repdata下创建目录
    [root@client repdata]# touch {1..10}.txt
    [root@client repdata]# ls
    10.txt 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt
    node1和node2中查看
    [root@node1 ~]# ls /brick1/test2
    10.txt 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt
    [root@node2 brick1]# ls /brick1/test2/
    10.txt 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt
    创建分布式复制卷,需要4台服务器
    gluster volume create testv3 replica 2 node1:/brick1/test3 node2:/brick1/test3 node3:/brick1/test3 node4:/brick1/test3
    21.png
    [root@node1 ~]# gluster volume start testv3
    客户端挂载
    mount -t glusterfs node1:/testv3 /mnt3
    [root@client repdata]# cd /mnt3
    [root@client mnt3]# touch {1..40}.txt
    [root@client mnt3]# ls
    10.txt 12.txt 14.txt 16.txt 18.txt 1.txt 21.txt 23.txt 25.txt 27.txt 29.txt 30.txt 32.txt 34.txt 36.txt 38.txt 3.txt 4.txt 6.txt 8.txt
    11.txt 13.txt 15.txt 17.txt 19.txt 20.txt 22.txt 24.txt 26.txt 28.txt 2.txt 31.txt 33.txt 35.txt 37.txt 39.txt 40.txt 5.txt 7.txt 9.txt
    在node1--node4上查看
    [root@node1 ~]# ls /brick1/test3
    13.txt 17.txt 19.txt 23.txt 26.txt 27.txt 28.txt 29.txt 31.txt 32.txt 33.txt 34.txt 35.txt 37.txt 39.txt 40.txt 4.txt 8.txt 9.txt
    [root@node2 ~]# ls /brick1/test3
    13.txt 17.txt 19.txt 23.txt 26.txt 27.txt 28.txt 29.txt 31.txt 32.txt 33.txt 34.txt 35.txt 37.txt 39.txt 40.txt 4.txt 8.txt 9.txt
    [root@node3 ~]# ls /brick1/test3
    10.txt 11.txt 12.txt 14.txt 15.txt 16.txt 18.txt 1.txt 20.txt 21.txt 22.txt 24.txt 25.txt 2.txt 30.txt 36.txt 38.txt 3.txt 5.txt 6.txt 7.txt
    [root@node4 ~]# ls /brick1/test3
    10.txt 11.txt 12.txt 14.txt 15.txt 16.txt 18.txt 1.txt 20.txt 21.txt 22.txt 24.txt 25.txt 2.txt 30.txt 36.txt 38.txt 3.txt 5.txt 6.txt 7.txt

相关文章

网友评论

      本文标题:GlusterFS分布式文件实战应用

      本文链接:https://www.haomeiwen.com/subject/rjuzsktx.html