A-A+

初学linux网络服务之NFS 共享服务实验

2016年02月20日 站长资讯 暂无评论

一、实验拓扑如下描述

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服务端操作:

  1. [root@dhcpser ~]# cat /etc/exports                  //查看nfs共享配置文件  
  2. /root   192.168.1.20(rw,sync,no_root_squash)  
  3. [root@dhcpser ~]# service portmap restart           //重启rpc服务  
  4. [root@dhcpser ~]# service nfs restart               //重启nfs服务  
  5. [root@dhcpser ~]# chkconfig portmap on           //开机启动rpc  
  6. [root@dhcpser ~]# chkconfig nfs on               //开机启动nfs  

NFS客户端操作:

  1. [root@localhost ~]# service portmap restart         //重启rpc服务  
  2. [root@localhost ~]# showmount -e 192.168.1.253   //查看远程共享   
  3. Export list for 192.168.1.253:  
  4. /root    192.168.1.20  
  5. [root@localhost ~]# mkdir -p /data/root/            //新建文件夹  
  6. [root@localhost ~]# mount 192.168.1.253:/root/ /data/root/       //挂载共享文件夹  
  7. [root@localhost ~]# df -hT | grep nfs                         //查看挂载结果  
  8.                nfs     19G  2.7G   16G  15% /data/root  
  9. [root@localhost ~]# cd /data/root/                          //进入目录  
  10. [root@localhost ~]# touch  /data/root/test1.txt        //创建测试文件  
  11. [root@localhost root]# ls -l/data/root/test1.txt       //查看测试结果  
  12.   
  13. -rw-r--r-- 1 root root 0 06-12 17:18 test1.txt  

实验二:

将/usr/src 共享给192.168.1.0/24网段,可写、异步

NFS服务端操作:

  1. [root@dhcpser ~]# cat /etc/exports                        //查看nfs共享配置文件  
  2. /root   192.168.1.20(rw,sync,no_root_squash)  
  3. /usr/src        192.168.1.0/24(rw,async)  
  4. [root@dhcpser ~]# exportfs -rv //...                    //重启rpc服务  
  5. [root@dhcpser ~]# setfacl -m u:nfsnobody:rwx /usr/src/      //设置acl访问控制  

NFS客户端操作:

  1. [root@localhost ~]# mkdir -p /data1/src                //建挂载点  
  2. [root@localhost ~]# showmount -e 192.168.1.253          //查看远程共享  
  3. Export list for 192.168.1.253:  
  4.   
  5. /root    192.168.1.20  
  6. /usr/src 192.168.1.0/24  
  7. [root@localhost ~]# mount 192.168.1.253:/usr/src/ /data1/src/   //挂载远程共享文件夹  
  8. [root@localhost ~]# cd /data1/src/                          //进入目录  
  9. [root@localhost src]# touch test2.txt                       //创建测试文件  
  10. [root@localhost src]# ls -l test2.txt                        //查看测试结果  
  11. -rw-r--r-- 1 nfsnobody nfsnobody 0 06-12 17:23 test2.txt  

实验三:

在上一个实验基础上实现客户端上面所有用户身份都映射成nfsnobody

NFS服务端操作:

[root@dhcpser ~]# chmod o+w /usr/src/ //改目录属性实现其他人可写

NFS客户端操作:

  1. [root@localhost ~]# useradd tom         //添加普通用户  
  2. [root@localhost ~]# echo “123456” | passwd --stdin tom  //为tom设置密码  
  3. [root@localhost ~]# su - tom            //切换为普通用户  
  4. [tom@localhost ~]$ cd /data1/src/          //进目录  
  5. [tom@localhost src]$ touch tom1.txt      //建文件  
  6. [tom@localhost src]$ ls -l tom1.txt        //看结果为属主是tom  
  7. -rw-rw-r-- 1 tom tom 0 06-12 17:29 tom1.txt  

再次回到服务器端来修改NFS主配置文件

  1. [root@dhcpser ~]# cat /etc/exports                       //查看nfs共享配置文件  
  2.   
  3. /root   192.168.1.20(rw,sync,no_root_squash)  
  4. /usr/src        192.168.1.0/24(rw,async,all_squash)  
  5. [root@dhcpser ~]# exportfs -rv                          //重启rpc服务  

NFS客户端操作:

  1. [tom@localhost src]$ touch tom2.txt                      //建文件  
  2. [tom@localhost src]$ ls -l tom2.txt                       //看结果属主是nfsnobody  
  3. -rw-rw-r-- 1 nfsnobody nfsnobody 0 06-12 17:31 tom2.txt  

客户端实现开机自动挂载:

  1. [root@localhost ~]# cat /etc/fstab |tail -2                     //编辑开机挂载配置  
  2. 192.168.1.1:/root       /date/root  nfs defaults 0 0  
  3. 192.168.1.1:/usr/src    /date/srv         nfs  defaults  0 0  

客户端实现触发挂载:

  1. [root@localhost ~]#vim /etc/auto.master                   //编辑触发挂载主目录  
  2. /date  /etc/auto.misc  
  3. [root@localhost ~]#vim /etc/auto.misc                    //编辑触发关键字  
  4. src           -rw                     192.168.1.253:/usr/src   
  5. service autofs restart                                  //重启服务  
  6. chkconfig autofs on                                  //设开机启动  
标签:

给我留言