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

说明

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值