Ubuntu下安装GlusterFS

1 安装

1.1 配置要求

1 硬件要求

GlusterFS支持大多数的符合商业标准的x86-64bit硬件平台。存储可以是直接附加的存储,RAID盘,以SATA/SAS/FC盘做后端的FC/Infiniband/iSCSI SAN盘。

2 网路要求

GlusterFS支持千兆网,百兆网和Infiniband(光纤)。

3 操作系统要求

GlusterFS可以支持很多POSIX兼容的系统,如GNU/Linux, FreeBSD, OpenSolaris, Solaris, 和Mac OS X。Gluster建议采用Ext3, Ext4或者ZFS作为子系统磁盘的格式。Gluster对GNU/linux, Mac OS X, FreeBSD和OpenSolaris有内嵌的支持。

1.2 Ubuntu下安装

Ubuntu 14: install software-properties-common:

    sudo apt-get install software-properties-common

Then add the community GlusterFS PPA:

    sudo add-apt-repository ppa:gluster/glusterfs-3.8
    sudo apt-get update

Finally, install the packages:

    sudo apt-get install glusterfs-server


1.3 gluster安装包下载

https://download.gluster.org/pub/gluster/glusterfs/

1.4 源码安装

1.4.1 安装

  1. ./configure  
  2. make  
  3. make install  

1.4.2 问题

  1. # ./configure   
  2. configure: error: no acceptable C compiler found in $PATH  

解决:apt-get install build-essential

  1. configure: error: Flex or lex required to build glusterfs.  
解决:apt-get install flex
  1. configure: error: GNU Bison required to build glusterfs.  
解决:apt-get install bison
  1. # ./configure   
  2. configure: error: OpenSSL crypto library is required to build glusterfs  

解决:apt-get install libssl-dev

  1. error: Support for POSIX ACLs is required  

解决:apt-get install libacl1 libacl1-dev

  1. checking for SQLITE... configure: error: pass --disable-tiering to build without sqlite  
解决:./configure --disable-tiering
  1. configure: error: liburcu-bp not found  
解决:apt-get install liburcu1 liburcu-dev
  1. # /usr/local/sbin/gluster  
  2. /usr/local/sbin/gluster: error while loading shared libraries: libglusterfs.so.0: cannot open shared object file: No such file or directory  
解决:执行命令ldconfig

1.4.3 卸载

执行make命令:

  1. make uninstall-recursive  
  2. make uninstall  
  3. make mostlyclean-recursive  
  4. make clean-recursive  
  5. make distclean-recursive  
再执行:
  1. # for i in `find / -name "gluster*"`; do rm -rf $i; done  

2 安装

2.1 部署拓扑

3台存储服务器: 192.168.4.132、192.168.4.133、192.168.4.134
  1. root@block2:/glusterfs# cat /etc/hosts  
  2. 127.0.0.1   localhost  
  3. 192.168.4.130   controller  
  4. 192.168.4.131   network  
  5. 192.168.4.132   compute  
  6. 192.168.4.133   block1  
  7. 192.168.4.134   block2  

2.2 安装

在所有存储服务器上执行安装。


2.2.1 如果出现错误:

  1. W: Failed to fetch http://ppa.launchpad.net/gluster/glusterfs-3.8/ubuntu/dists/trusty/main/binary-amd64/Packages  Hash Sum mismatch  
  2.   
  3. W: Failed to fetch http://ppa.launchpad.net/gluster/glusterfs-3.8/ubuntu/dists/trusty/main/binary-i386/Packages  Hash Sum mismatch  
  4.   
  5. W: Failed to fetch http://ppa.launchpad.net/gluster/glusterfs-3.8/ubuntu/dists/trusty/main/i18n/Translation-en  Hash Sum mismatch  
  6.   
  7. E: Some index files failed to download. They have been ignored, or old ones used instead.  
是因为没有把这3个文件取到/var/lib/apt/lists目录下。正常情况下:
  1. root@block1:~# ls /var/lib/apt/lists/ppa*  
  2. /var/lib/apt/lists/ppa.launchpad.net_gluster_glusterfs-3.8_ubuntu_dists_trusty_InRelease  
  3. /var/lib/apt/lists/ppa.launchpad.net_gluster_glusterfs-3.8_ubuntu_dists_trusty_main_binary-amd64_Packages  
  4. /var/lib/apt/lists/ppa.launchpad.net_gluster_glusterfs-3.8_ubuntu_dists_trusty_main_binary-i386_Packages  
  5. /var/lib/apt/lists/ppa.launchpad.net_gluster_glusterfs-3.8_ubuntu_dists_trusty_main_i18n_Translation-en  

