zoukankan      html  css  js  c++  java
  • GFS分布式文件系统环境部署与管理

    Gluster分布式文件系统

    准备环境五台虚拟机

    创建/gfs目录,把软件包全部拷贝目录

    yum仓库的源放进bak下才能执行以下脚本

    并指定主机名这四台机器都要执行脚本

    [root@localhost ~]# mkdir /gfs

    [root@localhost ~]# cd /gfs

    把包放进/gfs

    Vim gfs.sh

    #!/bin/bash

    for i in $(fdisk -l | grep -wo "/dev/sd[b-z]" | sort)

    do

    dd if=/dev/zero of=$i bs=1024 count=1024

    fdisk $i << EOF

    n

    p

    w

    EOF

    partprobe $i

    mkfs.ext4 ${i}1

    done

    mkdir /b3 /c4 /d5 /e6

    fdisk -l | grep -w "/dev/sd[b-z]" | sed -r 's/.*(/d.{8}).*/1/g' | sed -r 's/(.*)(.)(.*)/mount 121 /23/' | bash

    fdisk -l | grep -w "/dev/sd[b-z]" | sed -r 's/.*(/d.{8}).*/1/g' | sed -r 's/(.*)(.)(.*)/121 /23 xf default 0 0/' >> /etc/fstab

    iptables -F

    systemctl stop firewalld

    setenforce 0

    cat << EOF >> /etc/hosts

    192.168.30.21 node1

    192.168.30.22 node2

    192.168.30.23 node3

    192.168.30.24 node4

    EOF

    cat << EOF >> /etc/yum.repos.d/gfs.repo

    [gfs]

    name=gfs

    baseurl=file:///gfs

    gpgcheck=0

    enabled=1

    EOF

    yum clean all && yum makecache

    yum -y install glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma

    systemctl start glusterd

    systemctl enable glusterd

    read -p "请输入主机名" hn

    hostname $hn

    bash

    [root@node1 ~]# df -h

    启动GlusterFS在所有节点执行

    [root@node1 ~]# systemctl start glusterd

    [root@node1 ~]# systemctl enable glusterd

    添加节点,只在node1上执行操作,添加node1-node4节点

    [root@node1 ~]# gluster peer probe node1

    peer probe: success. Probe on localhost not needed

    [root@node1 ~]# gluster peer probe node2

    peer probe: success.

    [root@node1 ~]# gluster peer probe node3

    peer probe: success.

    [root@node1 ~]# gluster peer probe node4

    peer probe: success.

    查看集群状态

    [root@node1 ~]# gluster peer status

    Number of Peers: 3

    Hostname: node2

    Uuid: b2c6fb38-6d87-4f0e-8ec2-cac17abdb51a

    State: Peer in Cluster (Connected)

    Hostname: node3

    Uuid: d8ca1764-5370-49bb-9c6e-02028fbb2c3a

    State: Peer in Cluster (Connected)

    Hostname: node4

    Uuid: 7f480c33-7b11-4785-a718-b54ea10bc82c

    State: Peer in Cluster (Connected)

    创建卷

    1,创建分布式卷

    [root@node1 ~]# gluster volume create dis-volume node1:/e6 node2:/e6 force

    volume create: dis-volume: success: please start the volume to access data

    [root@node1 ~]# gluster volume info dis-volume

    Volume Name: dis-volume

    Type: Distribute

    Volume ID: 07b832ed-d8ee-4982-a6fc-8ee646739fa0

    Status: Created

    Snapshot Count: 0

    Number of Bricks: 2

    Transport-type: tcp

    Bricks:

    Brick1: node1:/e6

    Brick2: node2:/e6

    Options Reconfigured:

    transport.address-family: inet

    nfs.disable: on

    [root@node1 ~]# gluster volume start dis-volume

    volume start: dis-volume: success

    没有执行类型,默认创建的是分布式卷

    2,创建条带卷

    [root@node1 ~]# gluster volume create stripe-volume stripe 2 node1:/d5 node2:/d5 force

    volume create: stripe-volume: success: please start the volume to access data

    [root@node1 ~]# gluster volume info stripe-volume

    Volume Name: stripe-volume

    Type: Stripe

    Volume ID: 9eea0fc5-6809-4910-b996-c4c70a32e7e9

    Status: Created

    Snapshot Count: 0

    Number of Bricks: 1 x 2 = 2

    Transport-type: tcp

    Bricks:

    Brick1: node1:/d5

    Brick2: node2:/d5

    Options Reconfigured:

    transport.address-family: inet

    nfs.disable: on

    [root@node1 ~]# gluster volume start stripe-volume

    指定类型为stripe,数值为2,而且后面跟了2Brick serer 所有创建的是条带卷

    3,创建复制卷

    [root@node1 ~]# gluster volume create rep-volume replica 2 node3:/d5 node4:/d5 force

    volume create: rep-volume: success: please start the volume to access data

    [root@node1 ~]# gluster volume info rep-volume

     

    Volume Name: rep-volume

    Type: Replicate

    Volume ID: 923fb5ea-edf1-4cf3-8154-1e85328ff605

    Status: Created

    Snapshot Count: 0

    Number of Bricks: 1 x 2 = 2

    Transport-type: tcp

    Bricks:

    Brick1: node3:/d5

    Brick2: node4:/d5

    Options Reconfigured:

    transport.address-family: inet

    nfs.disable: on

    [root@node1 ~]# gluster volume start rep-volume

    volume start: rep-volume: success

     

    指定类型为replica,数值为2,而且后面跟了2Brick server 所有创建的是复制卷

    4,创建分布式条带卷

    [root@node1 ~]# gluster volume create dis-stripe stripe 2 node1:/b3 node2:/b3 node3:/b3 node4:/b3 force

    volume create: dis-stripe: success: please start the volume to access data

    [root@node1 ~]# gluster volume info rep-stripe

    Volume rep-stripe does not exist

    [root@node1 ~]# gluster volume info dis-stripe

    Volume Name: dis-stripe

    Type: Distributed-Stripe

    Volume ID: 616c1a3a-3e95-42e6-820a-36e61af92776

    Status: Created

    Snapshot Count: 0

    Number of Bricks: 2 x 2 = 4

    Transport-type: tcp

    Bricks:

    Brick1: node1:/b3

    Brick2: node2:/b3

    Brick3: node3:/b3

    Brick4: node4:/b3

    Options Reconfigured:

    transport.address-family: inet

    nfs.disable: on

    [root@node1 ~]# gluster volume start dis-stripe

    volume start: dis-stripe: success

    5创建分布式复制卷

    [root@node1 ~]# gluster volume create dis-rep replica 2 node1:/c4 node2:/c4 node3:/c4 node4:/c4 force

    volume create: dis-rep: success: please start the volume to access data

    [root@node1 ~]# gluster volume info dis-rep

    Volume Name: dis-rep

    Type: Distributed-Replicate

    Volume ID: f0a97902-8c26-4d91-8478-cd7d9d11c7b5

    Status: Created

    Snapshot Count: 0

    Number of Bricks: 2 x 2 = 4

    Transport-type: tcp

    Bricks:

    Brick1: node1:/c4

    Brick2: node2:/c4

    Brick3: node3:/c4

    Brick4: node4:/c4

    Options Reconfigured:

    transport.address-family: inet

    nfs.disable: on

    [root@node1 ~]# gluster volume start dis-rep

    volume start: dis-rep: success

    部署Gluster客户端

    把软件包都放进去,然后把yum源藏一下

    [root@zhao ~]# vim gfs.sh

    #!/bin/bash

    iptables -F

    systemctl stop firewalld

    setenforce 0

    cat << EOF >> /etc/hosts

    192.168.30.21 node1

    192.168.30.22 node2

    192.168.30.23 node3

    192.168.30.24 node4

    EOF

    cat << EOF >> /etc/yum.repos.d/gfs.repo

    [gfs]

    name=gfs

    baseurl=file:///gfs

    gpgcheck=0

    enabled=1

    EOF

    yum clean all && yum makecache

    yum -y install glusterfs glusterfs-fuse

    systemctl start glusterd

    systemctl enable glusterd

    read -p "请输入主机名: " hn

    hostname $hn

    bash

    创建挂载目录

    [root@zhao ~]#  mkdir -p /test/{dis,stripe,rep,dis_and_stripe,dis_and_rep}

    [root@zhao ~]# ls /test

    dis  dis_and_rep  dis_and_stripe  rep  stripe

    修改hosts文件

    [root@zhao ~]# tail -4 /etc/hosts

    192.168.30.21 node1

    192.168.30.22 node2

    192.168.30.23 node3

    192.168.30.24 node4

    挂载Gluster文件系统

    [root@zhao ~]# mount -t glusterfs node1:dis-volume /test/dis

    [root@zhao ~]#  mount -t glusterfs node1:stripe-volume /test/stripe

    [root@zhao ~]# mount -t glusterfs node1:rep-volume /test/rep/

    [root@zhao ~]# mount -t glusterfs node1:dis-stripe /test/dis_and_stripe/

    [root@zhao ~]#  mount -t glusterfs node1:dis-rep /test/dis_and_rep

    修改fstab配置文件

    node1:dis-volume /test/dis glusterfs defaults,_netdev 0 0 

    node1:stripe-volume /test/stripe glusterfs defaults,_netdev 00

    node1:rep-volume /test/rep glusterfs defaults,_netdev 0 0

    node1:dis-rep /test/dis_and_rep glusterfs defaults,_netdev 0 0

    node1:dis-stripe /test/dis_and_stripe glusterfs defaults,_netdev 0 0

    [root@zhao ~]# for i in {1..5};do dd if=/dev/zero of=/root/demon$i.log bs=1M count=43;done

    测试Gluster文件系统

    1、卷中写入文件

    [root@zhao ~]# ls -lh demo*

    -rw-r--r--. 1 root root 43M 4月  25 15:27 demon1.log

    -rw-r--r--. 1 root root 43M 4月  25 15:27 demon2.log

    -rw-r--r--. 1 root root 43M 4月  25 15:27 demon3.log

    -rw-r--r--. 1 root root 43M 4月  25 15:27 demon4.log

    -rw-r--r--. 1 root root 43M 4月  25 15:27 demon5.log

    [root@zhao ~]# cp demon* /test/dis

    [root@zhao ~]# cp demon* /test/stripe/

    [root@zhao ~]# cp demon* /test/rep

    [root@zhao ~]# cp demon* /test/dis_and_stripe

    [root@zhao ~]# cp demon* /test/dis_and_rep

    查看文件分布
    下面查看分布式卷文件分布

    node1上去操作

    [root@node1 ~]# ll -h /e6

    总用量 130M

    -rw-r--r--. 2 root root 43M 4月  25 15:28 demon1.log

    -rw-r--r--. 2 root root 43M 4月  25 15:28 demon3.log

    -rw-r--r--. 2 root root 43M 4月  25 15:28 demon4.log

    [root@node2 ~]# ll -h /e6

    总用量 87M

    -rw-r--r--. 2 root root 43M 4月  25 15:28 demon2.log

    -rw-r--r--. 2 root root 43M 4月  25 15:28 demon5.log

    下面查看条带卷文件分布:

    [root@node1 ~]# ll -h /d5

    总用量 108M

    -rw-r--r--. 2 root root 22M 4月  25 15:29 demon1.log

    -rw-r--r--. 2 root root 22M 4月  25 15:29 demon2.log

    -rw-r--r--. 2 root root 22M 4月  25 15:29 demon3.log

    -rw-r--r--. 2 root root 22M 4月  25 15:29 demon4.log

    -rw-r--r--. 2 root root 22M 4月  25 15:29 demon5.log

    [root@node2 ~]# ll -h /d5

    总用量 108M

    -rw-r--r--. 2 root root 22M 4月  25 15:29 demon1.log

    -rw-r--r--. 2 root root 22M 4月  25 15:29 demon2.log

    -rw-r--r--. 2 root root 22M 4月  25 15:29 demon3.log

    -rw-r--r--. 2 root root 22M 4月  25 15:29 demon4.log

    -rw-r--r--. 2 root root 22M 4月  25 15:29 demon5.log

    下面查看复制卷文件分布

    [root@node3 ~]# ll -h /d5

    总用量 216M

    -rw-r--r--. 2 root root 43M 4月  25 23:29 demon1.log

    -rw-r--r--. 2 root root 43M 4月  25 23:29 demon2.log

    -rw-r--r--. 2 root root 43M 4月  25 23:29 demon3.log

    -rw-r--r--. 2 root root 43M 4月  25 23:29 demon4.log

    -rw-r--r--. 2 root root 43M 4月  25 23:29 demon5.log

    [root@node4 ~]# ll -h /d5

    总用量 216M

    -rw-r--r--. 2 root root 43M 4月  25 15:29 demon1.log

    -rw-r--r--. 2 root root 43M 4月  25 15:29 demon2.log

    -rw-r--r--. 2 root root 43M 4月  25 15:29 demon3.log

    -rw-r--r--. 2 root root 43M 4月  25 15:29 demon4.log

    -rw-r--r--. 2 root root 43M 4月  25 15:29 demon5.log

    下面查看分布式条带卷文件分布

    [root@node1 ~]# ll -h /b3

    总用量 65M

    -rw-r--r--. 2 root root 22M 4月  25 15:29 demon1.log

    -rw-r--r--. 2 root root 22M 4月  25 15:29 demon3.log

    -rw-r--r--. 2 root root 22M 4月  25 15:29 demon4.log

    [root@node2 ~]# ll -h /b3

    总用量 65M

    -rw-r--r--. 2 root root 22M 4月  25 15:29 demon1.log

    -rw-r--r--. 2 root root 22M 4月  25 15:29 demon3.log

    -rw-r--r--. 2 root root 22M 4月  25 15:29 demon4.log

    [root@node3 ~]# ll -h /b3

    总用量 44M

    -rw-r--r--. 2 root root 22M 4月  25 23:29 demon2.log

    -rw-r--r--. 2 root root 22M 4月  25 23:29 demon5.log

    [root@node4 ~]# ll -h /b3

    总用量 44M

    -rw-r--r--. 2 root root 22M 4月  25 15:29 demon2.log

    -rw-r--r--. 2 root root 22M 4月  25 15:29 demon5.log

    下面查看分布式复制卷文件分布:

    [root@node1 ~]# ll -h /c4

    总用量 130M

    -rw-r--r--. 2 root root 43M 4月  25 15:29 demon1.log

    -rw-r--r--. 2 root root 43M 4月  25 15:29 demon3.log

    -rw-r--r--. 2 root root 43M 4月  25 15:29 demon4.log

    [root@node2 ~]# ll -h /c4

    总用量 130M

    -rw-r--r--. 2 root root 43M 4月  25 15:29 demon1.log

    -rw-r--r--. 2 root root 43M 4月  25 15:29 demon3.log

    -rw-r--r--. 2 root root 43M 4月  25 15:29 demon4.log

    [root@node3 ~]# ll -h /c4

    总用量 87M

    -rw-r--r--. 2 root root 43M 4月  25 23:29 demon2.log

    -rw-r--r--. 2 root root 43M 4月  25 23:29 demon5.log

    [root@node4 ~]# ll -h /c4

    总用量 87M

    -rw-r--r--. 2 root root 43M 4月  25 15:29 demon2.log

    -rw-r--r--. 2 root root 43M 4月  25 15:29 demon5.log

    破坏性测试

    挂起node2节点,在客户端上测试文件是否可以正常使用

    [root@zhao ~]#  head -1 /test/dis/demon2.log

    head: 无法打开"/test/dis/demon2.log" 读取数据: 没有那个文件或目录

    [root@zhao ~]#  head -1 /test/dis/demon3.log

    ^C

    [root@zhao ~]#  head -1 /test/dis/demon4.log

    ^C[root@zhao ~]#  head -1 /test/dis/demon5.log

    head: 无法打开"/test/dis/demon5.log" 读取数据: 没有那个文件或目录

    分布在node2节点上的demon2.logdemon5.log 无法访问,分布式卷不具备冗余性

    测试条带卷数据是否可以正常访问

    [root@zhao ~]#  head -1 /test/stripe/demon1.log

    head: 读取"/test/stripe/demon1.log" 时出错: 没有那个文件或目录

    [root@zhao ~]#  head -1 /test/stripe/demon2.log

    head: 读取"/test/stripe/demon2.log" 时出错: 没有那个文件或目录

    [root@zhao ~]#  head -1 /test/stripe/demon3.log

    head: 读取"/test/stripe/demon3.log" 时出错: 没有那个文件或目录

    [root@zhao ~]#  head -1 /test/stripe/demon4.log

    head: 读取"/test/stripe/demon4.log" 时出错: 没有那个文件或目录

    [root@zhao ~]#  head -1 /test/stripe/demon5.log

    head: 读取"/test/stripe/demon5.log" 时出错: 没有那个文件或目录

    node2节点挂起后,所有数据全部丢失

    测试分布式条带卷数据是否可以访问

    [root@zhao ~]#  head -1 /test/dis_and_stripe/demon1.log

    head: 读取"/test/dis_and_stripe/demon1.log" 时出错: 没有那个文件或目录

    [root@zhao ~]#  head -1 /test/dis_and_stripe/demon2.log

    ^C

    [root@zhao ~]#  head -1 /test/dis_and_stripe/demon3.log

    head: 读取"/test/dis_and_stripe/demon3.log" 时出错: 没有那个文件或目录

    [root@zhao ~]#  head -1 /test/dis_and_stripe/demon4.log

    head: 读取"/test/dis_and_stripe/demon4.log" 时出错: 没有那个文件或目录

    [root@zhao ~]#  head -1 /test/dis_and_stripe/demon5.log

    node2节点挂起后,分布在node1node2节点的数据丢失,而分布在node3node4节点

    的数据不丢失

    测试分布式复制卷数据是否可以访问:

    [root@zhao ~]#  head -1 /test/dis_and_rep/demon5.log

    ^C

    [root@zhao ~]#  head -1 /test/dis_and_rep/demon4.log

    ^C

    [root@zhao ~]#  head -1 /test/dis_and_rep/demon3.log

    ^C

    [root@zhao ~]#  head -1 /test/dis_and_rep/demon2.log

    ^C

    [root@zhao ~]#  head -1 /test/dis_and_rep/demon1.log

    node2节点挂起后,数据不丢失
    继续挂起node4节点,在客户端上测试文件是否可以正常使用。

    测试复制卷数据

    [root@zhao ~]#  head -1 /test/rep/demon1.log

    [root@zhao ~]#  head -1 /test/rep/demon2.log

    [root@zhao ~]#  head -1 /test/rep/demon3.log

    [root@zhao ~]#  head -1 /test/rep/demon4.log

    [root@zhao ~]#  head -1 /test/rep/demon5.log

    是否可以访问:

    node2node4节点挂起后,数据不丢失

    测试分布式条带卷数据是否可以访问:

    [root@zhao ~]#  head -1 /test/dis_and_stripe/demon1.log

    head: 读取"/test/dis_and_stripe/demon1.log" 时出错: 没有那个文件或目录

    [root@zhao ~]#  head -1 /test/dis_and_stripe/demon2.log

    head: 读取"/test/dis_and_stripe/demon2.log" 时出错: 没有那个文件或目录

    [root@zhao ~]#  head -1 /test/dis_and_stripe/demon3.log

    head: 读取"/test/dis_and_stripe/demon3.log" 时出错: 没有那个文件或目录

    [root@zhao ~]#  head -1 /test/dis_and_stripe/demon4.log

    head: 读取"/test/dis_and_stripe/demon4.log" 时出错: 没有那个文件或目录

    [root@zhao ~]#  head -1 /test/dis_and_stripe/demon5.log

    head: 读取"/test/dis_and_stripe/demon5.log" 时出错: 没有那个文件或目录

    测试分布式复制卷数据是否可以访问:

    [root@zhao ~]# tail -1 /test/dis_and_rep/demon1.log

    ^C

    [root@zhao ~]# tail -1 /test/dis_and_rep/demon2.log

    ^C

    [root@zhao ~]# tail -1 /test/dis_and_rep/demon3.log

    ^C

    [root@zhao ~]# tail -1 /test/dis_and_rep/demon4.log

    ^C

    [root@zhao ~]# tail -1 /test/dis_and_rep/demon5.log

    node2node4节点挂起后,数据不丢失

     

  • 相关阅读:
    [精华] Linux内存:内存管理的实质
    阿里巴巴笔试题
    LINUX内核经典面试题(转)
    常见网络编程面试题答案征集与面试题(收集)
    转使用jQuery Ajax的内存回收
    模式识别与机器学习
    vc2010 学习笔记2
    vc2010 学习笔记3
    Android高级编程(笔记)第6章 数据存储、检索和共享—3SQLite数据库
    Android高级编程(笔记)第6章 数据存储、检索和共享1共享Preference
  • 原文地址:https://www.cnblogs.com/zc1741845455/p/10921263.html
Copyright © 2011-2022 走看看