一、安装glusterfs

1、使用glusterfs安装源
  1. [root@pod2 yum.repos.d]# yum search centos-release-gluster
  2. Loaded plugins: fastestmirror, priorities
  3. Loading mirror speeds from cached hostfile
  4. * epel: mirrors.tuna.tsinghua.edu.cn
  5. ================================================= N/S matched: centos-release-gluster =================================================
  6. centos-release-gluster-legacy.noarch : Disable unmaintained Gluster repositories from the CentOS Storage SIG
  7. centos-release-gluster40.x86_64 : Gluster 4.0 (Short Term Stable) packages from the CentOS Storage SIG repository
  8. centos-release-gluster41.noarch : Gluster 4.1 (Long Term Stable) packages from the CentOS Storage SIG repository
  9. centos-release-gluster5.noarch : Gluster 5 packages from the CentOS Storage SIG repository
  10. centos-release-gluster6.noarch : Gluster 6 packages from the CentOS Storage SIG repository
  1. 我们选择4.1 LTS版本
2、安装glusterfs
  1. yum install glusterfs-server glusterfs-cli -y

如果安装错误,需要强制安装userspace-rcu-0.10.0-3.el7.x86_64.rpm

3、启动glusterfs-server
  1. systemctl start glusterd
  2. systemctl enable glusterd
4、 多加入glusterfs加入pool
  1. gluster peer probe hostname|ip
5、安装 xfs 支持包(ext4文件格式支持16TB的磁盘大小,而xfs是PB级别的)
  1. yum install xfsprogs -y
6、创建 volume 及其他操作

GlusterFS 五种卷

Distributed:分布式卷,文件通过 hash 算法随机分布到由 bricks 组成的卷上。
Replicated: 复制式卷,类似 RAID 1,replica 数必须等于 volume 中 brick 所包含的存储服务器数,可用性高。
Striped: 条带式卷,类似 RAID 0,stripe 数必须等于 volume 中 brick 所包含的存储服务器数,文件被分成数据块,以 Round Robin 的方式存储在 bricks 中,并发粒度是数据块,大文件性能好。
Distributed Striped: 分布式的条带卷,volume中 brick 所包含的存储服务器数必须是 stripe 的倍数(>=2倍),兼顾分布式和条带式的功能。
Distributed Replicated: 分布式的复制卷,volume 中 brick 所包含的存储服务器数必须是 replica 的倍数(>=2倍),兼顾分布式和复制式的功能。

分布式复制卷的brick顺序决定了文件分布的位置,一般来说,先是两个brick形成一个复制关系,然后两个复制关系形成分布。

glustfs 最常用的卷就是分布式复制卷。
striped 的目的就提高性能,读取更快。

企业一般用后两种,大部分会用分布式复制(可用容量为 总容量/复制份数),通过网络传输的话最好用万兆交换机,万兆网卡来做。这样就会优化一部分性能。它们的数据都是通过网络来传输的。

