Glusterfs 分布式存儲部署 是存儲當中可以選擇的一種 現在很多虛擬化 雲計算都在用軟件存儲 例如 ceph
Glusterfs 等等 今天我們部署一下Glusterfs環境
GlusterFs安裝
環境信息:
Glusterfs-01 | 10.20.0.200 |
Glusterfs-02 | 10.20.0.201 |
Glusterfs-03 | 10.20.0.202 |
硬盤各一塊 8G 測試 /dev/sdb
服務器版本信息
# cat /etc/redhat-release CentOS release 6.6 (Final)
# uname -r
2.6.32-504.el6.x86_64
軟件下載地址
http://download.gluster.org/pub/gluster/glusterfs/3.4/3.4.6/CentOS/epel-6.6/x86_64
依賴包安裝
直接用Yum安裝 每台都需要安裝
# yum -y install libibverbs librdmacm xfsprogs nfs-utils rpcbind libaio liblvm2app lvm2-devel
軟件安裝
安裝服務器端軟件包
glusterfs-3.4.6-1.el6.x86_64.rpm glusterfs-api-3.4.6-1.el6.x86_64.rpm glusterfs-cli-3.4.6-1.el6.x86_64.rpm glusterfs-fuse-3.4.6-1.el6.x86_64.rpm glusterfs-libs-3.4.6-1.el6.x86_64.rpm glusterfs-server-3.4.6-1.el6.x86_64.rpm
安裝客戶端軟件包
glusterfs-3.4.6-1.el6.x86_64.rpm glusterfs-fuse-3.4.6-1.el6.x86_64.rpm glusterfs-libs-3.4.6-1.el6.x86_64.rpm
磁盤配置
磁盤分區:
EXT4格式化工具目前最大支持16TB
使用parted進行磁盤分區
分區格式化
每個服務器上面都需要至少添加一塊硬盤 我們這邊是用的1塊8G硬盤 現在每台都格式化
# mkfs.ext4 -L /brick1 /dev/sdb mke2fs 1.41.12 (17-May-2010) /dev/sdb is entire device, not just one partition! Proceed anyway? (y,n) y Filesystem label=/brick1 OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 524288 inodes, 2097152 blocks 104857 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2147483648 64 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 39 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
自動掛載分區
# vim /etc/fstab
LABEL=/brick1 /brick1 ext4 defaults 0 0
mount文件系統
# mkdir /brick1 # mount -L /brick1 /brick1/ # df -kh Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup-lv_root 47G 759M 44G 2% / tmpfs 491M 0 491M 0% /dev/shm /dev/sda1 477M 28M 425M 6% /boot /dev/sdb 7.8G 18M 7.4G 1% /brick1
基礎測試包安裝 性能測試包
工具軟件
Atop,iperf,sysstat
dd,lozone,fio,postmark
工具安裝
#rpm -ivh http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum install sysstat
Gcc -o postmark postmark-1.52.c
有些可以用yum安裝
安裝GlusterFS軟件包
每台創建存放軟件的目錄 我們目前安裝的是3.4.6的版本
#mdkir /home/tools/3.4.6 -p
#cd /home/tools/3.4.6 # ll total 2164 -rw-r--r-- 1 root root 1027320 Oct 4 11:13 glusterfs-3.4.6-1.el6.x86_64.rpm -rw-r--r-- 1 root root 66680 Oct 4 11:13 glusterfs-api-3.4.6-1.el6.x86_64.rpm -rw-r--r-- 1 root root 108872 Oct 4 11:14 glusterfs-cli-3.4.6-1.el6.x86_64.rpm -rw-r--r-- 1 root root 88452 Oct 4 11:14 glusterfs-fuse-3.4.6-1.el6.x86_64.rpm -rw-r--r-- 1 root root 124288 Oct 4 11:14 glusterfs-geo-replication-3.4.6-1.el6.x86_64.rpm -rw-r--r-- 1 root root 227900 Oct 4 11:14 glusterfs-libs-3.4.6-1.el6.x86_64.rpm -rw-r--r-- 1 root root 50128 Oct 4 11:14 glusterfs-rdma-3.4.6-1.el6.x86_64.rpm -rw-r--r-- 1 root root 504744 Oct 4 11:14 glusterfs-server-3.4.6-1.el6.x86_64.rpm
直接rpm安裝
# rpm -ivh *.rpm warning: glusterfs-3.4.6-1.el6.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 4ab22bb3: NOKEY Preparing... ########################################### [100%] 1:glusterfs-libs ########################################### [ 13%] 2:glusterfs ########################################### [ 25%] 3:glusterfs-fuse ########################################### [ 38%] 4:glusterfs-cli ########################################### [ 50%] 5:glusterfs-server ########################################### [ 63%] 6:glusterfs-geo-replicati########################################### [ 75%] 7:glusterfs-api ########################################### [ 88%] 8:glusterfs-rdma ########################################### [100%]
安裝成功啟動GlusterFS
# service glusterd start
Starting glusterd: [ OK ]
# chkconfig glusterd on
組建集群擴展
在GlusterFS-01服務器上面操作 選擇10.20.0.200 作為當前集群節點
添加另外兩台服務器
# gluster peer probe 10.20.0.201 peer probe: success # gluster peer probe 10.20.0.202 peer probe: success
GlusterFS-01服務器查看添加狀態
# gluster peer status Number of Peers: 2 Hostname: 10.20.0.201 Port: 24007 Uuid: c4d9edfd-d6ae-4628-8ab3-5a9fbb5f18fc State: Peer in Cluster (Connected) Hostname: 10.20.0.202 Port: 24007 Uuid: c0b425bb-a7b4-4dae-bc19-ea6031bf02b9 State: Peer in Cluster (Connected)
GlusterFS-02服務器查看添加狀態
# gluster peer status Number of Peers: 2 Hostname: 10.20.0.200 Port: 24007 Uuid: 7ad4db05-ee75-44e6-8213-e58072b62d33 State: Peer in Cluster (Connected) Hostname: 10.20.0.202 Uuid: c0b425bb-a7b4-4dae-bc19-ea6031bf02b9 State: Peer in Cluster (Connected)
GlusterFS-03服務器查看添加狀態
# gluster peer status Number of Peers: 2 Hostname: 10.20.0.200 Port: 24007 Uuid: 7ad4db05-ee75-44e6-8213-e58072b62d33 State: Peer in Cluster (Connected) Hostname: 10.20.0.201 Uuid: c4d9edfd-d6ae-4628-8ab3-5a9fbb5f18fc State: Peer in Cluster (Connected)
表示成功
如果添加不成功 排除錯誤:
1,每台服務器是否能否Ping通
2,防火牆是否關閉iptables selinux
3,glusterd服務是否啟動成功
創建卷
- 確定創建卷的類型
- 確定創建卷的brick列表
- 確實創建卷的網絡類型(TCP/RDMA)
Gluster volume create創建卷
在GlusterFS-01服務器上面操作 可以任選一台
# gluster volume create dht-vol1 10.20.0.200:/brick1/b1 10.20.0.201:/brick1/b2 10.20.0.202:/brick1/b 3 volume create: dht-vol1: success: please start the volume to access data
(1)distribute volume:分布式卷,文件通過hash算法分布到brick server上,這種卷是glusterfs的基礎和最大特點;
(2)stripe volume:條帶卷,類似RAID0,條帶數=brick server數量,文件分成數據塊以Round Robin方式分布到brick server上,並發粒度是數據塊,大文件性能高;
(3)replica volume:鏡像卷,類似RAID1,鏡像數=brick server數量,所以brick server上文件數據相同,構成n-way鏡像,可用性高;
(4)distribute stripe volume:分布式條帶卷,brick server數量是條帶數的倍數,兼具distribute和stripe卷的特點;
(5)distribute replica volume:分布式鏡像卷,brick server數量是鏡像數的倍數,兼具distribute和replica卷的特點
查看卷狀態信息
# gluster volume info Volume Name: dht-vol1 Type: Distribute Volume ID: 7d947cf1-c743-477e-a28d-7d030572b655 Status: Created Number of Bricks: 3 Transport-type: tcp Bricks: Brick1: 10.20.0.200:/brick1/b1 Brick2: 10.20.0.201:/brick1/b2 Brick3: 10.20.0.202:/brick1/b3
啟動卷
# gluster volume start dht-vol1
volume start: dht-vol1: success
客戶端掛載卷
# mkdir /data # mount -t glusterfs 10.20.0.200:/dth-vol1 /data/ # df -kh Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup-lv_root 47G 1.1G 44G 3% / tmpfs 491M 0 491M 0% /dev/shm /dev/sda1 477M 28M 425M 6% /boot /dev/sdb 7.8G 19M 7.4G 1% /brick1 10.20.0.200:/dth-vol1 24G 55M 22G 1% /data
注:這個默認卷類型 是3塊盤 加起來的容量
測試 創建replic 復制卷
#gluster volume create rep1 replica 3 10.20.0.200:/brick1/b20 10.20.0.201:/brick1/b20 10.20.0.202:/brick1/b20
客戶端掛載
# mkdir /data1 # mount -t glusterfs 10.20.0.200:/rep1 /data1 # df -kh Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup-lv_root 47G 1.1G 44G 3% / tmpfs 491M 0 491M 0% /dev/shm /dev/sda1 477M 28M 425M 6% /boot /dev/sdb 7.8G 19M 7.4G 1% /brick1 10.20.0.200:/dth-vol1 24G 55M 22G 1% /data 10.20.0.200:/rep1 7.8G 19M 7.4G 1% /data1
注:replic類型 是復制模式 相當於raid1 一塊盤的容量
常規命令:
添加磁盤
gluster volume add-brick dht-vol1 10.20.0.200:/brick1/b1 rebalance 同步數據 gluster volume rebalance dht-vol1 start
刪除磁盤
gluster volume remove-brick dht-vol1 10.20.0.200:/brick1/b1 gluster volume rebalance dht-vol1 start
刪除卷
先停止 在刪除
# gluster volume stop dht-vol1 Stopping volume will make its data inaccessible. Do you want to continue? (y/n) y volume stop: dht-vol1: success # gluster volume delete dht-vol1 Deleting volume will erase all information about the volume. Do you want to continue? (y/n) y volume delete: dht-vol1: success # gluster volume info No volumes present
集群擴展
增加節點
gluster peer probe IP/主機名
刪除節點
gluster peer detach IP/主機名
節點狀態
gluster peer status
GlusterFS典型故障處理:
1,恢復節點配置信息
故障現象:其中一個節點配置信息不正確
故障模擬:
刪除server2部分配置信息
配置信息位置:/var/lib/glusterd/
修復方法
觸發自修復:通過Gluster工具同步配置信息
gluster volume sync server1 all
2,復制卷數據不一致
故障現象:雙副本卷數據出現不一致
故障模擬:刪除其中一個brick數據
修復方法
新mount一下
3 復制卷的目錄刪除了
如何解決
修復方法:
先替換brick
#gluster volume replace-brick bbs_img 10.20.0.201:/brick1/share2 10.20.0.201:/brick1/share start
#gluster volume replace-brick bbs_img 10.20.0.201:/brick1/share2 10.20.0.201:/brick1/share commit
還原的時候注意會報錯
解決辦法
rm -rf /data/share2/.glusterfs
setfattr -x trusted.glusterfs.volume-id /data/share2
setfattr -x trusted.gfid /data/share2