发布时间: 2024-6-18 文章作者: myluzh 分类名称: NOTES 朗读文章
sudo apt-get update sudo apt-get install -y glusterfs-server2、启动 GlusterFS 服务
sudo systemctl start glusterd sudo systemctl enable glusterd
sudo gluster peer probe <node2-ip>2、检查集群状态
sudo gluster peer status3、创建一个分布式或复制卷(假设存储路径为 /data/gluster )
# mkdir -p /data/gluster # 分布式卷(性能优先): sudo gluster volume create gv0 transport tcp <node1>:/data/gluster <node2>:/data/gluster # 复制卷(高可用优先): sudo gluster volume create gv0 replica 2 transport tcp <node1>:/data/gluster <node2>:/data/gluster # 启动卷: sudo gluster volume start gv04、设置卷权限(可选):
# 全部允许 sudo gluster volume set gv0 auth.allow "*" # 配置只能某个网段访问 sudo gluster volume set gv0 auth.allow "192.168.0.*"5、验证配置,查看当前卷配置
sudo gluster volume info gv0
sudo apt-get update sudo apt-get install -y keepalived2、配置keepalived
vrrp_instance VI_1 { state MASTER interface eth0 # 替换为实际网络接口名称,例如 eth0 或 ens3 virtual_router_id 51 priority 100 # 主节点优先级更高 advert_int 1 authentication { auth_type PASS auth_pass mypassword # 设置密码,确保主备一致 } virtual_ipaddress { 192.168.0.11 # 虚拟 IP 地址 } }备节点配置 vi /etc/keepalived/keepalived.conf
vrrp_instance VI_1 { state BACKUP interface eth0 # 替换为实际网络接口名称,例如 eth0 或 ens3 virtual_router_id 51 priority 90 # 备份节点优先级较低 advert_int 1 authentication { auth_type PASS auth_pass mypassword # 设置密码,确保主备一致 } virtual_ipaddress { 192.168.0.11 # 虚拟 IP 地址 } }3、启动 Keepalived,在两台服务器上启动并设置 Keepalived 开机自启
sudo systemctl start keepalived sudo systemctl enable keepalived4、验证vip
# 1、在主节点运行以下命令,确认 VIP 已分配 ip addr show | grep 192.168.0.11 # 2、测试故障转移,手动停止主节点上的 Keepalived 服务: sudo systemctl stop keepalived # 3、然后检查备份节点是否接管了 VIP,如果 VIP 出现在备份节点上,说明故障转移成功。 ip addr show
sudo apt-get install -y nfs-ganesha-gluster2、编辑 NFS-Ganesha 的配置文件 /etc/ganesha/ganesha.conf,添加对 GlusterFS 卷的支持。
EXPORT_DEFAULTS { Access_Type = RW; } EXPORT { Export_Id = 1 ; Path = "/gv0"; Pseudo = "/gv0"; Disable_ACL = True; Protocols = "3","4"; Access_Type = RW; Squash = No_root_squash; Sectype = "sys"; Transports = "TCP"; FSAL { Name = "GLUSTER"; Hostname = "192.168.0.11"; Volume = "gv0"; } } LOG { Default_Log_Leve1 = WARN; }3、确保 NFS-Ganesha 在 GlusterFS 服务完全启动并就绪后延迟 5 秒再启动,以避免因依赖服务未完全初始化导致的启动失败。
# vi /usr/lib/systemd/system/nfs-ganesha.service # 添加以下内容 [Unit] After=glusterd.service Requires=glusterd.service [Service] ExecStartPre=/bin/sleep 54、启动 NFS-Ganesha
systemctl daemon-reload sudo systemctl reload nfs-ganesha sudo systemctl restart nfs-ganesha sudo systemctl enable nfs-ganesha # 查看日志 tail -f /var/log/ganesha/ganesha.log4、客户端通过nfs进行挂载
mkdir -p /mnt/nfs mount -t nfs 192.168.0.11:/gv0 /mnt/nfs
标签: nfs GlusterFS cluster nfs集群
发表评论