NFS高可用部署

环境信息

| 主机 | IP 地址 | 角色 |
| node1 | 192.168.229.133 | GlusterFS + NFS-Ganesha+ Keepalived (Master) |
| node2 | 192.168.229.134 | GlusterFS + Ganesha + Keepalived (Backup) |
| VIP | 192.168.229.100 | 虚拟 IP(客户端挂载地址) |

部署GlusterFS

安装GlusterFS

yum install -y glusterfs-server

启动GlusterFS

systemctl enable --now glusterd

创建目录,数据目录不能是根分区

mkdir -p /apps/gfs
#node01节点操作
gluster peer probe node02
gluster peer probe node03

创建两节点复制卷

#node01节点操作
gluster volume create nfs-volume replica 3 node01:/apps/gfs node02:/apps/gfs node03:/apps/gfs

启动卷

#node01节点操作
gluster volume start nfs-volume

设置性能参数

#node01节点操作
gluster volume set nfs-volume performance.cache-size 256MB

禁用原生NFS

gluster volume set nfs-volume nfs.disable on

验证

#node01节点操作
$ gluster volume info

Volume Name: nfs-volume
Type: Replicate
Volume ID: 13af8347-f9b7-4b27-b474-ca7fc6804061
Status: Started
Snapshot Count: 0
Number of Bricks: 1 x 3 = 3
Transport-type: tcp
Bricks:
Brick1: node01:/apps/gfs
Brick2: node02:/apps/gfs
Brick3: node03:/apps/gfs
Options Reconfigured:
performance.cache-size: 256MB
cluster.granular-entry-heal: on
storage.fips-mode-rchecksum: on
transport.address-family: inet
nfs.disable: on
performance.client-io-threads: off

部署NFS-Ganesha

安装NFS-Ganesha

yum install nfs-ganesha-9.7-0.1.oe2203.bclinux.x86_64.rpm libntirpc-7.2-0.1.oe2203.bclinux.x86_64.rpm nfs-ganesha-monitoring-9.7-0.1.oe2203.bclinux.x86_64.rpm nfs-ganesha-gluster-9.7-0.1.oe2203.bclinux.x86_64.rpm

编辑配置文件/etc/ganesha/ganesha.conf

#################################################
# NFS-Ganesha Configuration for Kubernetes + GlusterFS
# Exports GlusterFS volume 'nfs-volume' as /apps/gfs
# Supports both NFSv3 and NFSv4
#################################################

NFS_CORE_PARAM {
mount_path_pseudo = true;
Protocols = 3,4;

# 禁用不必要的安全模块
Enable_GSS = false; # ⭐ 关闭 Kerberos/GSS,消除 CRIT 错误
Enable_NLM = false; # 如无需文件锁(K8s 通常用 RWX PV,可关)
Enable_RQUOTA = false; # 如无需磁盘配额
}

THREADS {
nb_worker_threads = 16; # 替代已弃用的 Nb_Worker
}

EXPORT_DEFAULTS {
Access_Type = RW;
}

EXPORT {
Export_Id = 101;
Path = "/apps/gfs";
Pseudo = "/apps/gfs";
Protocols = 3,4;
Access_Type = RW;
Squash = No_Root_Squash;
Transports = TCP;
SecType = "sys"; # 明确使用 sys 安全模型

FSAL {
Name = GLUSTER;
Hostname = "localhost";
Volume = "nfs-volume";
}

CLIENT {
Clients = 10.244.0.0/16, 192.168.229.0/24;
Access_Type = RW;
}
}

LOG {
Default_Log_Level = WARN;
Components {
FSAL = INFO;
NFS4 = EVENT;
EXPORT = EVENT;
}
Facility {
name = FILE;
destination = "/var/log/ganesha/ganesha.log";
enable = active;
}
}

# MDCACHE 保留有效参数,移除无效的 Dir_Chunk_Size
MDCACHE {
Entries_HWMark = 500000;
# Dir_Chunk_Size 不存在,已移除
}

启动服务

systemctl start nfs-ganesha
systemctl enable nfs-ganesha
systemctl status nfs-ganesha

测试nfs

showmount -e localhost
Export list for localhost:
/apps/gfs 10.244.0.0/16,192.168.229.0/24

挂载nfs

mount -t nfs 192.168.229.132:/apps/gfs /mnt/
文章作者: 慕容峻才
文章链接: https://www.acaiblog.top/NFS高可用部署/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 阿才的博客
微信打赏
支付宝打赏