GlusterFS 分布式文件系统——理论及基础配置

来源:互联网 发布:蚂蚁信息源码 编辑:程序博客网 时间:2024/05/21 14:54
云存储
分布式存储
分布式文件系统
--------------------------------------------------------------------------------
GlusterFS简介:
PB级容量 高可用性 读/写性能 基于文件系统级别共享 分布式
https://www.gluster.org/
http://gluster.readthedocs.io/en/latest/Quick-Start-Guide/Quickstart/
https://wiki.centos.org/HowTos/GlusterFSonCentOS
GlusterFS is a scalable network filesystem. Using common off-the-shelf hardware, you can create large, distributed storage solutions for media streaming, data analysis, and other data- and bandwidth-intensive tasks. GlusterFS is free and open source software.
GlusterFS(GNU ClusterFile System)是一种全对称的开源分布式文件系统,所谓全对称是指GlusterFS采用弹性
哈希算法,没有中心节点,所有节点全部平等。GlusterFS配置方便,稳定性好,可轻松达到PB级容量,数千个节点。

2011年被红帽收购,之后推出了基于GlusterFS的 Red Hat Storage Server,增加了针对KVM的许多特性。可用作

为KVM存储image存储集群,也可以为LB或HA提供存储。

GlusterFS重要特性:
全对称架构
支持多种卷类型(类似RAID0/1/5/10/01)
支持卷级别的压缩
支持FUSE
支持NFS
支持SMB
支持Hadoop
支持Openstack
与oVirt深度整合 (对应RHEV红帽企业级虚拟化)
GlusterFS重要概念:
brick: GlusterFS的基本单元,以节点服务器目录形式展现。
Volume: 多个 bricks 的逻辑集合
Metadata: 元数据,用于描述文件、目录等的信息。
Self-heal: 用于后台运行检测复本卷中文件和目录的不一致性并解决这些不一致。
FUSE: Filesystem Userspace是一个可加载的内核模块,其支持非特权用户创建自己的文件系统而不需要修改内核代码。
通过在用户空间运行文件系统的代码通过FUSE代码与内核进行桥接。
GlusterFS Server:数据存储服务器,即组成GlusterFs存储集群的节点。
GlusterFS Client: 使用GlusterFS存储服务器的服务器,例如KVM、Openstack、LB RealServer、HA node。
--------------------------------------------------------------------------------
实验架构图:
                       vm1.cluster.com(模拟客户端)
                           172.16.25.2

vm2.cluster.com           vm3.cluster.com              vm4.cluster.com             vm5.cluster.com
172.16.25.3                  172.16.25.4                     172.16.25.5                    172.16.25.6
分别模拟分布式存储服务器1,2,3,4
第一步:实验前准备,五台虚拟机(centos7.3平台)
1,配置主机名,并且互相全部主机名绑定
# hostnamectl set-hostname --static vm1.cluster.com
# vim /etc/hosts
172.16.25.2 vm1.cluster.com client
172.16.25.3 vm2.cluster.com storage1
172.16.25.4 vm3.cluster.com storage2
172.16.25.5 vm4.cluster.com storage3
172.16.25.6 vm5.cluster.com storage4
2,ip静态
3,关闭iptables,selinux
4,时间同步

5,配置yum (本地镜像yum源仓库和下面的glusterfs源仓库)