7、分布式卷创建
  1. # 创建分布式卷
  2. [root@mystorage1 ~]# gluster volume create gv1 mystorage1:/storage/brick1 mystorage2:/storage/brick1 force
  3. volume create: gv1: success: please start the volume to access data
  4. # 启动创建的卷
  5. [root@mystorage1 ~]# gluster volume start gv1
  6. volume start: gv1: success
  7. # 在另一台机器(mystorage4)查看卷信息
  8. [root@mystorage4 ~]# gluster volume info
  9. Volume Name: gv1
  10. Type: Distribute
  11. Volume ID: b6ec2f8a-d1f0-4d1b-806b-238efb6dcb84
  12. Status: Started
  13. Number of Bricks: 2
  14. Transport-type: tcp
  15. Bricks:
  16. Brick1: mystorage1:/storage/brick1
  17. Brick2: mystorage2:/storage/brick1
  18. Options Reconfigured:
  19. performance.readdir-ahead: on
  20. # 挂载卷到目录
  21. [root@mystorage4 ~]# mount -t glusterfs 127.0.0.1:/gv1 /mnt
  22. [root@mystorage4 ~]# df -h
  23. Filesystem Size Used Avail Use% Mounted on
  24. /dev/sda3 33G 1.3G 30G 5% /
  25. tmpfs 242M 0 242M 0% /dev/shm
  26. /dev/sda1 976M 38M 888M 5% /boot
  27. /dev/sdb 10G 33M 10G 1% /storage/brick1
  28. 127.0.0.1:/gv1 20G 65M 20G 1% /mnt
  29. # 在 mystorage1 创建测试文件
  30. [root@mystorage1 ~]# touch /mnt/{a..d}
  31. [root@mystorage1 ~]# ll /mnt
  32. total 0
  33. -rw-r--r-- 1 root root 0 Jul 30 00:54 a
  34. -rw-r--r-- 1 root root 0 Jul 30 00:54 b
  35. -rw-r--r-- 1 root root 0 Jul 30 00:54 c
  36. -rw-r--r-- 1 root root 0 Jul 30 00:54 d
  37. # 在 mystorage4 也可看到新创建的文件,信任存储池中的每一台主机挂载这个卷后都可以看到
  38. [root@mystorage4 ~]# ll /mnt/
  39. total 0
  40. -rw-r--r-- 1 root root 0 Jul 30 00:54 a
  41. -rw-r--r-- 1 root root 0 Jul 30 00:54 b
  42. -rw-r--r-- 1 root root 0 Jul 30 00:54 c
  43. -rw-r--r-- 1 root root 0 Jul 30 00:54 d
  44. # 文件实际存在位置
  45. [root@mystorage1 ~]# ls /storage/brick1
  46. a b c e
  47. [root@mystorage2 ~]# ls /storage/brick1
  48. d
  49. # 上面可以看到文件根据 hash 算法随机分布到由不同的 brick 上
8、复制式卷创建
  1. # 创建复制式卷
  2. [root@mystorage1 ~]# gluster volume create gv2 replica 2 mystorage3:/storage/brick1 mystorage4:/storage/brick1 force
  3. volume create: gv2: success: please start the volume to access data
  4. # 启动创建的卷
  5. [root@mystorage1 ~]# gluster volume start gv2
  6. volume start: gv2: success
  7. # 查看卷信息
  8. [root@mystorage1 ~]# gluster volume info gv2
  9. Volume Name: gv2
  10. Type: Replicate
  11. Volume ID: 11928696-263a-4c7a-a155-5115af29221f
  12. Status: Started
  13. Number of Bricks: 1 x 2 = 2
  14. Transport-type: tcp
  15. Bricks:
  16. Brick1: mystorage3:/storage/brick1
  17. Brick2: mystorage4:/storage/brick1
  18. Options Reconfigured:
  19. performance.readdir-ahead: on
  20. # 挂载卷到目录,创建测试文件
  21. [root@mystorage1 ~]# mount -t glusterfs 127.0.0.1:/gv2 /opt
  22. [root@mystorage1 ~]# touch /opt/{a..d}
  23. [root@mystorage1 ~]# ls /opt
  24. a b c d
  25. # 在 mystorage3,4 可看到新创建的文件
  26. [root@mystorage3 ~]# mount -t glusterfs 127.0.0.1:/gv2 /opt
  27. [root@mystorage3 ~]# ls /opt/
  28. a b c d
  29. [root@mystorage4 ~]# mount -t glusterfs 127.0.0.1:/gv2 /opt
  30. [root@mystorage4 ~]# ls /opt/
  31. a b c d
  32. # 文件实际存在位置
  33. [root@mystorage3 ~]# ls /storage/brick1
  34. a b c d
  35. [root@mystorage4 ~]# ls /storage/brick1
  36. a b c d
  37. # 上面可以看到文件根据在 2 台机器上的 brick 上都有
