CentOS 7 上使用 GlusterFS 的高可用性存储 - 跨两个存储服务器的镜像
本教程适用于这些操作系统版本
- CentOS 7.2
- CentOS 5.4
在此页
- 1 条初步说明
- 2 启用其他存储库
- 3 设置 GlusterFS 服务器
- 4 设置 GlusterFS 客户端
- 5 测试
- 6 个链接
本教程展示了如何使用两台使用 GlusterFS 的存储服务器 (CentOS 7.2) 设置高可用性存储。每台存储服务器都是另一台存储服务器的镜像,文件将在两台存储服务器之间自动复制。客户端系统(以及 CentOS 7.2)将能够像访问本地文件系统一样访问存储。 GlusterFS 是一个集群文件系统,能够扩展到几个 peta 字节。它通过 Infiniband RDMA 或 TCP/IP 互连将各种存储块聚合到一个大型并行网络文件系统中。存储块可以由任何商用硬件制成,例如带有 SATA-II RAID 和 Infiniband HBA 的 x86_64 服务器。
1 初步说明
在本教程中,我使用了三个系统、两个服务器和一个客户端:
- server1.example.com:IP 地址 192.168.0.100(服务器)
- server2.example.com:IP 地址 192.168.0.101(服务器)
- client1.example.com:IP 地址 192.168.0.102(客户端)
所有三个系统都应该能够解析其他系统的主机名。如果这不能通过 DNS 完成,您应该编辑 /etc/hosts 文件,使其在所有三个系统上看起来如下所示:
nano /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
192.168.0.100 server1.example.com server1
192.168.0.101 server2.example.com server2
192.168.0.102 client1.example.com client1
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
(在以下设置中也可以使用 IP 地址而不是主机名。如果您更喜欢使用 IP 地址,则不必关心主机名是否可以解析。)
2 启用额外的存储库
server1.example.com/server2.example.com/client1.example.com:
首先,我们导入软件包的 GPG 密钥:
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*
然后我们在我们的 CentOS 系统上启用 EPEL 7 存储库:
yum -y install epel-release
yum -y install yum-priorities
编辑 /etc/yum.repos.d/epel.repo...
nano /etc/yum.repos.d/epel.repo
...并将行 priority=10 添加到 [epel] 部分:
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
priority=10
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
[...]
然后我们更新系统上现有的包:
yum -y update
3 设置 GlusterFS 服务器
GlusterFS 在 CentOS 存储特别兴趣小组的存储库中可用。使用此命令安装存储库:
yum -y install centos-release-gluster
然后按如下方式安装 GlusterFS 服务器:
yum -y install glusterfs-server
为 Gluster 守护进程创建系统启动链接并启动它:
systemctl enable glusterd.service
systemctl start glusterd.service
命令
glusterfsd --version
现在应该显示您刚刚安装的 GlusterFS 版本(在本例中为 3.7.12):
[ ~]# glusterfsd --version
glusterfs 3.7.12 built on Jun 24 2016 14:11:19
Repository revision: git://git.gluster.com/glusterfs.git
Copyright (c) 2006-2013 Red Hat, Inc. <http://www.redhat.com/>
GlusterFS comes with ABSOLUTELY NO WARRANTY.
It is licensed to you under your choice of the GNU Lesser
General Public License, version 3 or any later version (LGPLv3
or later), or the GNU General Public License, version 2 (GPLv2),
in all cases as published by the Free Software Foundation.
如果您使用防火墙,请确保 TCP 端口 111、24007、24008、24009-(24009 + 所有卷中的块数)在 server1.example.com 和 server2.example.com 上打开。
接下来,我们必须将 server2.example.com 添加到受信任的存储池(请注意,我从 server1.example.com 运行所有 GlusterFS 配置命令,但您也可以从 server2.example.com 运行它们,因为配置已被复制在 GlusterFS 节点之间 - 只需确保使用正确的主机名或 IP 地址):
在 server1.example.com 上,运行
gluster peer probe server2.example.com
[ ~]# gluster peer probe server2.example.com
peer probe: success.
可信存储池的状态现在应该类似于这样:
gluster peer status
[ ~]# gluster peer status
Number of Peers: 1
Hostname: server2.example.com
Uuid: 582e10da-aa1b-40b8-908c-213f16f57fe5
State: Peer in Cluster (Connected)
接下来,我们在 server1.example.com 和 server2.example.com 上创建具有两个副本的名为 testvol 的共享(请注意,在这种情况下,副本数等于服务器数,因为我们要设置镜像) /data 目录(如果不存在则创建):
gluster volume create testvol replica 2 transport tcp server1.example.com:/data server2.example.com:/data force
[ ~]#
启动音量:
gluster volume start testvol
结果应该是:
[ ~]#
上面的命令可能告诉您操作不成功:
[ ~]#
在这种情况下,您应该检查...的输出
netstat -tap | grep glusterfsd
在两台服务器上。
如果你得到这样的输出......
[ ~]#
...一切都很好,但是如果您没有得到任何输出...
[ ~]#
...在相应的服务器上重新启动 GlusterFS 守护程序(在本例中为 server2.example.com):
systemctl restart glusterd.service
然后检查输出...
netstat -tap | grep glusterfsd
...再次在那台服务器上 - 它现在应该是这样的:
[ ~]#
现在回到 server1.example.com:
您可以使用命令检查卷的状态
gluster volume info
[[email ~]# gluster 卷信息
Volume Name: testvol
Type: Replicate
Volume ID: e1f825ca-c9d9-4eeb-b6c5-d62c4aa02376
Status: Started
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: server1.example.com:/data
Brick2: server2.example.com:/data
Options Reconfigured:
performance.readdir-ahead: on
[ ~]#
默认情况下,所有客户端都可以连接到该卷。如果您只想授予对 client1.example.com (= 192.168.1.102) 的访问权限,请运行:
gluster volume set testvol auth.allow 192.168.1.102
请注意,可以对 IP 地址使用通配符(例如 192.168.*),并且您可以指定多个 IP 地址并以逗号分隔(例如 192.168.1.102,192.168.1.103)。
卷信息现在应该显示更新状态:
gluster volume info
[ ~]# gluster volume info
Volume Name: testvol
Type: Replicate
Volume ID: e1f825ca-c9d9-4eeb-b6c5-d62c4aa02376
Status: Started
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: server1.example.com:/data
Brick2: server2.example.com:/data
Options Reconfigured:
auth.allow: 192.168.1.102
performance.readdir-ahead: on
[ ~]#
4 设置 GlusterFS 客户端
在客户端,我们可以安装GlusterFS客户端,如下:
yum -y install glusterfs-client
然后我们创建如下目录:
mkdir /mnt/glusterfs
就是这样!现在我们可以使用以下命令将 GlusterFS 文件系统挂载到 /mnt/glusterfs:
mount.glusterfs server1.example.com:/testvol /mnt/glusterfs
(而不是 server1.example.com 你也可以在上面的命令中使用 server2.example.com!)
您现在应该在...的输出中看到新份额
mount
[ ~]#
... 和...
df -h
[ ~]#
您无需在客户端手动安装 GlusterFS 共享,而是将安装命令添加到 /etc/rc.local 文件。我不会将它添加到 /etc/fstab 因为 rc.local 总是在网络启动后执行,这是网络文件系统所必需的
打开 /etc/rc.local 并附加以下行:
nano /etc/rc.local
[...]
/usr/sbin/mount.glusterfs server1.example.com:/testvol /mnt/glusterfs
(同样,您也可以使用 server2.example.com 而不是 server1.example.com!)
要测试修改后的 /etc/rc.local 是否正常工作,请重新启动客户端:
reboot
重新启动后,您应该在...的输出中找到共享
df -h
... 和...
mount
5 测试
现在让我们在 GlusterFS 共享上创建一些测试文件:
touch /mnt/glusterfs/test1
touch /mnt/glusterfs/test2
现在让我们检查 server1.example.com 和 server2.example.com 上的 /data 目录。 test1 和 test2 文件应该出现在每个节点上:
server1.example.com/server2.example.com:
ls -l /data
[ ~]
现在我们关闭 server1.example.com 并在 client1.example.com 上的 GlusterFS 共享上添加/删除一些文件。
shutdown -h now
touch /mnt/glusterfs/test3
touch /mnt/glusterfs/test4
rm -f /mnt/glusterfs/test2
这些命令可能需要一些时间才能执行,因为 Glusterfs 在无法再连接到服务器 1 后切换到服务器 2。我们可以在这里看到系统的容错能力,因为当 server1 离线时我们仍然可以在我们的数据存储共享上工作。更改应该在 server2.example.com 上的 /data 目录中可见:
ls -l /data
[ ~]# ls -l /data
total 8
-rw-r--r--. 2 root root 0 Jul 1 15:17 test1
-rw-r--r--. 2 root root 0 Jul 1 15:19 test3
-rw-r--r--. 2 root root 0 Jul 1 15:19 test4
让我们再次启动 server1.example.com 并查看 /data 目录:
ls -l /data
[ ~]#
如您所见,server1.example.com 自动同步了更改。如果更改尚未同步,那么这很容易修复,我们需要做的就是在 client1.example.com 上的 GlusterFS 共享上调用读取命令,例如:
ls -l /mnt/glusterfs/
[ ~]#
现在再次查看 server1.example.com 上的 /data 目录,您应该会看到更改已复制到该节点:
ls -l /data
[ ~]#
6个链接
- GlusterFS:http://www.gluster.org/
- GlusterFS 3.2 文档:http://download.gluster.com/pub/gluster/glusterfs/3.2/Documentation/AG/html/index.html
- CentOS:http://www.centos.org/