1. 首页 > Linux教程 > 正文

Linux教程FG354-GlusterFS分布式存储

内容简介:本文风哥教程参考Linux官方文档、Red Hat Enterprise Linux官方文档、Ansible Automation Platform官方文档、Docker官方文档、Kubernetes官方文档和Podman官方文档等内容,详细介绍了相关技术的配置和使用方法。

本文档介

风哥提示:

绍GlusterFS分布式存储的配置和使用方法。

Part01-GlusterFS安装

1.1 安装GlusterFS

# 安装GlusterFS
[root@gluster1 ~]# dnf install -y glusterfs glusterfs-server glusterfs-fuse
Updating Subscription Management repositories.
Last metadata expiration check: 0:05:23 ago on Fri Ap更多学习教程公众号风哥教程itpux_comr 4 21:20:00 2026.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
glusterfs x86_64 10.3-1.el9 epel 500 k
glusterfs-server x86_64 10.3-1.el9 epel 1.学习交流加群风哥微信: itpux-com0 M
glusterfs-fuse x86_64 10.3-1.el9 epel 200 k

Transaction Summary
================================================================================
Install 3 Packages

Total download size: 1.7 M
Installed size: 5.0 M
Downloading Packages:
(1/3): glusterfs-10.3-1.el9.x86_64.rpm 1.0 MB/s | 500 kB 00:00
(2/3): glusterfs-server-10.3-1.el9.x86_64.rpm 2.0 MB/s | 1.0 MB 00:00
(3/3): glusterfs-fuse-10.3-1.el9.x86_64.rpm 500 kB/s | 200 kB 00:00
——————————————————————————–
Total 3.5 MB/s | 1.7 MB 00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/3
Installing : glusterfs-10.3-1.el9.x86_64 1/3
Installing : glusterfs-server-10.3-1.el9.x86_64 2/3
Installing : glusterfs-fuse-10.3-1.el9.x86_64 3/3
Running scriptlet: glusterfs-fuse-10.3-1.el9.x86_64 3/3
Verifying : glusterfs-10.3-1.el9.x86_64 1/3
Verifying : glusterfs-server-10.3-1.el9.x86_64 2/3
Verifying : glusterfs-fuse-10.3-1.el9.x86_64 3/3

Installed:
glusterfs-10.3-1.el9.x86_64
glusterfs-server-10.3-1.el9.x86_64
glusterfs-fuse-10.3-1.el9.x86_64

Complete!

# 启动GlusterFS服务
[root@gluster1 ~]# systemctl enable –now glusterd
Created symlink /etc/systemd/system/multi-user.target.wants/glusterd.service → /usr/lib/systemd/system/glusterd.service.

# 查看服务状态
[root@gluster1 ~]# systemctl status glusterd
● glusterd.service – GlusterFS, a clustered file-system server
Loaded: loaded (/usr/lib/systemd/system/glusterd.service; enabled; preset: disabled)
Active: active (running) since Fri 2026-04-04 21:25:00 CST; 10s ago
Main PID: 12345 (glusterd)
Tasks: 10 (limit: 11232)
Memory: 50.0M
CGroup: /system.slice/glusterd.service
└─12345 /usr/sbin/glusterd -p /var/run/glusterd.pid

# 配置防火墙
[root@gluster1 ~]# firewall-cmd –permanent –add-service=glusterfs
success
[root@gluster1 ~]# firewall-cmd –reload
success

