系统环境:
[[email protected] ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[[email protected] ~]# uname -r
3.10.0-327.el7.x86_64
[[email protected] ~]# ip addr show enp0s8 | awk ‘NR==3{print $2}‘
192.168.235.36/24
#关闭防火墙和selinux
#安装NFS
[[email protected] ~]# yum install nfs-utils rpcbind -y
[[email protected] ~]# mkdir /nfs
[[email protected] ~]# chmod 777 /nfs
[[email protected] ~]# echo "hello" > /nfs/test.txt
#修改主配置文件 格式为:NFS共享目录 NFS客户端地址(权限1,权限2.....)
[[email protected] ~]# vim /etc/exports
/nfs 192.168.235.0/24(rw,sync,root_squash)
#rw 读写权限,sync 数据同步到NFS server后才返回,root_squash 压缩为匿名用户,
#更多权限 man 5 exports
#启动NFS服务,应先开起 RPC 服务
[[email protected] ~]# systemctl start rpcbind
[[email protected] ~]# systemctl start nfs-server
#显示远程共享列表
[[email protected] ~]# showmount -e 192.168.235.36
Export list for 192.168.235.36:
/nfs 192.168.235.0/24
#创建挂载目录 并挂载
[[email protected] ~]# mkdir /nfsfile
[[email protected] ~]# mount -t nfs 192.168.235.36:/nfs /nfsfile/
[[email protected] ~]# cd /nfsfile/
[[email protected] nfsfile]# ls
test.txt
[[email protected] nfsfile]# echo "hello" > test_2.txt
[[email protected] nfsfile]# ll
total 8
-rw-r--r-- 1 nfsnobody nfsnobody 6 Mar 31 16:58 test_2.txt
-rw-r--r-- 1 root root 6 Mar 31 16:44 test.txt
#Auto自动挂载服务
[[email protected] ~]# yum install -y autofs
#删除nfsfile目录
[[email protected] ~]# rm -rf /nfsfile
#在/etc/auto.master添加一行
[[email protected] /]# sed -n ‘7p‘ /etc/auto.master
/nfsfile /etc/nfs.misc
#创建nfs.misc
[[email protected] /]# vim /etc/nfs.misc
[[email protected] /]# cat /etc/nfs.misc
nfs -fstype=nfs 192.168.235.36:/nfs
[[email protected] /]# ls | grep nfsfile #没有nfsfile目录
[[email protected] /]# systemctl start autofs #开启autofs服务
[[email protected] /]# ls | grep nfsfile #出现一个目录
nfsfile
[[email protected] /]# cd nfsfile
[[email protected] nfsfile]# ls #该目录下面没有任何目录
[[email protected] nfsfile]# cd nfs #任可以切换到nfs目录下面,在我们切换的时候,autofs自动帮我们挂载了
[[email protected] nfs]# ls
test_2.txt test.txt
#自动挂载成功!