您的位置:首页 > 其它

分布式存储系统GlusterFS安装配置

2013-07-26 17:01 453 查看
一、前言
前段时间我同事玩GlusterFS,下午总算有点时间了,也玩玩,GlusterFS是一个开源的分布式文件系统,于2011年被红帽收购.它具有高扩展性、高性能、高可用性、可横向扩展的弹性特点,无元数据服务器设计使glusterfs没有单点故障隐患,详细介绍请查看官网:www.gluster.org
二、环境
1、系统:
Centos 6.4
2、部署说明
服务端:
172.28.26.101
172.28.26.102
172.28.26.188
172.28.26.189
客户端:
172.28.26.103
三、部署
1、服务端安装:
yum -y install glusterfs glusterfs-server
chkconfig glusterd on
service glusterd start
2、服务端配置:
将4个存储节点组成一集群,本文在第一个节点执行,只需要在任意节点执行就OK。
[root@db1 ~]# gluster peer probe 172.28.26.102
Probe successful
[root@db1 ~]# gluster peer probe 172.28.26.188
Probe successful
[root@db1 ~]# gluster peer probe 172.28.26.189
Probe successful
查看集群的节点信息:

[root@db1 ~]# gluster peer status
Number of Peers: 3
Hostname: 172.28.26.102
Uuid: b9437089-b2a1-4848-af2a-395f702adce8
State: Peer in Cluster (Connected)
Hostname: 172.28.26.188
Uuid: ce51e66f-7509-4995-9531-4c1a7dbc2893
State: Peer in Cluster (Connected)
Hostname: 172.28.26.189
Uuid: 66d7fd67-e667-4f9b-a456-4f37bcecab29
State: Peer in Cluster (Connected)
以/data/gluster为共享目录,创建名为img的卷,副本数为2:

mkdir /data/gluster
[root@db1 ~]#  gluster volume create img replica 2 172.28.26.101:/data/gluster 172.28.26.102:/data/gluster 172.28.26.188:/data/gluster 172.28.26.189:/data/gluster
Creation of volume img has been successful. Please start the volume to access data.
启动卷:

[root@db1 ~]# gluster volume start img
Starting volume img has been successful
查看卷状态:


[root@db1 ~]# gluster volume info
Volume Name: img
Type: Distributed-Replicate
Status: Started
Number of Bricks: 2 x 2 = 4
Transport-type: tcp
Bricks:
Brick1: 172.28.26.101:/data/gluster
Brick2: 172.28.26.102:/data/gluster
Brick3: 172.28.26.188:/data/gluster
Brick4: 172.28.26.189:/data/gluster
3、客户端安装配置:

安装:

yum -y installglusterfs glusterfs-fuse
挂载:
mount -t glusterfs 172.28.26.102:/img /mnt/ (挂载任意一个节点即可)
mount -t nfs -o mountproto=tcp,vers=3 172.28.26.102:/img /log/mnt/ (使用NFS挂载,注意远端的rpcbind服务必须开启)
echo "172.28.26.102:/img /mnt/ glusterfs defaults,_netdev 0 0" >> /etc/fstab (开机自动挂载)
四、测试

1、检查文件正确性


dd if=/dev/urandom of=/data/navy bs=1M count=100 # 在挂载客户端生成测试文件
cp /data/navy /mnt/  # 文件拷贝到存储上
md5sum /data/navy /mnt/navy # 在查看客户端检查文件哈希
md5sum /data/gluster/navy # 存储集群的某2个节点上会有此文件,检查其哈希
2、宕机测试。使用glusterfs-fuse挂载,即使目标服务器故障,也完全不影响使用。用NFS则要注意挂载选项,否则服务端故障容易导致文件系统halt住而影响服务!

# 将其中一个节点停止存储服务service glusterd stop
service glusterfsd stop# 在挂载客户端删除测试文件
rm -fv /mnt/navy# 此时在服务端查看,服务被停止的节点上navy并未被删除。此时启动服务:service glusterd start# 数秒后,navy就被自动删除了。新增文件效果相同!
五、运维常用命令:

删除卷
gluster volume stop img
gluster volume delete img
将机器移出集群
gluster peer detach 172.28.26.102
只允许172.28.0.0的网络访问glusterfs
gluster volume set img auth.allow 172.28.26.*
加入新的机器并添加到卷里(由于副本数设置为2,至少要添加2(4、6、8..)台机器)
gluster peer probe 172.28.26.105
gluster peer probe 172.28.26.106
gluster volume add-brick img 172.28.26.105:/data/gluster 172.28.26.106:/data/gluster
收缩卷
# 收缩卷前gluster需要先移动数据到其他位置
gluster volume remove-brick img 172.28.26.101:/data/gluster/img 172.28.26.102:/data/gluster/img start
# 查看迁移状态
gluster volume remove-brick img 172.28.26.101:/data/gluster/img 172.28.26.102:/data/gluster/img status
# 迁移完成后提交
gluster volume remove-brick img 172.28.26.101:/data/gluster/img 172.28.26.102:/data/gluster/img commit
迁移卷
# 将172.28.26.101的数据迁移到,先将172.28.26.107加入集群
gluster peer probe 172.28.26.107
gluster volume replace-brick img 172.28.26.101:/data/gluster/img 172.28.26.107:/data/gluster/img start
# 查看迁移状态gluster volume replace-brick img 172.28.26.101:/data/gluster/img 172.28.26.107:/data/gluster/img status
# 数据迁移完毕后提交gluster volume replace-brick img 172.28.26.101:/data/gluster/img 172.28.26.107:/data/gluster/img commit
# 如果机器172.28.26.101出现故障已经不能运行,执行强制提交然后要求gluster马上执行一次同步
gluster volume replace-brick img 172.28.26.101:/data/gluster/img 172.28.26.102:/data/gluster/img commit -force
gluster volume heal imgs full

本文出自 “屌丝运维男” 博客,请务必保留此出处http://navyaijm.blog.51cto.com/4647068/1258250
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: