«

使用 GlusterFS创建NFS集群

myluzh 发布于 阅读:83 NOTES


0x01 安装 GlusterFS

1、在两台 Ubuntu 服务器上安装 GlusterFS:

sudo apt-get update
sudo apt-get install -y glusterfs-server

2、启动 GlusterFS 服务

sudo systemctl start glusterd
sudo systemctl enable glusterd

0x02 配置 GlusterFS

1、在第一台节点(node1)上将第二台节点(node2)添加到集群中:

sudo gluster peer probe <node2-ip>

2、检查集群状态

sudo gluster peer status

3、创建一个分布式或复制卷(假设存储路径为 /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 gv0

4、设置卷权限(可选):

# 全部允许
sudo gluster volume set gv0 auth.allow "*"
# 配置只能某个网段访问
sudo gluster volume set gv0 auth.allow "192.168.0.*"

5、验证配置,查看当前卷配置

sudo gluster volume info gv0

0x03 通过keepalived创建虚拟IP(VIP)

通过 Keepalived 创建一个虚拟 IP(VIP),可以让客户端通过该 VIP 访问 GlusterFS 卷 gv0
需要注意的是:在使用 Keepalived 配置虚拟 IP(VIP)时,通常需要关闭网卡的 源目地址检查功能(rp_filter),以确保 VIP 能够正常工作。
1、在两台机子上安装keepalived

sudo apt-get update
sudo apt-get install -y keepalived

2、配置keepalived
主节点配置 vi /etc/keepalived/keepalived.conf

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 keepalived

4、验证vip

# 1、在主节点运行以下命令,确认 VIP 已分配
ip addr show | grep 192.168.0.11

# 2、测试故障转移,手动停止主节点上的 Keepalived 服务:
sudo systemctl stop keepalived

# 3、然后检查备份节点是否接管了 VIP,如果 VIP 出现在备份节点上,说明故障转移成功。
ip addr show

0x04 通过nfs方式挂载

需要通过标准 NFS 协议访问 GlusterFS 卷,可以使用 NFS-Ganesha 作为网关。
1、每个节点都安装NFS-Ganesha,使GlusterFS 卷支持NFS 访问。

sudo apt-get install -y nfs-ganesha-gluster

2、编辑 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 5

4、启动 NFS-Ganesha
注意:启动nfs-ganesha会和nfs端口冲突需要先停掉nfs

systemctl daemon-reload 
sudo systemctl reload nfs-ganesha
sudo systemctl restart nfs-ganesha
sudo systemctl enable nfs-ganesha
# 查看日志
tail -f /var/log/ganesha/ganesha.log

4、客户端通过nfs进行挂载

mkdir -p /mnt/nfs
mount -t nfs 192.168.0.11:/gv0 /mnt/nfs

0x05 通过GlusterFS挂载

在客户端上挂载 GlusterFS 卷作为 NFS 共享:

参考资料
通过nfs-ganesha实现nfs客户端挂载glusterfs虚拟卷 https://www.cnblogs.com/jingzhe2020/p/15892741.html

nfs GlusterFS cluster nfs集群


正文到此结束
版权声明:若无特殊注明,本文皆为 Myluzh Blog 原创,转载请保留文章出处。
文章内容:https://itho.cn/notes/525.html
文章标题:《使用 GlusterFS创建NFS集群