解决方法:
将/var/lib/apt/lists/partial/下的所有文件删除,但是这可以解决大部分问题,个别源不能解决,
注:经过长时间的实践,这个解决方法不是万能的。 


2.2.2 安装glusterfs-server时,会安装glusterfs-client

  1. root@block2:/glusterfs# apt-get install glusterfs-server  
  2. Reading package lists... Done  
  3. Building dependency tree         
  4. Reading state information... Done  
  5. The following extra packages will be installed:  
  6.   attr glusterfs-client glusterfs-common liblvm2app2.2 liburcu1  
  7. The following NEW packages will be installed:  
  8.   attr glusterfs-client glusterfs-common glusterfs-server liblvm2app2.2  
  9.   liburcu1  
  10. 0 upgraded, 6 newly installed, 0 to remove and 4 not upgraded.  
  11. Need to get 3,389 kB of archives.  
  12. After this operation, 16.0 MB of additional disk space will be used.  
  13. Do you want to continue? [Y/n]   

安装成功后,gluster会运行。查看版本:
  1. root@block2:/glusterfs# glusterfs --version  
  2. glusterfs 3.8.10  
  1. root@block2:/glusterfs# ps -ef | grep gluster  
  2. root     17920     1  0 17:58 ?        00:00:00 /usr/sbin/glusterd -p /var/run/glusterd.pid  


2.3 查看运行端口

  1. root@compute: # netstat -pan | grep glus  
  2. tcp        0      0 0.0.0.0:24007           0.0.0.0:*               LISTEN      5323/glusterd     
  3. tcp        0      0 192.168.4.132:24007     192.168.4.133:1023      ESTABLISHED 5323/glusterd     
  4. tcp        0      0 192.168.4.132:1023      192.168.4.134:24007     ESTABLISHED 5323/glusterd     
  5. tcp        0      0 192.168.4.132:24007     192.168.4.134:1020      ESTABLISHED 5323/glusterd     
  6. tcp        0      0 192.168.4.132:1021      192.168.4.133:24007     ESTABLISHED 5323/glusterd    

2.4 服务启停

使用命令:service glusterfs-server start/stop

  1. root@compute:~# ps -ef | grep gluster  
  2. root     10929     1  0 Mar16 ?        00:00:00 /usr/sbin/glusterd -p /var/run/glusterd.pid  
  3. root     12215  1650  0 10:22 pts/0    00:00:00 grep --color=auto gluster  
  4. root@compute:~# ls /etc/init.d/glusterfs*  
  5. /etc/init.d/glusterfs-server  
  6. root@compute:~# service glusterfs-server stop  
  7. glusterfs-server stop/waiting  
  8. root@compute:~# ps -ef | grep gluster  
  9. root     12225  1650  0 10:23 pts/0    00:00:00 grep --color=auto gluster  
  10. root@compute:~# service glusterfs-server start  
  11. glusterfs-server start/running, process 12233  
  12. root@compute:~# ps -ef | grep gluster  
  13. root     12233     1  0 10:23 ?        00:00:00 /usr/sbin/glusterd -p /var/run/glusterd.pid  
  14. root     12467  1650  0 10:23 pts/0    00:00:00 grep --color=auto gluster  


集群关联

3.1创建GlusterFS集群

$ gluster peer probe SERVER     SERVER表示存储服务器的hostname。

在服务器192.168.4.132上执行:

  1. root@compute:~#  gluster peer probe   
  2. Usage: peer probe <HOSTNAME>  
  3. root@compute:~#  gluster peer probe block1  
  4. peer probe: success  
  5. root@compute:~# gluster peer probe block2  
  6. peer probe: success  
 注意:在构建 GlusterFS 集群时,需要在其中任意一台存储服务器上依次将其他存储服务器添加到集群中。

3.2  查看集群信息

