A-A+
	初学linux网络服务之NFS 共享服务实验
一、实验拓扑如下描述
RHEL5.9_A----(vmnet1)---- RHEL5.9_B
RHEL5.9_A: 192.168.1.253/24
RHEL5.9_B: 192.168.1.20/24
实验一:
将/root 共享给192.168.1.20,可写、同步,允许客户机以root权限访问
NFS服务端操作:
- [root@dhcpser ~]# cat /etc/exports //查看nfs共享配置文件
 - /root 192.168.1.20(rw,sync,no_root_squash)
 - [root@dhcpser ~]# service portmap restart //重启rpc服务
 - [root@dhcpser ~]# service nfs restart //重启nfs服务
 - [root@dhcpser ~]# chkconfig portmap on //开机启动rpc
 - [root@dhcpser ~]# chkconfig nfs on //开机启动nfs
 
NFS客户端操作:
- [root@localhost ~]# service portmap restart //重启rpc服务
 - [root@localhost ~]# showmount -e 192.168.1.253 //查看远程共享
 - Export list for 192.168.1.253:
 - /root 192.168.1.20
 - [root@localhost ~]# mkdir -p /data/root/ //新建文件夹
 - [root@localhost ~]# mount 192.168.1.253:/root/ /data/root/ //挂载共享文件夹
 - [root@localhost ~]# df -hT | grep nfs //查看挂载结果
 - nfs 19G 2.7G 16G 15% /data/root
 - [root@localhost ~]# cd /data/root/ //进入目录
 - [root@localhost ~]# touch /data/root/test1.txt //创建测试文件
 - [root@localhost root]# ls -l/data/root/test1.txt //查看测试结果
 - -rw-r--r-- 1 root root 0 06-12 17:18 test1.txt
 
实验二:
将/usr/src 共享给192.168.1.0/24网段,可写、异步
NFS服务端操作:
- [root@dhcpser ~]# cat /etc/exports //查看nfs共享配置文件
 - /root 192.168.1.20(rw,sync,no_root_squash)
 - /usr/src 192.168.1.0/24(rw,async)
 - [root@dhcpser ~]# exportfs -rv //... //重启rpc服务
 - [root@dhcpser ~]# setfacl -m u:nfsnobody:rwx /usr/src/ //设置acl访问控制
 
NFS客户端操作:
- [root@localhost ~]# mkdir -p /data1/src //建挂载点
 - [root@localhost ~]# showmount -e 192.168.1.253 //查看远程共享
 - Export list for 192.168.1.253:
 - /root 192.168.1.20
 - /usr/src 192.168.1.0/24
 - [root@localhost ~]# mount 192.168.1.253:/usr/src/ /data1/src/ //挂载远程共享文件夹
 - [root@localhost ~]# cd /data1/src/ //进入目录
 - [root@localhost src]# touch test2.txt //创建测试文件
 - [root@localhost src]# ls -l test2.txt //查看测试结果
 - -rw-r--r-- 1 nfsnobody nfsnobody 0 06-12 17:23 test2.txt
 
实验三:
在上一个实验基础上实现客户端上面所有用户身份都映射成nfsnobody
NFS服务端操作:
[root@dhcpser ~]# chmod o+w /usr/src/ //改目录属性实现其他人可写
NFS客户端操作:
- [root@localhost ~]# useradd tom //添加普通用户
 - [root@localhost ~]# echo “123456” | passwd --stdin tom //为tom设置密码
 - [root@localhost ~]# su - tom //切换为普通用户
 - [tom@localhost ~]$ cd /data1/src/ //进目录
 - [tom@localhost src]$ touch tom1.txt //建文件
 - [tom@localhost src]$ ls -l tom1.txt //看结果为属主是tom
 - -rw-rw-r-- 1 tom tom 0 06-12 17:29 tom1.txt
 
再次回到服务器端来修改NFS主配置文件
- [root@dhcpser ~]# cat /etc/exports //查看nfs共享配置文件
 - /root 192.168.1.20(rw,sync,no_root_squash)
 - /usr/src 192.168.1.0/24(rw,async,all_squash)
 - [root@dhcpser ~]# exportfs -rv //重启rpc服务
 
NFS客户端操作:
- [tom@localhost src]$ touch tom2.txt //建文件
 - [tom@localhost src]$ ls -l tom2.txt //看结果属主是nfsnobody
 - -rw-rw-r-- 1 nfsnobody nfsnobody 0 06-12 17:31 tom2.txt
 
客户端实现开机自动挂载:
- [root@localhost ~]# cat /etc/fstab |tail -2 //编辑开机挂载配置
 - 192.168.1.1:/root /date/root nfs defaults 0 0
 - 192.168.1.1:/usr/src /date/srv nfs defaults 0 0
 
客户端实现触发挂载:
- [root@localhost ~]#vim /etc/auto.master //编辑触发挂载主目录
 - /date /etc/auto.misc
 - [root@localhost ~]#vim /etc/auto.misc //编辑触发关键字
 - src -rw 192.168.1.253:/usr/src
 - service autofs restart //重启服务
 - chkconfig autofs on //设开机启动