一、GlusterFS的安装

  • 以下为示例环境

1.1 部署环境

系统CentOS 7.3
glusterfs版本3.12.1
主机名IP
server110.81.29.87
server210.81.9.115

hosts解析

  1. [root@server1 ~]# cat /etc/hosts
  2. 127.0.0.1 localhost
  3. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  4. 10.81.29.87 server1
  5. 10.81.9.115 server2

格式化磁盘、创建目录并挂载

  1. #在所有存储节点执行
  2. #格式化磁盘
  3. mkfs.xfs /dev/vdb
  4. #制作挂载点目录
  5. mkdir -p /data
  6. #编辑 /etc/fstab 配置开机挂载信息
  7. echo "/dev/vdb /data xfs defaults 1 2" >>/etc/fstab
  8. #执行挂载操作
  9. mount -a

查看挂载情况

  1. [root@server1 ~]# df -h
  2. Filesystem Size Used Avail Use% Mounted on
  3. /dev/vda1 40G 1.9G 36G 5% /
  4. devtmpfs 1.9G 0 1.9G 0% /dev
  5. tmpfs 1.9G 0 1.9G 0% /dev/shm
  6. tmpfs 1.9G 332K 1.9G 1% /run
  7. tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
  8. tmpfs 380M 0 380M 0% /run/user/0
  9. /dev/vdb 20G 33M 20G 1% /data #出现这条记录,即挂载成功
  1. [root@server2 ~]# df -h
  2. Filesystem Size Used Avail Use% Mounted on
  3. /dev/vda1 40G 1.9G 36G 5% /
  4. devtmpfs 1.9G 0 1.9G 0% /dev
  5. tmpfs 1.9G 0 1.9G 0% /dev/shm
  6. tmpfs 1.9G 344K 1.9G 1% /run
  7. tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
  8. tmpfs 380M 0 380M 0% /run/user/0
  9. /dev/vdb 20G 33M 20G 1% /data #出现这条记录,即挂载成功

1.2 安装glusterfs

  1. #所有存储节点执行
  2. yum install centos-release-gluster -y
  3. yum install glusterfs-server -y

1.3 启动GlusterFS服务

  1. #所有存储节点执行
  2. systemctl start glusterd.service
  3. systemctl enable glusterd.service
  4. systemctl status glusterd.service

1.4 配置信任池(一端添加就行)

  1. [root@server1 ~]# gluster peer probe server2
  2. peer probe: success.
  3. [root@server1 ~]# gluster peer status
  4. Number of Peers: 1
  5. Hostname: server2
  6. Uuid: be69468e-94b6-45a6-8a3d-bea86c2702dc
  7. State: Peer in Cluster (Connected)

1.5 创建卷

  1. # 所有节点都需执行
  2. mkdir -p /data/glusterfs
  3. # 创建一个卷
  4. gluster volume create data replica 2 server1:/data/glusterfs server2:/data/glusterfs
  5. Replica 2 volumes are prone to split-brain. Use Arbiter or Replica 3 to avoid this. See: http://docs.gluster.org/en/latest/Administrator%20Guide/Split%20brain%20and%20ways%20to%20deal%20with%20it/.
  6. Do you still want to continue?
  7. (y/n) y
  8. volume create: data: success: please start the volume to access data

1.6 查看卷的信息

  1. [root@server1 ~]# gluster volume info
  2. Volume Name: data
  3. Type: Replicate
  4. Volume ID: 8c16603c-2fab-4117-8020-2310b0041b35
  5. Status: Created
  6. Snapshot Count: 0
  7. Number of Bricks: 1 x 2 = 2
  8. Transport-type: tcp
  9. Bricks:
  10. Brick1: server1:/data/glusterfs
  11. Brick2: server2:/data/glusterfs
  12. Options Reconfigured:
  13. transport.address-family: inet
  14. nfs.disable: on

启动卷

  1. [root@server1 ~]# gluster volume start data
  2. volume start: data: success

1.7 挂载测试

  1. #server1 挂载
  2. [root@server1 ~]# mount -t glusterfs server1:/data /mnt
  3. #server2 挂载
  4. [root@server2 ~]# mount -t glusterfs server2:/data /mnt
  5. #在server2上创建文件
  6. [root@server2 ~]# touch /mnt/{1..10}test.txt
  7. #在server1上查看文件是否同步,如出现上一步创建的文件,说明同步成功
  8. [root@server1 ~]# ls /mnt/
  9. 10test.txt 2test.txt 4test.txt 6test.txt 8test.txt
  10. 1test.txt 3test.txt 5test.txt 7test.txt 9test.txt