Linux主机间文件共享(NFS)

实验要求:

1、将目录/zhy共享给网段192.168.1.0/24内的主机;访问权限为可写、同步;允许客户机以root权限访问。

2、将目录/zn共享给192.168.1.20主机访问权限为读写、同步;主机192.168.1.21只读访问,异步;访问用户均降为nfsnobody用户。

3、开机自动挂载/zhy,挂载到客户端的/zhy目录。

4、触发挂载/zn,挂载到客户端的/zn/nfs目录。

实验步骤:

1、安装软件包

[root@localhost ~]# rpm -q portmap

portmap-4.0-65.2.2.1

[root@localhost ~]# rpm -q nfs-utils

nfs-utils-1.0.9-66.el5                             //系统中这两个软件包已经安装

2、修改配置文件

[root@localhost ~]# cat /etc/exports

/zhy    192.168.1.0/24(rw,sync,no_root_squash)             //以root权限访问

/zn     192.168.1.20(rw,sync) 192.168.1.21(rw,async,all_squash)  //不可用root权限访问

[root@localhost ~]# setfacl -m u:nfsnobody:rwx /zn            //为/zn目录设置访问权限

[root@localhost ~]# cat /etc/fstab

……

192.168.1.253:/zhy      /zhy      nfs     defaults    0 0  //客户端开机自动挂载

[root@localhost ~]# cat /etc/auto.master

……

/misc   /etc/auto.misc

/zn     /etc/zn.txt                //配置触发挂载主文件

……

[root@localhost ~]# cat /etc/zn.txt

zn      -fstype=nfs,rw          192.168.1.253:/zn    //配置触发挂载子文件

3、重启服务

[root@localhost ~]# exportfs -rv                      //重启nfs服务

exporting 192.168.1.0/24:/zhy

exporting 192.168.1.20:/zn

exporting 192.168.1.21:/zn

[root@localhost ~]# chkconfig portmap on

[root@localhost ~]# chkconfig nfs on

[root@localhost ~]# service portmap restart          

停止 portmap:                                             [确定]

启动 portmap:                                             [确定]

[root@localhost ~]# service nfs restart

关闭 NFS mountd:                                          [失败]

关闭 NFS 守护进程:                                        [失败]

关闭 NFS quotas:                                          [失败]

关闭 NFS 服务:                                            [确定]

启动 NFS 服务:                                            [确定]

关掉 NFS 配额:                                            [确定]

启动 NFS 守护进程:                                        [确定]

启动 NFS mountd:                                          [确定]

Stopping RPC idmapd:                                       [确定]

正在启动 RPC idmapd:                                      [确定]

4、客户端验证

[root@localhost ~]# showmount -e 192.168.1.253

Export list for 192.168.1.253:

/zn  192.168.1.21,192.168.1.20

/zhy 192.168.1.0/24                //客户端验证成功