指令:gluster peer status

  1. root@compute:/etc/glusterfs# gluster peer status  
  2. Number of Peers: 2  
  3.   
  4. Hostname: block1  
  5. Port: 24007  
  6. Uuid: ac468b50-3d66-4290-aa8d-cb01279e9bf2  
  7. State: Peer in Cluster (Connected)  
  8.   
  9. Hostname: block2  
  10. Port: 24007  
  11. Uuid: 06288da0-1b18-42fb-a7b8-cd9ca24d5f26  
  12. State: Peer in Cluster (Connected)  
  13.   
  14. root@block1:/etc/glusterfs# gluster peer status  
  15. Number of Peers: 2  
  16.   
  17. Hostname: 192.168.4.132  
  18. Port: 24007  
  19. Uuid: 9fdd15f2-c7e1-44e1-9315-d62e1dcfb44d  
  20. State: Peer in Cluster (Connected)  
  21.   
  22. Hostname: block2  
  23. Uuid: 06288da0-1b18-42fb-a7b8-cd9ca24d5f26  
  24. State: Peer in Cluster (Connected)  
  25. root@block1:/etc/glusterfs# gluster volume info  
  26. No volumes present  

Connected,说明集群节点添加成功,但其中compute是以192.168.4.132这个ip加入集群的,如果需要换成hostname,登陆集群中的集群中的另一个节点,执行:


  1. root@block1:~# gluster peer detach 192.168.4.132  
  2. peer detach: success  
  3. root@block1:~#   
  4. root@block1:~# gluster peer status  
  5. Number of Peers: 1  
  6.   
  7. Hostname: block2  
  8. Uuid: 06288da0-1b18-42fb-a7b8-cd9ca24d5f26  
  9. State: Peer in Cluster (Connected)  
  10. root@block1:~#   
  11. root@block1:~#  gluster peer probe compute  
  12. peer probe: success.   
  13. root@block1:~#   
  14. root@block1:~# gluster peer status  
  15. Number of Peers: 2  
  16.   
  17. Hostname: block2  
  18. Uuid: 06288da0-1b18-42fb-a7b8-cd9ca24d5f26  
  19. State: Peer in Cluster (Connected)  
  20.   
  21. Hostname: compute  
  22. Uuid: 9fdd15f2-c7e1-44e1-9315-d62e1dcfb44d  
  23. State: Peer in Cluster (Connected)  

4 Volume卷操作

基本卷:

(1)  distribute volume:分布式卷

文件通过hash算法分布到所有brick server上,这种卷是glusterfs的基础和最大特点。优点是容量大,缺点是没冗余。

(2)  stripe volume:条带卷

类似RAID0,文件分成数据块以Round Robin方式分布到brick server上,并发粒度是数据块,支持超大文件,大文件性能高优点是分布式读写,性能整体较好。缺点是没冗余,分片随机读写可能会导致硬盘IOPS饱和。

(3)  replica volume:复制卷

文件同步复制到多个brick上,文件级RAID 1,具有容错能力,写性能下降,读性能提升。缺点是磁盘利用率低。

复合卷:

(4)  distribute stripe volume:分布式条带卷

brickserver数量是条带数的倍数,兼具distribute和stripe卷的特点;

(5)  distribute replica volume:分布式复制卷

brickserver数量是镜像数的倍数,兼具distribute和replica卷的特点,可以在2个或多个节点之间复制数据。

(6) stripe replica volume:条带复制卷

类似RAID 10

同时具有条带卷和复制卷的特点

(7) distribute stripe replicavolume:分布式条带复制卷

三种基本卷的复合卷

通常用于类Map Reduce应用

(8) 冗余卷(Dispersed volume)

近似于raid5,文件分片存储在各个硬盘上,但有部分硬盘用于冗余用途,数量可以指定。比如一共10块硬盘,2块盘用于冗余,那么就可以承受同时损坏两块硬盘,总容量是8块盘。

优点是在冗余和性能之间取得平衡


4.1.创建volume


a. 单磁盘,调试环境推荐
sudo gluster volume create vol_name 172.17.0.2:/d/disk0

b. 多磁盘,无raid,试验、测试环境推荐。
sudo gluster volume create vol_name 172.17.0.2:/d/disk0 172.17.0.3:/d/disk0 172.17.0.4:/d/disk0 172.17.0.5:/d/disk0

