在本指南中,我们将学习如何设置 .使用分布式卷,文件将分布在卷中的各种块中,以便文件 A 存储在其中一个卷上,文件 B 存储在另一个卷上。此体系结构的目的是以较低的成本扩展卷大小。但是,它不提供冗余,卷故障将导致该卷中存储的数据完全丢失。distributed GlusterFS
因此,我们的环境由两个存储节点和一个客户端组成。他们的详细信息如下所示。
请注意,不要将 root 分区用于 GlusterFS。添加另一个存储分区,最好在不同的驱动器上。
- 存储节点 1:
- 主机名:gfs01.kifarunix-demo.com
- IP 地址:192.168.57.6
- Gluster 存储磁盘:/dev/sdb1
- 大小: 4GB
- 挂载点:/gfsvolume
- 操作系统: Ubuntu 22.04/Ubuntu 20.04
- 存储节点 2:
- 主机名:gfs02.kifarunix-demo.com
- IP 地址:192.168.56.124
- Gluster 存储磁盘:/dev/sdb1
- 大小: 4GB
- 挂载点:/gfsvolume
- 操作系统: Ubuntu 22.04/Ubuntu 20.04
- GlusterFS 客户端:
- 主机名:gfsclient.kifarunix-demo.com
- IP 地址:192.168.43.197
- 操作系统: Ubuntu 22.04/Ubuntu 20.04
- 确保 hostsnames 是可解析的。如果您没有 DNS 服务器,请相应地填充每个服务器的 hosts 文件,以便可以通过主机名访问这三个服务器。
- 要考虑的另一件事是 NTP 服务器。确保三个服务器的时间同步。
更新和升级您的系统软件包。
apt update
在 Ubuntu 22.04/Ubuntu 20.04 节点上安装 GlusterFS 服务器
GlusterFS 软件包在默认的 Ubuntu 22.04/Ubuntu 20.04 上可用。运行以下命令以安装 GlusterFS 服务器。
apt install glusterfs-server
启动并启用 GlusterFS 服务器 () 以在系统启动时运行;glusterd
systemctl enable --now glusterd
检查状态;
systemctl status glusterd
● glusterd.service - GlusterFS, a clustered file-system server
Loaded: loaded (/lib/systemd/system/glusterd.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2022-06-02 17:59:13 UTC; 11s ago
Docs: man:glusterd(8)
Process: 3346 ExecStart=/usr/sbin/glusterd -p /var/run/glusterd.pid --log-level $LOG_LEVEL $GLUSTERD_OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 3347 (glusterd)
Tasks: 9 (limit: 2241)
Memory: 7.1M
CPU: 1.394s
CGroup: /system.slice/glusterd.service
└─3347 /usr/sbin/glusterd -p /var/run/glusterd.pid --log-level INFO
Jun 02 17:59:11 gfs02.kifarunix-demo.com systemd[1]: Starting GlusterFS, a clustered file-system server...
Jun 02 17:59:13 gfs02.kifarunix-demo.com systemd[1]: Started GlusterFS, a clustered file-system server.
在 Ubuntu 22.04/Ubuntu 20.04 上设置分布式 GlusterFS 卷
如果 Firewall 正在运行,请运行以下命令以允许 Gluster 存储节点通过 Gluster 守护程序服务端口 24007/TCP 相互通信
<span style="background-color:#081c34"><span style="color:#ffffff"><code>ufw allow from <strong><other-node-IP></strong> to any port 24007 proto tcp comment "GlusterFS Management"</code></span></span>
如果您使用的是 iptables;
<span style="background-color:#081c34"><span style="color:#ffffff"><code>iptables -A INPUT -s <strong><other-node-IP></strong> -p tcp --dport 24007 -j ACCEPT -m comment --comment "GlusterFS Management"</code></span></span>
cp /etc/iptables/rules.v4{,.old}
iptables-save > /etc/iptables/rules.v4
还允许 GlusterFS 客户端连接到 GlusterFS 守护程序;
ufw allow from <Client-IP> to any port 24007 proto tcp comment "GlusterFS Client Access"
- 配置 GlusterFS 可信池
要在 GlusterFS 节点之间创建可信存储池,请从 GlusterFS Node01 运行探测器,如下所示;
gluster peer probe gfs02.kifarunix-demo.com
示例输出;
peer probe: success.
要检查上面刚刚创建的受信任池的状态,请执行以下命令;
gluster peer status
Number of Peers: 1
Hostname: gfs02.kifarunix-demo.com
Uuid: b81803a8-893a-499e-9a87-6bac00a62822
State: Accepted peer request (Connected)
如果您收到 ,请在此处查看解决方案。State: Peer Rejected (Connected)
第二个节点的输出;
Number of Peers: 1
Hostname: gfs01.kifarunix-demo.com
Uuid: 26fe538a-91c2-42a1-b34a-67c2c94c7492
State: Peer in Cluster (Connected)
列出存储池;
<span style="background-color:#081c34"><span style="color:#ffffff"><code>gluster pool list</code></span></span>
UUID Hostname State
b81803a8-893a-499e-9a87-6bac00a62822 gfs02.kifarunix-demo.com Connected
26fe538a-91c2-42a1-b34a-67c2c94c7492 localhost Connected
- 创建分布式 GlisterFS 卷
在两个存储节点上的 GlusterFS 存储设备挂载点上为 GlusterFS 卷创建 brick 目录。
Brick 是 GlusterFS 中的基本存储单位,由可信存储池中服务器上的导出目录表示。块是通过将服务器与导出目录组合在一起来表示的,格式如下: 'SERVER:EXPORT' 例如: 'myhostname:/exports/myexportdir/'。
因此,在 BOTH 节点上,创建 brick 目录。
>mkdir /gfsvolume/gv0
请注意,我们的 GlusterFS 磁盘 /dev/sdb1 已挂载在 /gfsvolume 目录下。
<span style="background-color:#081c34"><span style="color:#ffffff"><code>df -hT -P /gfsvolume</code></span></span>
示例输出;
Filesystem Type Size Used Avail Use% Mounted on
/dev/sdb1 ext4 3.9G 24K 3.7G 1% /gfsvolume
接下来,创建一个名为 on the nodes 的分布式卷。名字可以是任何东西!distributed_vol
在任一节点上运行此命令一次。
gluster volume create distributed_vol transport tcp gfs01:/gfsvolume/gv0 gfs02:/gfsvolume/gv0
示例输出;
volume create: distributed_vol: success: please start the volume to access data
- 启动创建的卷。
您现在可以启动创建的卷块。
<span style="background-color:#081c34"><span style="color:#ffffff"><code>gluster volume start distributed_vol</code></span></span>
示例输出;
volume start: distributed_vol: success
- 显示有关已创建卷的信息。
您可以使用以下命令显示有关已创建 Brick 卷的信息;
gluster volume info
<span style="background-color:#001a33"><span style="color:#ffffff"><code>
Volume Name: distributed_vol
Type: Distribute
Volume ID: 98519652-97a2-4fb8-bd1a-9b6a83d8936e
Status: Started
Snapshot Count: 0
Number of Bricks: 2
Transport-type: tcp
Bricks:
Brick1: gfs01:/gfsvolume/gv0
Brick2: gfs02:/gfsvolume/gv0
Options Reconfigured:
transport.address-family: inet
storage.fips-mode-rchecksum: on
nfs.disable: on
</code></span></span>
- 获取 GlusterFS 卷状态;
<span style="background-color:#081c34"><span style="color:#ffffff"><code>gluster volume status</code></span></span>
Status of volume: distributed_vol
Gluster process TCP Port RDMA Port Online Pid
------------------------------------------------------------------------------
Brick gfs01:/gfsvolume/gv0 49152 0 Y 6110
Brick gfs02:/gfsvolume/gv0 60116 0 Y 4501
Task Status of Volume distributed_vol
------------------------------------------------------------------------------
There are no active volume tasks
- 在防火墙上打开 GlusterFS 卷端口
为了让客户端连接到创建的卷,您需要在防火墙上打开相应的节点卷端口。端口如上所示。
此外,请确保节点可以在这些端口上相互通信。
例如,在 GlusterFS 节点 01 上,打开端口 49152 以允许客户端挂载卷。
ufw allow from <Client-IP-or-Network> to any port 49152 proto tcp comment "GlusterFS Client Access"
<span style="background-color:#081c34"><span style="color:#ffffff"><code>ufw allow from <strong><Node02 IP></strong> to any port 49152 proto tcp comment "GlusterFS Node02"</code></span></span>
在节点 02 上;
<span style="background-color:#081c34"><span style="color:#ffffff"><code>ufw allow from <strong><strong><Client-IP-or-Network></strong></strong> to any port 60116 proto tcp comment "GlusterFS Client Access"</code></span></span>
<span style="background-color:#081c34"><span style="color:#ffffff"><code>ufw allow from <strong><strong><Node01 IP></strong></strong> to any port 60116 proto tcp comment "GlusterFS Node01"</code></span></span>
在 Ubuntu 22.04/Ubuntu 20.04 客户端上安装 GlusterFS 客户端
在 Ubuntu 22.04/Ubuntu 20.04 上,执行命令在 Ubuntu 22.04/Ubuntu 20.04 上安装 GlusterFS 客户端;
apt update
apt install glusterfs-client
- 在 GlusterFS 客户端挂载 GlusterFS 卷
我们将使用本机 GlusterFS 客户端来挂载 GlusterFS 节点。
创建挂载点
mkdir /mnt/gfsvol
挂载分布式卷。如果使用域名,请确保它们是可解析的。
mount -t glusterfs gfs01:/distributed_vol /mnt/gfsvol/
运行 df 命令以检查挂载的文件系统。
df -hTP /mnt/gfsvol/
Filesystem Type Size Used Avail Use% Mounted on
gfs01:/distributed_vol fuse.glusterfs 7.8G 97M 7.3G 2% /mnt/gfsvol
从其他客户端,您可以将卷挂载到另一个节点上;
mount -t glusterfs gfs02:/distributed_vol /mnt/gfsvol/
要在系统启动时自动挂载卷,您需要将下面的行添加到 ./etc/fstab
gfs01:/distributed_vol /mnt/gfsvol glusterfs defaults,_netdev 0 0
要测试数据分布,请在客户端上创建两个测试文件。其中一个文件将存储在其中一个卷上,另一个文件将存储在另一个卷上。请参阅下面的示例;
mkdir /mnt/gfsvol/Test-dir
touch /mnt/gfsvol/Test-dir/{test-file,test-file-two}
如果您可以检查 node01,
ls /gfsvolume/gv0/Test-dir/
test-file-two
在 node02 上,
ls /gfsvolume/gv0/Test-dir/
test-file
我们关于在 Ubuntu 22.04/Ubuntu 20.04 上设置 GlusterFS 的指南到此结束,特别是如何设置分布式 GlusterFS 卷。在下一个教程中,我们将学习如何设置复制的 GlusterFS 卷。