Debian 8 上使用 GlusterFS 的高可用性存储 - 跨两个存储服务器的镜像
本教程适用于这些操作系统版本
- Debian 8(杰西)
- Debian 5(莱尼)
在此页
- 1 条初步说明
- 2 设置 GlusterFS 服务器
- 3 设置 GlusterFS 客户端
- 4 测试 GlusterFS 复制
- 5 个链接
本教程介绍如何使用两个使用 GlusterFS 的存储服务器 (Debian Jessie) 设置高可用性存储。每台存储服务器都是另一台存储服务器的镜像,文件将在两个存储节点之间自动复制。客户端系统(以及 Debian 8)将能够像访问本地文件系统一样访问存储。 GlusterFS 是一个集群文件系统,能够扩展到几个 peta 字节。它通过 Infiniband RDMA 或 TCP/IP 互连将各种存储块聚合到一个大型并行网络文件系统中。存储块可以由任何商用硬件制成,例如带有 SATA-II RAID 和 Infiniband HBA 的 x86_64 服务器。
1 初步说明
在本教程中,我将使用三个系统,两个服务器和一个客户端:
- server1.example.com:IP 地址 192.168.1.100(服务器)
- server2.example.com:IP 地址 192.168.1.101(服务器)
- client1.example.com:IP 地址 192.168.1.102(客户端)
所有三个系统都应该能够解析其他系统的主机名。如果这不能通过 DNS 完成,您应该编辑 /etc/hosts 文件,使其在所有三个系统上看起来如下所示:
nano /etc/hosts
127.0.0.1 localhost
192.168.1.100 server1.example.com server1
192.168.1.101 server2.example.com server2
192.168.1.102 client1.example.com client1
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
(在以下设置中也可以使用 IP 地址而不是主机名。如果您更喜欢使用 IP 地址,则不必关心主机名是否可以解析。)
2 设置 GlusterFS 服务器
最新的 GlusterFS 版本可以从 gluster.org 作为 Debian 软件包获得。我们可以按如下方式安装它:
我们在两台服务器上添加 gluster.org Debian 存储库的公钥。
wget -O - http://download.gluster.org/pub/gluster/glusterfs/3.7/3.7.9/rsa.pub | apt-key add -
然后添加 GlusterFS 存储库(命令是一行!)
echo deb http://download.gluster.org/pub/gluster/glusterfs/3.7/3.7.9/Debian/jessie/apt jessie main > /etc/apt/sources.list.d/gluster.list
并更新存储库列表。
apt-get update
现在我们可以使用 apt 安装 GlusterFS 服务器软件了。
apt-get -y install glusterfs-server
命令
glusterfsd --version
现在应该显示您刚刚安装的 GlusterFS 版本(在本例中为 3.7.9):
:/#
如果您使用防火墙,请确保 TCP 端口 111、24007、24008、24009-(24009 + 所有卷中的块数)在 server1.example.com 和 server2.example.com 上打开。
Glusterfs 应将其数据存储在服务器上的目录 /data 中。如果您的安装较小,或者您使用单独的硬盘分区并将其挂载为 /data,则该位置可以是普通目录。
在两台服务器上运行:
mkdir /data
创建数据目录。
接下来,我们必须将 server2.example.com 添加到受信任的存储池(请注意,我从 server1.example.com 运行所有 GlusterFS 配置命令,但您也可以从 server2.example.com 运行它们,因为配置已被复制在 GlusterFS 节点之间 - 只需确保使用正确的主机名或 IP 地址):
在 server1.example.com 上,运行
gluster peer probe server2.example.com
:/#
可信存储池的状态现在应该类似于这样:
gluster peer status
:/# gluster peer status
Number of Peers: 1
Hostname: server2.example.com
Uuid: 0f7ee46c-6a71-4a31-91d9-6076707eff95
State: Peer in Cluster (Connected)
:/#
接下来我们在 server1.example.com 和 server2.example.com 上创建具有两个副本的名为 testvol 的共享(请注意,在这种情况下,副本数等于服务器数,因为我们要设置镜像) /data/testvol 目录(如果不存在则创建):
gluster volume create testvol replica 2 transport tcp server1.example.com:/data/testvol server2.example.com:/data/testvol force
:/#
启动音量:
gluster volume start testvol
:/#
我们的测试卷已经成功启动。
上面的命令可能告诉您操作不成功:
:~#
在这种情况下,您应该检查...的输出
netstat -tap | grep glusterfsd
在两台服务器上。
如果你得到这样的输出......
:/#
...一切都很好,但是如果您没有得到任何输出...
:~#
...在相应的服务器上重新启动 GlusterFS 守护进程(本例中为 server1.example.com):
service glusterfs-server restart
然后检查输出...
netstat -tap | grep glusterfsd
...再次在那台服务器上 - 它现在应该是这样的:
:/#
现在回到 server1.example.com:
您可以使用命令检查卷的状态
gluster volume info
:/# gluster volume info
Volume Name: testvol
Type: Replicate
Volume ID: 3fc9af57-ca56-4a72-ad54-3d2ea03e5883
Status: Started
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: server1.example.com:/data/testvol
Brick2: server2.example.com:/data/testvol
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
[email :/# gluster 卷信息
Volume Name: testvol
Type: Replicate
Volume ID: 3fc9af57-ca56-4a72-ad54-3d2ea03e5883
Status: Started
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: server1.example.com:/data/testvol
Brick2: server2.example.com:/data/testvol
Options Reconfigured:
auth.allow: 192.168.1.102
performance.readdir-ahead: on
:/#
3 设置 GlusterFS 客户端
在客户端系统上,我们首先添加 gluster.org Debian 存储库的公钥。
wget -O - http://download.gluster.org/pub/gluster/glusterfs/3.7/3.7.9/rsa.pub | apt-key add -
然后添加 GlusterFS 存储库(命令是一行!)
echo deb http://download.gluster.org/pub/gluster/glusterfs/3.7/3.7.9/Debian/jessie/apt jessie main > /etc/apt/sources.list.d/gluster.list
并更新存储库列表。
apt-get update
现在我们可以按如下方式安装 GlusterFS 客户端。
apt-get -y install glusterfs-client
然后我们创建如下目录:
mkdir /mnt/glusterfs
就是这样!现在我们可以使用以下命令将 GlusterFS 文件系统挂载到 /mnt/glusterfs:
mount.glusterfs server1.example.com:/testvol /mnt/glusterfs
(您也可以在上述命令中使用 server2.example.com 而不是 server1.example.com!)
您现在应该在...的输出中看到新份额
mount
:/#
... 和...
df -h
:/#
您可以修改 /etc/fstab 以便在客户端启动时自动安装 GlusterFS 共享,而不是在客户端上手动安装 GlusterFS 共享。
打开 /etc/fstab 并附加以下行:
nano /etc/fstab
[...]
server1.example.com:/testvol /mnt/glusterfs glusterfs defaults,_netdev 0 0
(同样,您也可以使用 server2.example.com 而不是 server1.example.com!)
要测试修改后的 /etc/fstab 是否正常工作,请重新启动客户端:
reboot
重新启动后,您应该在...的输出中找到共享
df -h
... 和...
mount
4 测试 GlusterFS 复制
现在让我们在 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/testvol
:/# ls -l /data/testvol/
total 0
-rw-r--r-- 2 root root 0 Mar 23 2016 test1
-rw-r--r-- 2 root root 0 Mar 23 2016 test2
现在我们关闭 server1.example.com 并在 client1.example.com 上的 GlusterFS 共享上添加/删除一些文件。
shutdown -h now
touch /mnt/glusterfs/test3
touch /mnt/glusterfs/test4
rm -f /mnt/glusterfs/test2
更改应该在 server2.example.com 上的 /data/testvol 目录中可见:
ls -l /data/testvol
:/#
让我们再次启动 server1.example.com 并查看 /data 目录:
ls -l /data/testvol
:/#
如您所见,server1.example.com 自动同步了更改。如果更改尚未同步,那么这很容易修复,我们需要做的就是在 client1.example.com 上的 GlusterFS 共享上调用读取命令,例如:
ls -l /mnt/glusterfs/
:/#
5个链接
- GlusterFS:http://www.gluster.org/
- GlusterFS 文档:http://gluster.readthedocs.org/en/latest/
- Debian:http://www.debian.org/