操作系统版本: [root@localhost /]# cat /etc/redhat-release 1、检查portmap服务运行状态(因为NFS及其辅助程序都是基于RPC的,所以我们要确保系统中首先运行portmap服务) [root@localhost /]# id uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel) context=root:system_r:unconfined_t [root@localhost /]# service portmap status portmap is stopped 结果显示portmap服务是停止的,可以通过以下命令启动该服务: [root@localhost /]# service portmap start Starting portmap: [ OK ] [root@localhost /]# service portmap status portmap (pid 11085) is running... 结果显示portmap服务已处于“running”状态。 2、检查nfs服务运行状态 [root@localhost /]# service nfs status Shutting down NFS mountd: rpc.mountd is stopped nfsd is stopped rpc.rquotad is stopped 结果显示nfs服务是停止的,可以通过以下命令启动该服务: [root@localhost /]# service nfs start Starting NFS services: [ OK ] Starting NFS quotas: [ OK ] Starting NFS daemon: [ OK ] Starting NFS mountd: [ OK ] 此时来检查一下nfs服务运行状态,由下可知,nfs服务已启用。 [root@localhost /]# service nfs status Shutting down NFS mountd: rpc.mountd (pid 11155) is running... nfsd (pid 11151 11148 11147 11146 11145 11144 11143 11142) is running... rpc.rquotad (pid 11138) is running... 3、设置nfs服务在系统重启后自动运行 [root@localhost /]# chkconfig --list nfs nfs 0:off 1:off 2:off 3:off 4:off 5:off 6:off [root@localhost /]# chkconfig nfs on [root@localhost /]# chkconfig --list nfs nfs 0:off 1:off 2:on 3:on 4:on 5:on 6:off 4、/etc/exports文件设置 /etc/exports文件格式: 共享的目录 主机名称1或IP1(参数1,参数2) 共享的目录 主机名称2或IP2(参数3,参数4) 如果使用主机名称,则必须预先在/etc/hosts文件中定义。 exports主要参数: rw:可读写权限 ro:只读权限 no_root_squash: 对于登陆NFS主机的共享目录用户如果是root的话则对该目录具有root权限。 这样做极不安全,建议不用为好! root_squash: 对于登陆NFS主机的共享目录用户使用者如果是root则它的权限将被压缩成匿名使用者, 同时它的UID和GID都会变成nobody那个系统账号的身份。 all_squash: 不管登陆NFS主机用户身份如何,它的身份都会被压缩成匿名使用者,通常就是nobody anonuid:anonuid=xxx, 制定NFS服务器/etc/passwd中匿名用户的UID anongid:anonuid=xxx, 制定NFS服务器/etc/passwd中匿名用户的GID sync: 数据在请求时写入共享 async: NFS在写入数据前可响应请求 secure: NFS通过1024以下的安全端口发送 insecure: NFS通过1024以上端口发送 hide: 不共享NFS目录的子目录 no_hide: 共享NFS目录的子目录 例如在/etc/exports文件中添加以下内容(红色部分): [root@localhost /]# cat /etc/exports /study 10.10.10.12(rw,sync,no_root_squash) 5、输出共享目录 [root@localhost /]# exportfs -a 查看是否成功输出共享目录: [root@localhost /]# cat /etc/exports /study 10.10.10.12(rw,sync,no_root_squash) 九、NFS客户端相关的查询与设置操作设置(NFS客户端IP:10.10.10.12/25) [root@REDHATAS5 /]# cat /etc/redhat-release Red Hat Enterprise Linux Server release 5 (Tikanga) 1、检查portmap运行状态(因为NFS及其辅助程序都是基于RPC的,所以我们要确保系统中首先运行portmap服务) [root@REDHATAS5 /]# service portmap status portmap (pid 22742) is running... 如果portmap服务未启,则在mount时会报错: [root@REDHATAS5 /]# mount -t nfs 10.10.10.10:/study /nfstest mount.nfs: Input/output error 2、查看NFS服务端共享目录 [root@REDHATAS5 /]# showmount -e 10.10.10.10 Export list for 10.10.10.10: /study 10.10.10.12 3、挂载共享目录 [root@REDHATAS5 /]# mount -t nfs 10.10.10.10:/study /nfstest 4、查看成功挂载的nfs目录 [root@REDHATAS5 /]# df -h | grep /nfstest 10.10.10.10:/study 7.8G 6.8G 695M 91% /nfstest 5、测试共享目录是否可读写 [root@REDHATAS5 nfstest]# ls -l total 8 -rw-r--r-- 1 root root 21 Jun 24 13:13 nfs-server.txt [root@REDHATAS5 nfstest]# touch nfs-client.txt [root@REDHATAS5 nfstest]# ls -l total 12 -rw-r--r-- 1 root root 0 Jun 24 13:13 nfs-client.txt -rw-r--r-- 1 root root 21 Jun 24 13:13 nfs-server.txt 由上可知,表明可读写。 |
|