去下面的路径找你需要的对应版本,然后配置公网yum源路径就可以了 (2-5具体步骤省略,可参考http://blog.csdn.net/birdie_l/article/details/77994637)
https://buildlogs.centos.org/centos/7/storage/x86_64/
第二步:在所有存储服务器上(不包括客户端)安装glusterfs-server包并启动服务

# yum install glusterfs-server
# systemctl start glusterd
# systemctl status glusterd
# systemctl enable glusterd
第三步:让所有存储集群节点做成trusted pool(也就是建立连接)
只需要在其中一个存储节点上分别probe(建立连接)其它所有节点每人一次就可以了(不用排列组合的两两probe)
下面我就在storage1上操作
# gluster peer probe storage2
# gluster peer probe storage3
# gluster peer probe storage4 --这里使用ip,主机名,主机名别名都可以
然后在所有存储上都可以使用下面命令来验证检查
# gluster peer status
--注意:如果第三步建立连接有问题(一般问题会出现在相互之间的网络连接,iptables,selinux,主机名绑定等);如果想重做这一步,可以使用gluster peer detach xxxxx [force] 来断开连接,重新做第三步
第四步:在所有存储节点上,建立用于集群的存储目录(可以用单独的分区,也可以使用根分区)
# mkdir -p /data/gv0   --此目录不属于单独的分区,默认属于根分区
第五步:创建gluster volume取名叫gv0

在其中任一存储节点使用下面的命令创建glusterfs volume(其它存储节点不用重复执行)

# gluster volume create gv0 replica 4 storage1:/data/gv0/ storage2:/data/gv0/ storage3:/data/gv0/ storage4:/data/gv0/

volume create: gv0: failed: The brick storage1:/data/gv0 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
--replica 4后面的数字与你的节点数有关(replica是类似raid1的模式,我们先讨论这种模式)
--报错信息提示:建议使用非根分区来创建volume,但我们这里为了方便,并没有多加硬盘来挂载,默认使用的是根分区,所以多加一个force参数就可以了
# gluster volume create gv0 replica 4 storage1:/data/gv0/ storage2:/data/gv0/ storage3:/data/gv0/ storage4:/data/gv0/ force --加了force参数,成功
volume create: gv0: success: please start the volume to access data
所有存储节点都可以使用下面命令查看gv0的信息
# gluster volume info gv0
Volume Name: gv0
Type: Replicate --模式为replicate模式
Volume ID: 328d3d55-4506-4c45-a38f-f8748bdf1da6
Status: Created --这里状态为created,表示刚创建,还未启动,需要启动才能使用
Snapshot Count: 0
Number of Bricks: 1 x 4 = 4
Transport-type: tcp
Bricks:
Brick1: storage1:/data/gv0
Brick2: storage2:/data/gv0
Brick3: storage3:/data/gv0
Brick4: storage4:/data/gv0
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
第六步:在其中任一存储节点使用下面的命令启动gv0(其它存储节点不用重复执行)
# gluster volume start gv0
所有存储节点都可以使用下面命令查看gv0的信息
# gluster volume info gv0
Volume Name: gv0
Type: Replicate
Volume ID: 328d3d55-4506-4c45-a38f-f8748bdf1da6
Status: Started --现在看到状态变为started,那么就表示可以被客户端挂载使用了
Snapshot Count: 0
Number of Bricks: 1 x 4 = 4
Transport-type: tcp
Bricks:
Brick1: storage1:/data/gv0
Brick2: storage2:/data/gv0
Brick3: storage3:/data/gv0
Brick4: storage4:/data/gv0
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
第七步:在客户端上安装gluster客户端软件

# yum install glusterfs glusterfs-fuse
第八步:客户端挂载测试一:
--注意:客户端也需要在/etc/hosts文件里绑定存储节点的主机名,才可以挂载(因为我前面做的步骤是用名字的)
# mkdir /test{1,2,3,4} --建立四个测试挂载目录(相当于一个客户端模拟四个客户端)
# mount -t glusterfs storage1:/gv0 /test1
# mount -t glusterfs storage2:/gv0 /test2
# mount -t glusterfs storage3:/gv0 /test3
# mount -t glusterfs storage4:/gv0 /test4
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda3 17G 5.0G 12G 30% /
devtmpfs 482M 0 482M 0% /dev
tmpfs 497M 180K 497M 1% /dev/shm
tmpfs 497M 7.1M 490M 2% /run
tmpfs 497M 0 497M 0% /sys/fs/cgroup
/dev/vda1 297M 136M 162M 46% /boot
/dev/loop0 4.1G 4.1G 0 100% /yum
tmpfs 100M 8.0K 100M 1% /run/user/42
tmpfs 100M 20K 100M 1% /run/user/0
/dev/sr0 4.1G 4.1G 0 100% /run/media/root/CentOS 7 x86_64
storage1:/gv0 17G 5.4G 12G 33% /test1
storage2:/gv0 17G 5.4G 12G 33% /test2
storage3:/gv0 17G 5.4G 12G 33% /test3

storage4:/gv0 17G 5.4G 12G 33% /test4

# touch /test1/file{1..10}
# ls /test1/
file1 file10 file2 file3 file4 file5 file6 file7 file8 file9
# ls /test2/
file1 file10 file2 file3 file4 file5 file6 file7 file8 file9
# ls /test3/
file1 file10 file2 file3 file4 file5 file6 file7 file8 file9
# ls /test4/
file1 file10 file2 file3 file4 file5 file6 file7 file8 file9
读写测试结果是:类似raid1和lvm的镜像卷,写的东西在所有存储节点上都会产生一份(replica模式)
第九步:上面测试完后,如果要删除gv0这个volume,做法如下:
先在客户端umount已经挂载的目录
# rm /test1/* -rf --在umount之前把测试的数据干掉
# umount /test1
# umount /test2
# umount /test3
# umount /test4
在其中任一存储节点使用下面的命令停止gv0(其它存储节点不用重复执行)
# gluster volume stop gv0
Stopping volume will make its data inaccessible. Do you want to continue? (y/n) y
volume stop: gv0: success
在其中任一存储节点使用下面的命令删除gv0(其它存储节点不用重复执行)
# gluster volume delete gv0
Deleting volume will erase all information about the volume. Do you want to continue? (y/n) y
volume delete: gv0: success
在所有存储节点上都可以查看,没有gv0的信息了,说明这个volumn被删除了
# gluster volume info
Volume gv0 does not exist
stripe模式

第十步:
再重做成stripe模式(类似raid0和lvm的条带卷)的卷
# gluster volume create gv0 stripe 4 storage1:/data/gv0/ storage2:/data/gv0/ storage3:/data/gv0/ storage4:/data/gv0/ force
volume create: gv0: success: please start the volume to access data
# gluster volume start gv0
第十一步:
客户端再次挂载进行读写测试
# mount -t glusterfs storage1:/gv0 /test1
# mount -t glusterfs storage2:/gv0 /test2
# mount -t glusterfs storage3:/gv0 /test3
# mount -t glusterfs storage4:/gv0 /test4
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda3 17G 5.0G 12G 30% /
devtmpfs 482M 0 482M 0% /dev
tmpfs 497M 180K 497M 1% /dev/shm
tmpfs 497M 7.1M 490M 2% /run
tmpfs 497M 0 497M 0% /sys/fs/cgroup
/dev/vda1 297M 136M 162M 46% /boot
/dev/loop0 4.1G 4.1G 0 100% /yum
tmpfs 100M 8.0K 100M 1% /run/user/42
tmpfs 100M 20K 100M 1% /run/user/0
/dev/sr0 4.1G 4.1G 0 100% /run/media/root/CentOS 7 x86_64
storage1:/gv0 68G 21G 48G 33% /test1
storage2:/gv0 68G 21G 48G 33% /test2
storage3:/gv0 68G 21G 48G 33% /test3

storage4:/gv0 68G 21G 48G 33% /test4

# touch /test1/file{1..10}
# ls /test1
file1 file10 file2 file3 file4 file5 file6 file7 file8 file9
# ls /test2
file1 file10 file2 file3 file4 file5 file6 file7 file8 file9
# ls /test3
file1 file10 file2 file3 file4 file5 file6 file7 file8 file9
# ls /test4
file1 file10 file2 file3 file4 file5 file6 file7 file8 file9
测试结果比较:
replica模式 类似raid1,客户端挂载看到的大小为所有存储中最小存储的大小,客户端写1G,服务器会占4G,每个存储占1G
stripe模式 类似raid0,客户端挂载看到的大小为所有存储中大小的总和,客户端写1G,服务器会占1G,每个存储占1/4G

=============================================================================
除了这二种模式外,还有Distributed Striped,Distributed Replicated ,Distributed Striped Replicated,Striped Replicated,Dispersed,Distributed Dispersed等各种模式
参考官方文件路径为:
http://gluster.readthedocs.org/en/latest/Administrator%20Guide/Setting%20Up%20Volumes/



原创粉丝点击