9、创建条带卷
  1. # 创建分布式条带卷
  2. [root@mystorage1 ~]# gluster volume create gv3 stripe 2 mystorage3:/storage/brick2 mystorage4:/storage/brick2 force
  3. volume create: gv3: success: please start the volume to access data
  4. # 启动创建的卷
  5. [root@mystorage1 ~]# gluster volume start gv3
  6. volume start: gv3: success
  7. # 查看卷信息
  8. [root@mystorage1 ~]# gluster volume info gv3
  9. Volume Name: gv3
  10. Type: Stripe
  11. Volume ID: 2871801f-b125-465c-be3a-4eeb2fb44916
  12. Status: Started
  13. Number of Bricks: 1 x 2 = 2
  14. Transport-type: tcp
  15. Bricks:
  16. Brick1: mystorage3:/storage/brick2
  17. Brick2: mystorage4:/storage/brick2
  18. Options Reconfigured:
  19. performance.readdir-ahead: on
  20. # 挂载卷到目录,创建测试文件
  21. mkdir /gv1 /gv2 /gv3
  22. mount -t glusterfs 127.0.0.1:gv1 /gv1
  23. mount -t glusterfs 127.0.0.1:gv2 /gv2
  24. mount -t glusterfs 127.0.0.1:gv3 /gv3
  25. df -h
  26. dd if=/dev/zero bs=1024 count=10000 of=/gv3/10M.file
  27. dd if=/dev/zero bs=1024 count=20000 of=/gv3/20M.file
  28. # 查看新创建的文件
  29. [root@mystorage1 ~]# ll /gv3/
  30. total 30000
  31. -rw-r--r-- 1 root root 10240000 Jul 30 02:26 10M.file
  32. -rw-r--r-- 1 root root 20480000 Jul 30 02:26 20M.file
  33. # 文件实际存放位置
  34. [root@mystorage3 ~]# ll -h /storage/brick2/
  35. total 15M
  36. -rw-r--r-- 2 root root 4.9M Jul 30 02:26 10M.file
  37. -rw-r--r-- 2 root root 9.8M Jul 30 02:26 20M.file
  38. [root@mystorage4 ~]# ll -h /storage/brick2/
  39. total 15M
  40. -rw-r--r-- 2 root root 4.9M Jul 30 02:25 10M.file
  41. -rw-r--r-- 2 root root 9.8M Jul 30 02:26 20M.file
  42. # 上面可以看到 10M 20M 的文件分别分成了 2 块(这是条带的特点),每块又分别在同的 brick 下(这是分布式的特点)
10、创建分布式复制卷
  1. # 查看复制式卷的效果
  2. cd /gv2
  3. rm -f *
  4. dd if=/dev/zero bs=1024 count=10000 of=/gv2/10M.file
  5. dd if=/dev/zero bs=1024 count=20000 of=/gv2/20M.file
  6. dd if=/dev/zero bs=1024 count=30000 of=/gv2/30M.file
  7. [root@mystorage3 ~]# ll -h /storage/brick1/
  8. total 59M
  9. -rw-r--r-- 2 root root 9.8M Jul 30 02:41 10M.file
  10. -rw-r--r-- 2 root root 20M Jul 30 02:41 20M.file
  11. -rw-r--r-- 2 root root 30M Jul 30 02:41 30M.file
  12. [root@mystorage4 ~]# ll -h /storage/brick1
  13. total 59M
  14. -rw-r--r-- 2 root root 9.8M Jul 30 02:40 10M.file
  15. -rw-r--r-- 2 root root 20M Jul 30 02:40 20M.file
  16. -rw-r--r-- 2 root root 30M Jul 30 02:40 30M.file
  17. # gv2 添加 brick 进行扩容
  18. [root@mystorage1 ~]# gluster volume stop gv2
  19. Stopping volume will make its data inaccessible. Do you want to continue? (y/n) y
  20. [root@mystorage1 ~]# gluster volume add-brick gv2 replica 2 mystorage1:/storage/brick2 mystorage2:/storage/brick2 force
  21. volume add-brick: success
  22. [root@mystorage1 ~]# gluster volume start gv2
  23. volume start: gv2: success
  24. [root@mystorage1 ~]# gluster volume info gv2
  25. Volume Name: gv2
  26. Type: Distributed-Replicate # 这里显示是分布式复制卷,是在 gv2 复制卷的基础上增加 2 块 brick 形成的
  27. Volume ID: 11928696-263a-4c7a-a155-5115af29221f
  28. Status: Stopped
  29. Number of Bricks: 2 x 2 = 4
  30. Transport-type: tcp
  31. Bricks:
  32. Brick1: mystorage3:/storage/brick1
  33. Brick2: mystorage4:/storage/brick1
  34. Brick3: mystorage1:/storage/brick2
  35. Brick4: mystorage2:/storage/brick2
  36. Options Reconfigured:
  37. performance.readdir-ahead: on
11、移除 brick
  1. # 下面移除 gv2 卷的 2 个 bricks
  2. [root@mystorage1 ~]# gluster volume stop gv2
  3. Stopping volume will make its data inaccessible. Do you want to continue? (y/n) y
  4. volume stop: gv2: success
  5. [root@mystorage1 ~]# gluster volume remove-brick gv2 replica 2 mystorage3:/storage/brick1 mystorage4:/storage/brick1 force
  6. Removing brick(s) can result in data loss. Do you want to Continue? (y/n) y
  7. volume remove-brick commit force: success
  8. [root@mystorage1 ~]# gluster volume start gv2
  9. volume start: gv2: success
  10. [root@mystorage1 ~]# ll /gv2/
  11. total 40000
  12. -rw-r--r-- 1 root root 20480000 Jul 30 02:41 20M.file
  13. -rw-r--r-- 1 root root 20480000 Jul 30 03:13 20M.file1
  14. # 如果误操作删除了后,其实文件还在 /storage/brick1 里面的,加回来就可以了
  15. [root@mystorage1 ~]# gluster volume stop gv2
  16. Stopping volume will make its data inaccessible. Do you want to continue? (y/n) y
  17. volume stop: gv2: success
  18. [root@mystorage1 ~]# gluster volume add-brick gv2 replica 2 mystorage3:/storage/brick1 mystorage4:/storage/brick1 force
  19. volume add-brick: success
  20. [root@mystorage1 ~]# gluster volume info gv2
  21. Volume Name: gv2
  22. Type: Distributed-Replicate
  23. Volume ID: 11928696-263a-4c7a-a155-5115af29221f
  24. Status: Stopped
  25. Number of Bricks: 2 x 2 = 4
  26. Transport-type: tcp
  27. Bricks:
  28. Brick1: mystorage1:/storage/brick2
  29. Brick2: mystorage2:/storage/brick2
  30. Brick3: mystorage3:/storage/brick1
  31. Brick4: mystorage4:/storage/brick1
  32. Options Reconfigured:
  33. performance.readdir-ahead: on
  34. [root@mystorage1 ~]# gluster volume start gv2
  35. volume start: gv2: success
  36. [root@mystorage1 ~]# ll /gv2/ # 文件还在
  37. total 90000
  38. -rw-r--r-- 1 root root 10240000 Jul 30 02:40 10M.file
  39. -rw-r--r-- 1 root root 10240000 Jul 30 03:10 10M.file1
  40. -rw-r--r-- 1 root root 20480000 Jul 30 02:41 20M.file
  41. -rw-r--r-- 1 root root 20480000 Jul 30 03:13 20M.file1
  42. -rw-r--r-- 1 root root 30720000 Jul 30 02:40 30M.file
12、删除卷
  1. [root@mystorage1 ~]# umount /gv1
  2. [root@mystorage1 ~]# gluster volume stop gv1
  3. Stopping volume will make its data inaccessible. Do you want to continue? (y/n) y
  4. volume stop: gv1: success
  5. [root@mystorage1 ~]# gluster volume delete gv1
  6. Deleting volume will erase all information about the volume. Do you want to continue? (y/n) y
  7. volume delete: gv1: success
  8. [root@mystorage1 ~]# gluster volume info gv1
  9. Volume gv1 does not exist
文档更新时间: 2019-07-17 11:47   作者:张尚