c. 多磁盘,有raid1。线上高并发环境推荐。
  1. Usage: volume create <NEW-VOLNAME> [stripe <COUNT>] [replica <COUNT> [arbiter <COUNT>]] [disperse [<COUNT>]] [disperse-data <COUNT>] [redundancy <COUNT>] [transport <tcp|rdma|tcp,rdma><NEW-BRICK>?<vg_name>... [force]  
注意:以上命令中,磁盘数量必须为复制份数的整数倍。

实验命令是在根目录下创建目录/glusterfs,要在所有的3台服务器上都创建这个目录,否则会出错。

  1. root@compute:~# gluster volume create zhai-volume replica 2 192.168.4.132:/glusterfs/brick1 block1:/glusterfs/brick1  block2:/glusterfs/brick1  
  2. number of bricks is not a multiple of replica count  
  3. Usage: volume create <NEW-VOLNAME> [stripe <COUNT>] [replica <COUNT> [arbiter <COUNT>]] [disperse [<COUNT>]] [disperse-data <COUNT>] [redundancy <COUNT>] [transport <tcp|rdma|tcp,rdma><NEW-BRICK>?<vg_name>... [force]  
  4. root@compute:~#   
  5. root@compute:~# gluster volume create zhai-volume replica 2 compute:/glusterfs/brick1 compute:/glusterfs/brick2 block1:/glusterfs/brick1 block1:/glusterfs/brick2 block2:/glusterfs/brick1 block2:/glusterfs/brick2  
  6. volume create: zhai-volume: failed: The brick compute:/glusterfs/brick1 is being created in the root partition. It is recommended that you don't use the system's root partition for storage backend. Or use 'force' at the end of the command if you want to override this behavior.  
  7. root@compute:~#   
  8. root@compute:~# ls /glusterfs/  
  9. root@compute:~#   
  10. root@compute:~# gluster volume create zhai-volume replica 2 compute:/glusterfs/brick1 compute:/glusterfs/brick2 block1:/glusterfs/brick1 block1:/glusterfs/brick2 block2:/glusterfs/brick1 block2:/glusterfs/brick2 force  
  11. volume create: zhai-volume: failed: Staging failed on block2. Error: Failed to create brick directory for brick block2:/glusterfs/brick1. Reason : No such file or directory   
  12. Staging failed on block1. Error: Failed to create brick directory for brick block1:/glusterfs/brick1. Reason : No such file or directory   
  13. root@compute:~#   
  14. root@compute:~# gluster volume create zhai-volume replica 2 compute:/glusterfs/brick1 compute:/glusterfs/brick2 block1:/glusterfs/brick1 block1:/glusterfs/brick2 block2:/glusterfs/brick1 block2:/glusterfs/brick2 force  
  15. volume create: zhai-volume: success: please start the volume to access data  
  16. root@compute:~#   
  17. root@compute:~# gluster volume info  
  18.    
  19. Volume Name: zhai-volume  
  20. Type: Distributed-Replicate  
  21. Volume ID: 779a7440-e127-43c6-a13f-7420ab8baec8  
  22. Status: Created  
  23. Snapshot Count: 0  
  24. Number of Bricks: 3 x 2 = 6  
  25. Transport-type: tcp  
  26. Bricks:  
  27. Brick1: compute:/glusterfs/brick1  
  28. Brick2: compute:/glusterfs/brick2  
  29. Brick3: block1:/glusterfs/brick1  
  30. Brick4: block1:/glusterfs/brick2  
  31. Brick5: block2:/glusterfs/brick1  
  32. Brick6: block2:/glusterfs/brick2  
  33. Options Reconfigured:  
  34. transport.address-family: inet  

Note : The number of bricks should be a multiple of the replica count for a distributed replicated volume. Also, the order in which bricks are specified has a great effect on data protection. Each replica_count consecutive bricks in the list you give will form a replica set, with all replica sets combined into a volume-wide distribute set.

volume创建成功后,会在每台服务器的/glusterfs目录下生成brick1和brick2目录。
查看日志:
  1. root@compute:~# tail -20 /var/log/glusterfs/cli.log  
  2. [2017-03-17 03:01:38.518626] I [cli.c:728:main] 0-cli: Started running gluster with version 3.8.10  
  3. [2017-03-17 03:01:38.608896] I [MSGID: 101190] [event-epoll.c:628:event_dispatch_epoll_worker] 0-epoll: Started thread with index 1  
  4. [2017-03-17 03:01:38.608958] I [socket.c:2403:socket_event_handler] 0-transport: disconnecting now  
  5. [2017-03-17 03:01:38.619870] I [cli-rpc-ops.c:1117:gf_cli_create_volume_cbk] 0-cli: Received resp to create volume  
  6. [2017-03-17 03:01:38.619953] I [input.c:31:cli_batch] 0-: Exiting with: -1  
  7. [2017-03-17 03:02:34.746102] I [cli.c:728:main] 0-cli: Started running gluster with version 3.8.10  
  8. [2017-03-17 03:02:34.837934] I [MSGID: 101190] [event-epoll.c:628:event_dispatch_epoll_worker] 0-epoll: Started thread with index 1  
  9. [2017-03-17 03:02:34.838008] I [socket.c:2403:socket_event_handler] 0-transport: disconnecting now  
  10. [2017-03-17 03:02:36.111778] I [cli-rpc-ops.c:1117:gf_cli_create_volume_cbk] 0-cli: Received resp to create volume  
  11. [2017-03-17 03:02:36.111888] I [input.c:31:cli_batch] 0-: Exiting with: 0  

4.2.启动volume

刚创建好的volume还没有运行,需要执行运行命令方可使用。 在其中一台服务器上执行。
sudo gluster volume start vol_name
  1. root@compute:~# ps -ef | grep volume  
  2. root     12663  1650  0 11:16 pts/0    00:00:00 grep --color=auto volume  
  3. root@compute:~# gluster volume start zhai-volume  
  4. volume start: zhai-volume: success  
  5. root@compute:~# ps -ef | grep volume  
  6. root     12683     1  0 11:16 ?        00:00:00 /usr/sbin/glusterfsd -s compute --volfile-id zhai-volume.compute.glusterfs-brick1 -p /var/lib/glusterd/vols/zhai-volume/run/compute-glusterfs-brick1.pid -S /var/run/gluster/233b16b60a6dacf67c1b711bb1e7e89c.socket --brick-name /glusterfs/brick1 -l /var/log/glusterfs/bricks/glusterfs-brick1.log --xlator-option *-posix.glusterd-uuid=9fdd15f2-c7e1-44e1-9315-d62e1dcfb44d --brick-port 49152 --xlator-option zhai-volume-server.listen-port=49152  
  7. root     12702     1  0 11:16 ?        00:00:00 /usr/sbin/glusterfsd -s compute --volfile-id zhai-volume.compute.glusterfs-brick2 -p /var/lib/glusterd/vols/zhai-volume/run/compute-glusterfs-brick2.pid -S /var/run/gluster/55ba583ae215e8215759c8d1aca9548c.socket --brick-name /glusterfs/brick2 -l /var/log/glusterfs/bricks/glusterfs-brick2.log --xlator-option *-posix.glusterd-uuid=9fdd15f2-c7e1-44e1-9315-d62e1dcfb44d --brick-port 49153 --xlator-option zhai-volume-server.listen-port=49153  
  8. root     12729  1650  0 11:16 pts/0    00:00:00 grep --color=auto volume  
  1. root@block1:~# ps -ef | grep zhai-volume  
  2. root     26213     1  0 11:16 ?        00:00:00 /usr/sbin/glusterfsd -s block1 --volfile-id zhai-volume.block1.glusterfs-brick1 -p /var/lib/glusterd/vols/zhai-volume/run/block1-glusterfs-brick1.pid -S /var/run/gluster/98664ae15cd31af2fd3394f1a239d85b.socket --brick-name /glusterfs/brick1 -l /var/log/glusterfs/bricks/glusterfs-brick1.log --xlator-option *-posix.glusterd-uuid=ac468b50-3d66-4290-aa8d-cb01279e9bf2 --brick-port 49152 --xlator-option zhai-volume-server.listen-port=49152  
  3. root     26232     1  0 11:16 ?        00:00:00 /usr/sbin/glusterfsd -s block1 --volfile-id zhai-volume.block1.glusterfs-brick2 -p /var/lib/glusterd/vols/zhai-volume/run/block1-glusterfs-brick2.pid -S /var/run/gluster/e4bf4eb272d50def1259ad279e81bc61.socket --brick-name /glusterfs/brick2 -l /var/log/glusterfs/bricks/glusterfs-brick2.log --xlator-option *-posix.glusterd-uuid=ac468b50-3d66-4290-aa8d-cb01279e9bf2 --brick-port 49153 --xlator-option zhai-volume-server.listen-port=49153  
  1. root@block2:~# ps -ef | grep zhai-volume  
  2. root     24570     1  0 11:16 ?        00:00:00 /usr/sbin/glusterfsd -s block2 --volfile-id zhai-volume.block2.glusterfs-brick1 -p /var/lib/glusterd/vols/zhai-volume/run/block2-glusterfs-brick1.pid -S /var/run/gluster/b5c757abb3485edb13b25f9aaac3c387.socket --brick-name /glusterfs/brick1 -l /var/log/glusterfs/bricks/glusterfs-brick1.log --xlator-option *-posix.glusterd-uuid=06288da0-1b18-42fb-a7b8-cd9ca24d5f26 --brick-port 49152 --xlator-option zhai-volume-server.listen-port=49152  
  3. root     24589     1  0 11:16 ?        00:00:00 /usr/sbin/glusterfsd -s block2 --volfile-id zhai-volume.block2.glusterfs-brick2 -p /var/lib/glusterd/vols/zhai-volume/run/block2-glusterfs-brick2.pid -S /var/run/gluster/0acc5e5ccc951203695b9654ef4dbd67.socket --brick-name /glusterfs/brick2 -l /var/log/glusterfs/bricks/glusterfs-brick2.log --xlator-option *-posix.glusterd-uuid=06288da0-1b18-42fb-a7b8-cd9ca24d5f26 --brick-port 49153 --xlator-option zhai-volume-server.listen-port=49153  

4.3.挂载volume

4.3.1 在3台服务器中任一服务器上挂载都可以。 

For this step, we will use one of the servers to mount the volume. Typically, you would do this from an external machine, known as a "client". Since using this method would require additional packages to be installed on the client machine, we willuse one of the servers as a simple place to test first, as if it were that "client".

# 挂载任一节点即可(推荐)

  1. root@compute:~# mount -t glusterfs 192.168.4.132:/zhai-volume /mnt  
  2. root@compute:~# df -h  
  3. Filesystem                  Size  Used Avail Use% Mounted on  
  4. udev                        3.9G   12K  3.9G   1% /dev  
  5. tmpfs                       788M  660K  787M   1% /run  
  6. /dev/dm-0                   909G  2.4G  860G   1% /  
  7. none                        4.0K     0  4.0K   0% /sys/fs/cgroup  
  8. none                        5.0M     0  5.0M   0% /run/lock  
  9. none                        3.9G     0  3.9G   0% /run/shm  
  10. none                        100M     0  100M   0% /run/user  
  11. /dev/sda2                   237M   91M  134M  41% /boot  
  12. /dev/sda1                   511M  3.4M  508M   1% /boot/efi  
  13. 192.168.4.132:/zhai-volume  2.7T  6.0G  2.6T   1% /mnt  

4.3.2 在3台服务器之外的服务器上挂载

需要安装glusterfs-client包
否则,出错:

  1. root@network:~# mount -t glusterfs 192.168.4.132:/zhai-volume /mnt  
  2. mount: unknown filesystem type 'glusterfs'  

安装

  1. sudo  apt-get  install  glusterfs-client  

安装后,执行挂载

  1. # mount -t glusterfs 10.10.30.4:/zhai-volume /mnt  
  2. Mount failed. Please check the log file for more details.  
原因: 没有在/etc/hosts中添加glusterfs集群中各个服务器的信息

4.3.3 开机挂载

# 若需要开机自动挂载,请更新/etc/fstab

4.4.使用GlusterFS

a. 挂载了GlusterFS的某个卷后,就可以将其当做本地文件访问,代码中只需使用原生的文件api即可。这种方式使用不一定需要root权限,只要拥有对应目录或文件的权限即可。
b. 直接API方式,这种方式需要root权限才能使用,并且java、python、ruby的api包装目前都不够完整,一般情况不推荐使用。

测试1:

到/mnt目录下创建文件:

  1. root@compute:/mnt# uname -a >info  
  2. root@compute:/mnt# ls  
  3. info  
  4. root@compute:/mnt# cat info   
  5. Linux compute 4.4.0-31-generic #50~14.04.1-Ubuntu SMP Wed Jul 13 01:07:32 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux  
在3台服务器上查看, 在block2服务器上生成文件,在block1和compute结点上没有生成文件
  1. root@block2:~# ls /glusterfs/brick1/  
  2. info  
  3. root@block2:~# ls /glusterfs/brick2  
  4. info  
  5. root@block2:~# cat /glusterfs/brick1/info   
  6. Linux compute 4.4.0-31-generic #50~14.04.1-Ubuntu SMP Wed Jul 13 01:07:32 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux  

测试2:

    mount -t glusterfs server1:/gv0 /mnt
      for i in `seq -w 1 100`; do cp -rp /var/log/messages /mnt/copy-test-$i; done

First, check the mount point:

    ls -lA /mnt | wc -l

You should see 100 files returned. Next, check the GlusterFS mount points on each server:

    ls -lA /data/brick1/gv0

You should see 100 files on each server using the method we listed here. Without replication, in a distribute only volume (not detailed here), you should see about 50 files on each one.

4.5.卸载volume

卸载与挂载操作是一对。虽然没有卸载也可以停止volume,但是这样做是会出问题,如果集群较大,可能导致后面volume启动失败。
sudo umount /mnt

4.6.停止volume

停止与启动操作是一对。停止前最好先卸载所有客户端。
sudo gluster volume stop vol_name

4.7.删除volume

删除与创建操作是一对。删除前需要先停止volume。在生产上一般不会删除volume
sudo gluster volume delete vol_name

5 使用独立存储

使用独立/dev/sdb

5.1 分区

fdisk /dev/sdb //创建分区,输入,n,p,w,创建新主分区并写入分区表

5.2 Format and mount the bricks

(on both nodes): Note: These examples are going to assume the brick is going to reside on /dev/sdb1.

    mkfs.xfs -i size=512 /dev/sdb1
    mkdir -p /data/brick1
    echo '/dev/sdb1 /data/brick1 xfs defaults 1 2' >> /etc/fstab
    mount -a && mount

You should now see sdb1 mounted at /data/brick1

  1. root@block1:~# mkfs.xfs -i size=512 /dev/sdb1  
  2. root@compute:~# echo '/dev/sdb1 /glusterfs xfs defaults 1 2' >> /etc/fstab  
  3. root@compute:~# mount -a && mount  
  4. /dev/mapper/compute--vg-root on / type ext4 (rw,errors=remount-ro)  
  5. proc on /proc type proc (rw,noexec,nosuid,nodev)  
  6. sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)  
  7. none on /sys/fs/cgroup type tmpfs (rw)  
  8. none on /sys/fs/fuse/connections type fusectl (rw)  
  9. none on /sys/kernel/debug type debugfs (rw)  
  10. none on /sys/kernel/security type securityfs (rw)  
  11. none on /sys/firmware/efi/efivars type efivarfs (rw)  
  12. udev on /dev type devtmpfs (rw,mode=0755)  
  13. devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)  
  14. tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)  
  15. none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)  
  16. none on /run/shm type tmpfs (rw,nosuid,nodev)  
  17. none on /run/user type tmpfs (rw,noexec,nosuid,nodev,size=104857600,mode=0755)  
  18. none on /sys/fs/pstore type pstore (rw)  
  19. tracefs on /var/lib/ureadahead/debugfs/tracing type tracefs (rw,relatime)  
  20. /dev/sda2 on /boot type ext2 (rw)  
  21. /dev/sda1 on /boot/efi type vfat (rw)  
  22. systemd on /sys/fs/cgroup/systemd type cgroup (rw,noexec,nosuid,nodev,none,name=systemd)  
  23. rpc_pipefs on /run/rpc_pipefs type rpc_pipefs (rw)  
  24. 192.168.4.132:/zhai-volume on /mnt type fuse.glusterfs (rw,default_permissions,allow_other,max_read=131072)  
  25. /dev/sdb1 on /glusterfs type xfs (rw)  
  26.   
  27.   
  28. root@compute:~# df -h  
  29. Filesystem      Size  Used Avail Use% Mounted on  
  30. udev            3.9G   12K  3.9G   1% /dev  
  31. tmpfs           788M  660K  787M   1% /run  
  32. /dev/dm-0       909G  2.4G  860G   1% /  
  33. none            4.0K     0  4.0K   0% /sys/fs/cgroup  
  34. none            5.0M     0  5.0M   0% /run/lock  
  35. none            3.9G     0  3.9G   0% /run/shm  
  36. none            100M     0  100M   0% /run/user  
  37. /dev/sda2       237M   91M  134M  41% /boot  
  38. /dev/sda1       511M  3.4M  508M   1% /boot/efi  
  39. /dev/sdb1       932G   34M  932G   1% /glusterfs  

