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