Centos7和Centos8的NFS配置

Centos7和Centos8的NFS配置几乎是完全一样的

服务端

Centos7默认安装了rpcbind, nfs-utils, 其中rpcbind的服务默认是启用的, nfs-utils默认是禁用的, 需要将后者启用

# 检查 rpcbind
systemctl status rpcbind
systemctl is-enabled rpcbind
# 检查并启用 nfs-server
systemctl status nfs-server
systemctl is-enabled nfs-server
systemctl enable nfs-server
systemctl is-enabled nfs-server
systemctl start nfs-server
# 前往编辑exports
vi /etc/exports

# 重启两个服务
systemctl restart rpcbind
systemctl restart nfs-server

其中/etc/exports的内容, 表示将/data/uploads这个目录开放给192.168.12.*网段, 只读, 异步, root用户按匿名用户对待

/data/uploads  192.168.12.*  (ro,async,root_squash)

参数说明

  • ro 只读(read only)
  • rw 读写(read write)
  • sync 同时将数据写入到内存与硬盘中,保证不丢失数据
  • async 优先将数据保存到内存,然后再写入硬盘,效率更高,但可能丢失数据
  • root_squash 当NFS客户端以root管理员访问时,映射为NFS服务器匿名用户
  • no_root_squash 当NFS客户端以root管理员访问时,映射为NFS服务器的root管理员

配置防火墙
默认Centos7没安装firewalld, 如果安装了并且是开机启动的, 需要在防火墙上添加规则. nfs服务不仅需要nfs server 还需要rpc-bind服务和mountd服务, 因为nfs服务需要向客户端广播地址和端口信息, nfs客户端需要使用mount对远程nfs服务器目录进行挂载.

# 查看服务状态
systemctl status firewalld
# 查看防火墙配置
firewall-cmd --zone=public --list-all
# 列出可用的服务
firewall-cmd --get-services

# 添加 nfs, rpc-bind, mountd
firewall-cmd --permanent --zone=internal --add-service=nfs
firewall-cmd --permanent --zone=internal --add-service=rpc-bind
firewall-cmd --permanent --zone=internal --add-service=mountd
firewall-cmd --reload 

客户端

客户端为Centos7时, 默认也安装了nfs-utils, 可以直接通过showmount查看可用的nfs目录

showmount -e 192.168.12.84

建目录, 挂载

# 建目录
cd /mnt
mkdir nfs_uploads
# 挂载
mount -t nfs 192.168.12.84:/data/uploads nfs_uploads

加入fstab, 以便开机自动挂咋

vi /etc/fstab 
# 加入以下内容, 内容开始
192.168.12.84:/data/uploads /mnt/nfs_uploads  nfs  defaults  0 0
# 内容结束

posted on 2021-09-29 15:35  Milton  阅读(705)  评论(0编辑  收藏  举报

导航