mount之后再安装glusterfs

5.3 其它命令

  1. #apt-get install xfsprogs //安装xfs文件系统(如果没有的话),更安全可靠  
  2.   
  3. #lshw -short    //查看硬件信息,主要是查看硬盘信息,以决定哪块硬盘作为gluster来使用  
  4. 或使用lsblk来查看块设备  
  5. #lsblk  
Note : The number of bricks should be a multiple of the replica count for a distributed replicated volume. Also, the order in which bricks are specified has a great effect on data protection. Each replica_count consecutive bricks in the list you give will form a replica set, with all replica sets combined into a volume-wide distribute set.

6 相关问题

1 Q: 创建/启用/停用/删除volume最终都干了些什么?

(1) 创建volume能看得到的结果是: glusterd在工作目录(默认为/var/lib/glusterd)的vols目录下,创建以volume名称为名字的目录,并在这个目录下创建相关文件记录volume的相关信息;看不到的结果是glusterd程序中也记录了volume的相关信息。

(2) 启用volume的结果是在指定brick的节点上启动glusterfsd和glusterfs进程(注意:如果多个brick在同一节点下,会有多个glusterfsd进程,但只有一个glusterfs进程),同时在日志文件中更新记录的volume相关信息。

(3) 停用volume的结果是结束glusterfsd和glusterfs进程。

