现在有3台服务器 s1(主),s2(从), s3(从)需要实现文件实时同步,我们可以安装Nfs服务端和客户端来实现!

Centos7安装配置NFS服务和挂载及端口开通

一、安装 NFS 服务器所需的软件包:

yum install -y nfs-utils
二、编辑exports文件,添加从机
vim /etc/exports
/home/nfs/ 192.168.248.0/24(rw,sync,fsid=0)

同192.168.248.0/24一个网络号的主机可以挂载NFS服务器上的/home/nfs/目录到自己的文件系统中

rw表示可读写;sync表示同步写,fsid=0表示将/data找个目录包装成根目录

三、启动nfs服务

先为rpcbind和nfs做开机启动:(必须先启动rpcbind服务)

systemctl enable rpcbind.service
systemctl enable nfs-server.service

然后分别启动rpcbind和nfs服务:

systemctl restart rpcbind.service
systemctl restart nfs-server.service

确认NFS服务器启动成功:

rpcinfo -p

检查 NFS 服务器是否挂载我们想共享的目录 /home/nfs/:

exportfs
#可以查看到已经ok
/home/nfs 192.168.248.0/24

四、在从机上安装NFS 客户端

首先是安裝nfs,同上,然后启动rpcbind服务

先为rpcbind做开机启动:

systemctl enable rpcbind.service

然后启动rpcbind服务:

systemctl restart rpcbind.service

注意:客户端不需要启动nfs服务

检查 NFS 服务器端是否有目录共享:showmount -e nfs服务器的IP

[root@paas205 ~]# showmount -e 192.168.248.208
Export list for 192.168.248.208:
/home/nfs 192.168.248.0/24

在从机上使用 mount 挂载服务器端的目录/home/nfs到客户端某个目录下:

cd /home && mkdir /nfs
mount -t nfs 192.168.248.208:/home/nfs /home/nfs

df -h 查看是否挂载成功。

NFS设置固定端口,添加防火墙规则: https://www.jianshu.com/p/9fb004b30f1e

经测试:nfs客户端连接nfs server只需要开通TCP 111 2049端口 UDP 111 端口,可以多预留点端口例如TCP 111 2049 30001-30004端口 UDP 111 30002 端口。

参考:https://www.cnblogs.com/st-jun/p/7742560.html

相关文章: