版权声明:本文为博主原创文章,未经博主允许不得转载 https://blog.csdn.net/weixin_42867972/article/details/82726195
nfs 服务器
NFS(网络文件系统)为两台Linux主机之间的通讯,提供了类似于windows上共享目录一样的服务。NFS客户端经常通过NFS方式访问NFS服务器上的文件,NFS客户端可以通过挂在的方式将NFS服务端共享的数据文件目录挂载到NFS客户端本地系统之中。
一、安装 NFS 服务器
[root@centos-7 /]# yum install -y nfs-*
二、配置 NFS 服务器(共享 /data 目录)
[root@centos-7 /]# vim /etc/exports
/data 192.168.10.100/24(rw,no_root_squash,sync) #可读可写,不压缩客户端 root 权限
/data 192.168.0.0/24(ro) #只读方式
/data 10.10.0.0/24(rw) #可读可写
常用的服务器端 共享参数:
rw: 允许客户端读写
ro: 只读
no_root_squash: 不压缩 root 的权限
all_squash: 不管什么用户,它都会把权限改为 nfsnobody ,包含管理员
async: 数据异步模式,有改动,先放到内存中,再同步到磁盘 速度快,
sync: 数据同步模式,将共享数据的改动,同步到磁盘 ====(推荐) 稳定,数据不易丢失,但是速度慢;(默认设置)
三、启动服务
[root@centos-7 /]# systemctl start nfs
**四、在客户端上挂载 /data **
[root@deng-120 /]# mount -t nfs 192.168.10.71:/data /nfs
**五、在客户端上查看挂载情况 **
[root@deng-120 /]# mkdir /nfs
[root@deng-120 /]# df -h
......
192.168.10.71:/data 797M 33M 765M 5% /nfs
- nfs 检查并固定端口号:
打开 111 和 2049 端口,这是 rpcbind 和 nfs 进程对应的端口
但是其他端口是系统开机时随机分配的,很难确定,所有需要修改配置文件
打开注释,固定该端口 30003
[root@centos-7 /]# vim /etc/sysconfig/nfs
MOUNTD_PORT=30003
[root@centos-7 /]# netstat -natul #查看打开的端口
......
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:30003 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN
......
udp 0 0 0.0.0.0:2049 0.0.0.0:*
udp 0 0 0.0.0.0:111 0.0.0.0:*
udp 0 0 0.0.0.0:30003 0.0.0.0:*
- nfs在防火墙后环境的部署:
iptables -F #清空规则
iptables -t nat -F #清空 nat 表规则
iptables -X #删除用户自定义的规则链
iptables -t nat -X #删除用户自定义 nat 的规则链
iptables -t filter -P INPUT DROP #设定全局禁止模式
iptables -t filter -A INPUT -p tcp --dport 22 -j ACCEPT #开启 22 端口允许远程
iptables -t filter -A INPUT -p tcp --dport 111 -j ACCEPT #允许 111 端口 tcp 协议通过
iptables -t filter -A INPUT -p udp --dport 111 -j ACCEPT #允许 111 端口 udp 协议通过
iptables -t filter -A INPUT -p tcp --dport 2049 -j ACCEPT #允许 2049 端口 udp 协议通过
iptables -t filter -A INPUT -p udp --dport 2049 -j ACCEPT #允许 2049 端口 udp 协议通过
iptables -t filter -A INPUT -p tcp --dport 30003 -j ACCEPT #允许 30003 端口 udp 协议通过
iptables -t filter -A INPUT -p udp --dport 30003 -j ACCEPT #允许 30003 端口 udp 协议通过
在以后需要添加其他防火墙规制的时候可以在后面进行添加