(4)删除volume则是将创建volume的相关文件信息全部清除。


2 错误

  1. root@compute:~# gluster volume create volume-test block1:/glusterfs/repbrick block2:/glusterfs/repbrick  
  2. volume create: volume-test: failed: Staging failed on block2. Error: Brick: block2:/glusterfs/repbrick not available. Brick may be containing or be contained by an existing brick  
  3. Staging failed on block1. Error: Brick: block1:/glusterfs/repbrick not available. Brick may be containing or be contained by an existing brick  

这是因为创建volume时,在brick对应的存储目录上,增加了"trusted.glusterfs.volume-id"和"trusted.gfid"两个扩展属性,在删除volume时并未移除这两个属性,再次创建时,对brick的存储目录进行校验,发现已经有了扩展属性,因此会有brick已经是volume的一部分的提示。

通过getfattr命令可以查看这些存储路径的扩展属性

  1. root@block2:~# getfattr -d -m ".*" /glusterfs/repbrick  
  2. getfattr: Removing leading '/' from absolute path names  
  3. # file: glusterfs/repbrick  
  4. trusted.glusterfs.volume-id=0sS29pmfEgRDyMNCX3YAbwsQ==  
设置属性
  1. setfattr -n trusted.glusterfs.volume-id -v 0x$(grep volume-id /var/lib/glusterd/vols/volume-down-fault/info  | cut -d= -f2 | sed 's/-//g') /glusterfs/brick2  


