Centos7做NFS文件共享

准备服务器

服务器1:192.168.1.1(共享)
服务器2:192.168.1.2(挂载)
服务器2:192.168.1.3(挂载)

安装说明

每台服务器都需要安装NFS

安装

yum -y install nfs-utils 

开机启动

centos7

systemctl enable rpcbind.service
systemctl enable nfs.service

centos7以下开机启动

chkconfig rpcbind on
chkconfig nfs on

配置

每台服务器创建共享目录

mkdir /app/im_attach        ### 创建共享目录

配置

192.168.1.1(共享)服务器:
vi /etc/exports      

编辑配置文件

/app/im_attach/ 192.168.1.2(insecure,rw,no_root_squash,no_all_squash,sync)
/app/im_attach/ 192.168.1.3(insecure,rw,no_root_squash,no_all_squash,sync)

重启

service rpcbind restart        ### 重新启动rpcbind服务(centos7以下)
systemctl restart rpcbind.service   ### 重新启动rpcbind服务(centos7)

设置固定端口

编辑配置文件

vi /etc/sysconfig/nfs

将下面的内容添加到配置文件末尾

MOUNTD_PORT="825"
STATD_PORT="909"
LOCKD_TCPPORT="4004"
LOCKD_UDPPORT="4004"
RQUOTAD_PORT="909"

端口设置好之后输入命令重启相关服务:

#centos7以下开机启动
service rpcbind restart 
service nfs restart

#centos7开机启动
systemctl restart rpcbind.service
systemctl restart nfs.service

防火墙通过配置端口:

-A INPUT -s 192.168.1.1 -p tcp -m state --state NEW -m tcp --dport 111 -j ACCEPT
-A INPUT -s 192.168.1.1 -p udp -m state --state NEW -m udp --dport 111 -j ACCEPT
-A INPUT -s 192.168.1.1 -p tcp -m state --state NEW -m tcp --dport 825 -j ACCEPT
-A INPUT -s 192.168.1.1 -p udp -m state --state NEW -m udp --dport 825 -j ACCEPT
-A INPUT -s 192.168.1.1 -p tcp -m state --state NEW -m tcp --dport 909 -j ACCEPT
-A INPUT -s 192.168.1.1 -p udp -m state --state NEW -m udp --dport 909 -j ACCEPT
-A INPUT -s 192.168.1.1 -p tcp -m state --state NEW -m tcp --dport 2049 -j ACCEPT
-A INPUT -s 192.168.1.1 -p udp -m state --state NEW -m udp --dport 2049 -j ACCEPT
-A INPUT -s 192.168.1.1 -p tcp -m state --state NEW -m tcp --dport 4004 -j ACCEPT
-A INPUT -s 192.168.1.1 -p udp -m state --state NEW -m udp --dport 4004 -j ACCEPT

挂载服务器设置

服务器2:192.168.1.2(挂载)
mount -t nfs 192.168.1.1:/app/im_attach/ /app/im_attach/  ### 挂载   

服务器2:192.168.1.3(挂载)
mount -t nfs 192.168.1.1:/app/im_attach/ /app/im_attach/  ### 挂载   

开机自动挂载

vi /etc/fstab    ### 编辑配置文件,将下面规则加入,IP和目录请自行调整

server_IP:/remote_dir   /local_dir   nfs  defaults  1  1

说明

本文只做学习参考,如有任何不准确的地方欢迎指正。

猜你喜欢

转载自blog.csdn.net/lulongji2035/article/details/107981922