centos7 安装NFS

安装部署

  • 安装NFS和rpc

yum install -y  nfs-utils

yum install -y  rpcbind

 

  • 启动服务和设置开机启动

#先启动rpc

systemctl start rpcbind

systemctl enable rpcbind

 

#设置安全传输

systemctl start nfs-server nfs-secure-server

systemctl enable nfs-server nfs-secure-server

#设置防火墙放行或关闭防火墙

firewall-cmd --permanent --add-service=nfs

firewall-cmd  --reload

showmount -e 遇到防火墙问题

配置NFS服务

虚拟机CentOS系统版本信息:

[[email protected] ~]# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core) 
[[email protected] ~]# 
[[email protected] ~]# uname -r
3.10.0-693.el7.x86_64
[[email protected] ~]# 
[[email protected] ~]# uname -m
x86_64
[[email protected] ~]# uname -n

客户端使用showmount -e 服务器ip 查看共享目录

  • 配置共享文件目录

mkdir /mnt/data

vim /etc/exports

    #设置所有网段均可访问

       /mnt/data 172.16.10.0/24(rw,sync,all_squash) 172.16.20.0/24(rw,sync,all_squash) 172.16.30.0/24(rw,sync,all_squash) 172.16.40.0/24(rw,sync,all_squash)

 

  • 客户端远程挂载

showmount -e ip

 

mount -t nfs -o vers=3,proto=tcp,nolock,sync,rsize=1048576,wsize=1048576 172.16.40.102:/mnt/data /home/data

centos7 安装NFS

  • 设置开机自动挂载

Vim /etc/fstab

172.16.10.14:/mnt/data     /home/data      nfs  defaults,_rnetdev  1  1

 mount -t nfs -o nolock 192.168.1.208:/export/share/ /export/mount/192.168.1.208

centos7 安装NFS

centos7 安装NFS

  • 服务端查看服务运行

[[email protected] ~]# systemctl status nfs

 

设置开机自动挂载:

开机自动挂载:

如果服务端或客户端的服务器重启之后需要手动挂载,我们可以加入到开机自动挂载

在客户端/etc/fstab里添加

192.168.163.128:/nfsdir      /nfsdir      nfs  defaults,_rnetdev  1  1

备注:第1个1表示备份文件系统,第2个1表示从/分区的顺序开始fsck磁盘检测,0表示不检测。

_rnetdev  表示主机无法挂载直接跳过,避免无法挂载主机无法启动

此处,CentOS 7中,在fstab中添加了自动挂载NFS的配置,但是系统启动后没有成功挂载的解决办法是:

1.先确保CentOS 7中的rc.local系统启动时可以自动运行

->需要确保该文件有可执行的权限

->/etc/rc.local是个软链接,所链接的实际文件是/ect/rc.d/rc.local,CentOS 7中默认没有执行权限

->所以此处要去给/etc/rc.d/rc.local添加可执行权限:

 chmod +x /etc/rc.d/rc.local

2.然后再给/etc/rc.local中最后添加一行:

mount -a

如此,系统启动后,就会运行/etc/rc.local,然后就会执行到

mount -a

即执行fstab中的所有项,最终执行到NFS的mount。 

参考:https://www.crifan.com/centos_7_fstab_add_auto_mount_but_fail_to_run_nfs/

https://www.crifan.com/remote_ubuntu_server_setup_nfs_server_for_other_access_files/

 

查看启动日志 /var/log/boot.log