可执行程序

glusterfs安装后,会有gluster,glusterd,glusterfs,glusterfsd这么几个可执行程序,其作用分别为:

gluster:Glusterfs控制台管理程序(Gluster Console Manager),可以以命令形式或者交互式形式对glusterfs中的volume,brick,集群节点等信息进行查看及操作(增,删,改)。

glusterd:软链接指向glusterfsd,Glusterfs的管理进程,负责处理来自gluster的命令。

glusterfs:软链接指向glusterfsd,Glusterfs自带的客户端

glusterfsd:Glusterfs服务端程序

注:glusterd,glusterfs,glusterfsd为最终是运行同一个程序(glusterfsd),程序内部会根据可执行程序名称加以区别。

  1. staticuint8_t gf_get_process_mode (char*exec_name)  
  2. {  
  3.     char*dup_execname = NULL, *base = NULL;  
  4.     uint8_t ret = 0;  
  5.    
  6.     dup_execname = gf_strdup (exec_name);  
  7.     base = basename (dup_execname);  
  8.        
  9.     if(!strncmp (base, "glusterfsd", 10)) {  
  10.         ret = GF_SERVER_PROCESS;  
  11.     }else if (!strncmp(base, "glusterd", 8)) {  
  12.         ret = GF_GLUSTERD_PROCESS;  
  13.     }else {  
  14.         ret = GF_CLIENT_PROCESS;  
  15.     }  
  16.     GF_FREE (dup_execname);  
  17.     returnret;  
  18. }  

客户端依靠nfs协议(或gluster native协议)动态的从服务端获取卷的信息。

如果建立的是复制卷,gluster客户端会并发的向几个服务器写入\读取数据,而不是通过服务器之间进行数据的传输。


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值