# 配置hosts文件
[root@gluster1 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain
192.168.1.11 gluster1
192.168.1.12 gluster2
192.168.1.13 gluster3

1.2 创建存储池

# 在gluster1上添加节点
[root@gluster1 ~]# gluster peer probe gluster2
peer probe: success.

[root@gluster1 ~]# gluster peer probe gluster3
peer probe: success.

# 查看节点状态
[root@gluster1 ~]# gluster peer status
Number of Peers: 2

Hostname: gluster2
Uuid: 23456789-01ab-cdef-2345-67890abcdef12
State: Peer in Cluster (Connected)

Hostname: gluster3
Uuid: 34567890-12ab-cdef-3456-78901abcdef23
State: Peer in Cluster (Connected)

# 创建存储目录
[root@gluster1 ~]# mkdir -p /data/brick1
[root@gluster2 ~]# mkdir -p /data/brick1
[root@gluster3 ~]# mkdir -p /data/brick1

# 创建复制卷
[root@gluster1 ~]# gluster volume create gv1 replica 3 gluster1:/data/brick1 gluster2:/data/brick1 gluster3:/data/brick1
volume create: gv1: success: please start the volume to access data

# 启动卷
[root@gluster1 ~]# gluster volume start gv1
volume start: gv1: success

# 查看卷信息
[root@gluster1 ~]# gluster volume info gv1

Volume Name: gv1
Type: Replicate
Volume ID: 12345678-90ab-cdef-1234-567890abcdef
Status: Started
Snapshot Count: 0
Number of Bricks: 1 x 3 = 3
Transport-type: tcp
Bricks:
Brick1: gluster1:/data/brick1
Brick2: gluster2:/data/brick1
Brick3: gluster3:/data/brick1
Options Reconfigured:
cluster.granular-entry-heal: on
storage.更多视频教程www.fgedu.net.cnfips-mode-rchecksum: on
transport.address-family: inet
nfs.disable: on
performance.client-io-threads: off

Part02-GlusterFS使用

2.1 客户端挂载

# 安装客户端
[root@client ~]# dnf install -y glusterfs-fuse

# 创建挂载点
[root@client ~]# mkdir /data/gluster

# 挂载卷
[root@client ~]# mount -t glusterfs gluster1:/gv1 /data/gluster

# 查看挂载
[root@client ~]# df -h | grep gluster
gluster1:/gv1 100G 5.0G 95G 5% /data/gluster

# 配置自动挂载
[root@client ~]# cat >> /etc/fstab << 'EOF' gluster1:/gv1 /data/gluster glusterfs defaults,_netdev 0 0 EOF # 测试写入 [root@client ~]# echo "Hello GlusterFS" > /data/gluster/test.txt
[root@client ~]# cat /data/gluster/test.txt
Hello GlusterFS

# 查看卷状态
[root@gluster1 ~]# gluster volume status gv1
Status of volume: gv1
Gluster process TCP Port RDMA Port Online Pid
——————————————————————————
Brick gluster1:/data/brick1 49152 0 Y 12345
Brick gluster2:/data/brick1 49152 0 Y 12345
Brick gluster3:/data/brick1 49152 0 Y 12345
Self-heal Daemon on localhost N/A N/A Y 12346
Self-heal Daemon on gluster2 N/A N/A Y 12346
Self-heal Daemon on gluster3 N/A N/A Y 12346

Task Status of Volume gv1
——————————————————————————
There are no active volume tasks

2.2 卷类型配置

# 创建分布式卷
[root@gluster1 ~]# gluster volume create gv2 gluster1:/data/brick2 gluster2:/data/brick2 gluster3:/data/brick2
volume create: gv2: success: please start the volume to access data

# 创建条带卷
[root@gluster1 ~]# gluster volume create gv3 stripe 3 gluster1:/data/brick3 gluster2:/data/brick3 gluster3:/data/brick3
volume create: gv3: success: please start the volume to access data

# 创建分布式复制卷
[root@gluster1 ~]# gluster volume create gv4 replica 2 gluster1:/data/brick4 gluster2:/data/brick4 gluster3:/data/brick4 gluster1:/data/brick5 gluster2:/data/brick5 gluster3:/data/brick5
volume create: gv4: success: please start the volume to access data

# 查看所有卷
[root@gluster1 ~]# gluster volume list
gv1
gv2
gv3
gv4

# 扩展卷
[root@gluster1 ~]# gluster volume add-brick gv2 gluster1:/data/brick6
volume add-brick: success

# 收缩卷
[root@gluster1 ~]# gluster volume remove-brick gv2 gluster1:/data/brick6 start
volume remove-brick start: success

# 平衡卷
[root@gluster1 ~]# gluster volume rebalance gv2 start
volume rebalance: gv2: success: Rebalance on gv2 has been started.

# 删除卷
[root@gluster1 ~]# gluster volume stop gv3
Stopping volume will make its data inaccessible. Do you want to continue? (y/n) y
volume stop: gv3: success

[root@gluster1 ~]# gluster volume delete gv3
Deleting volume will erase all information about the volume. Do you want to continue? (y/n) y
volume delete: gv3: success

风哥针对GlusterFS配置建议:

  • 使用复制卷提高数据可靠性
  • 配置至少3个节点
  • 使用独立网络
  • 监控卷状态
  • 定期检查数据一致性

本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html

联系我们

在线咨询:点击这里给我发消息

微信号:itpux-com

工作日:9:30-18:30,节假日休息