服务端设置: [iyunv@server ~]# cat /etc/redhat-release 查看操作系统版本信息 CentOS release 5.5 (Final) [iyunv@server ~]# uname -r 查看当前系统内核版本号 2.6.18-194.el5 [iyunv@server ~]# uname -a Linux server 2.6.18-194.el5 #1SMP Fri Apr 2 14:58:35 EDT 2010 i686 i686 i386 GNU/Linux [iyunv@server ~]# rpm -aqnfs-utils portmap nfs-utils-1.0.9-44.el5 portmap-4.0-65.2.2.1 [iyunv@server ~]# rpm -aq |egrep "nfs|portmap" 查看软件包 nfs-utils-lib-1.0.8-7.6.el5 nfs-utils-1.0.9-44.el5 portmap-4.0-65.2.2.1
[iyunv@server ~]#/etc/init.d/portmap start 启动portmap服务 Starting portmap: [ OK ] [iyunv@server ~]# netstat -lnt|grep 111 查看端口,确认portmap服务启动 tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN [iyunv@server ~]#/etc/init.d/nfs start 启动 nfs服务 Starting NFS services: [ OK ] Starting NFS quotas: [ OK ] Starting NFS daemon: [ OK ] Starting NFS mountd: [ OK ] [iyunv@server ~]#/etc/init.d/nfs status rpc.mountd (pid 12083) isrunning... nfsd (pid 12080 12079 1207812077 12076 12075 12074 12073) is running... rpc.rquotad (pid 12068) isrunning... [iyunv@server ~]# ps -ef |grep rpc root 2603 7 0 May13 ? 00:00:00 [rpciod/0] root 2609 1 0 May13 ? 00:00:00 rpc.statd root 2641 1 0 May13 ? 00:00:00 rpc.idmapd rpc 12042 1 0 01:00 ? 00:00:00 portmap root 12068 1 0 01:01 ? 00:00:00 rpc.rquotad root 12083 1 0 01:01 ? 00:00:00 rpc.mountd root 12120 11924 0 01:02 pts/0 00:00:00 grep rpc
[iyunv@server /]# mkdir /data 创建共享目录 [iyunv@server /]# cd /data [iyunv@server data]#touch yubing.txt [iyunv@server data]# ll total 4 -rw-r--r-- 1 root root 0 May 1401:11 yubing.txt [iyunv@server data]# echo"my name is yubing">yubing.txt [iyunv@server data]# catyubing.txt my name is yubing
[iyunv@server ~]# vi /etc/exports /data 10.0.0.0/24(rw,sync) 格式为: 共享目录+指定共享IP地址或地址段(rw,sync)
[iyunv@server ~]#/etc/init.d/nfs reload 重新加载
[iyunv@server ~]#cat /var/lib/nfs/etab /data 10.0.0.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,mapping=identity,anonuid=65534,anongid=65534)
[iyunv@server ~]# showmount -e 127.0.0.1 Export list for 127.0.0.1: /data1 10.0.0.0/24
客户端设置: [iyunv@client ~]#/etc/init.d/portmap start 启动 portmap:[确定]
[iyunv@client ~]# mkdir /yubing [iyunv@client ~]# cd /yubing [iyunv@client yubing]# ll 总计 0
[iyunv@client ~]# mount -t nfs10.0.0.152:/data /yubing 挂载共享目录 [iyunv@client ~]# cd /yubing [iyunv@client yubing]# ll 总计 4 -rw-r--r-- 1 root root 0 05-1401:11 yubing.txt
共享目录权限设置: [iyunv@client yubing]# ll 总计 8 -rw-r--r-- 1 root root 18 05-1401:21 yubing.txt [iyunv@client yubing]# cat yubing.txt 能够查看文件内容却无法写入 my name is yubing 是因为文件权限为644 [iyunv@client yubing]# echo"aaaaa">yubing.txt -bash: yubing.txt: 权限不够 [iyunv@client yubing]# touch yubing1.txt 无法新建文件 touch: 无法触碰“yubing1.txt”: 权限不够 [iyunv@client yubing]# ls -ld/yubing drwxr-xr-x 2 root root 409605-14 01:11 /yubing [iyunv@client yubing]# rm yubing.txt rm:是否删除有写保护的一般文件“yubing.txt”? y 无法删除 rm: 无法删除“yubing.txt”: 权限不够
来到服务端进行权限更改: [iyunv@server data]# chown nfsnobody.nfsnobody /data [iyunv@server data]# ls -ld/data drwxr-xr-x 2 nfsnobody nfsnobody 4096 May 14 01:11 /data
回到客户端查看权限: [iyunv@client yubing]# ls -ld/yubing drwxr-xr-x 2 nfsnobody nfsnobody 4096 05-14 01:11 /yubing [iyunv@client yubing]# ll 总计 8 -rw-r--r-- 1 root root 18 05-1401:21 yubing.txt [iyunv@client yubing]# touchyubing1.txt 新建成功 [iyunv@client yubing]# ll 总计 12 -rw-r--r-- 1 nfsnobody nfsnobody 0 05-14 01:29 yubing1.txt -rw-r--r-- 1 root root 18 05-14 01:21 yubing.txt [iyunv@client yubing]# echo"aaaaa">yubing.txt 此文件用户为root,无写入权限 -bash: yubing.txt: 权限不够 [iyunv@client yubing]# echo"aaaaa">yubing1.txt [iyunv@client yubing]# cat yubing1.txt aaaaa [iyunv@client yubing]# rm yubing.txt rm:是否删除有写保护的一般文件“yubing.txt”? y [iyunv@client yubing]# ll 总计 8 -rw-r--r-- 1 nfsnobody nfsnobody 6 05-14 01:30 yubing1.txt [iyunv@client yubing]#
为什么chown nfsnobody.nfsnobody /data后客户端就有权限了呢? 在服务端我们可以看到: [iyunv@server ~]# cat /etc/exports /data 10.0.0.0/24(rw,sync) [iyunv@server ~]# cat /var/lib/nfs/etab /data 10.0.0.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,mapping=identity,anonuid=65534,anongid=65534) [iyunv@server ~]# grep nfsnobody /etc/passwd nfsnobody:x:65534:65534:AnonymousNFS User:/var/lib/nfs:/sbin/nologin
再来看客户端: [iyunv@client yubing]# grep nfsnobody /etc/passwd nfsnobody:x:65534:65534:AnonymousNFS User:/var/lib/nfs:/sbin/nologin
所以,我们可以 vi /etc/exports /data 10.0.0.0/24(rw,sync,all_squash,anonuid=888,anongid=999) 来指定用户的UID和GID,当然服务端需存在UID、GID为888的用户,客户端只要存在UID、GID为888的用户,就可以拥有服务端对共享目录设置权限后的各种权限了。
错误提示解决: 错误提示1: [iyunv@client yubing]# mount -tnfs 10.0.0.152:/data /yubing mount: mountto NFS server '10.0.0.152' failed: System Error: Connection refused. 挂载失败,查看服务端服务是否正常运行 [iyunv@server ~]#/etc/init.d/portmap status portmap is stopped [iyunv@server ~]#/etc/init.d/portmap start Starting portmap: [ OK ] [iyunv@server ~]#/etc/init.d/nfs status rpc.mountd is stopped nfsd is stopped rpc.rquotad is stopped [iyunv@server ~]#/etc/init.d/nfs start Starting NFS services: [ OK ] Starting NFS quotas: [ OK ] Starting NFS daemon: [ OK ] Starting NFS mountd: [ OK ]
[iyunv@client yubing]# mount -tnfs 10.0.0.152:/data /yubing [iyunv@client yubing]# df -h 文件系统容量已用可用已用% 挂载点 /dev/sda3 19G 1.6G 16G 9% / /dev/sda1 122M 12M 104M 10% /boot tmpfs 506M 0 506M 0% /dev/shm 10.0.0.152:/data 7.7G 1.6G 5.7G 22% /yubing 挂载成功
错误提示2: [iyunv@server ~]#/etc/init.d/nfs start 启动nfs失败 Starting NFSservices: [ OK ] Starting NFSquotas: Cannot register service: RPC: Unable to receive; errno = Connectionrefused rpc.rquotad:unable to register (RQUOTAPROG, RQUOTAVERS, udp). [FAILED] Starting NFSdaemon: [FAILED]
[iyunv@server ~]#/etc/init.d/portmap status portmap is stopped [iyunv@server ~]#/etc/init.d/portmap start Starting portmap: [ OK ] [iyunv@server ~]#/etc/init.d/nfs start Starting NFS services: [ OK ] Starting NFS quotas: [ OK ] Starting NFS daemon: [ OK ] Starting NFS mountd: [ OK ] 必须先启动portmap服务后再启动nfs服务,因为NFS及其辅助程序都是基于RPC(Remote Procedure Call)协议的(使用的端口为111),所以首先要确保系统中运行了portmap服务。
错误提示3: [iyunv@server ~]#/etc/init.d/nfs reload exportfs: Nooptions for /data10.0.0.0/24(rw,sync) : suggest (sync) to avoid warning
[iyunv@server ~]#/etc/init.d/nfs reload exportfs: No options for/data10.0.0.0/24(rw,sync) : suggest (sync) to avoid warning [iyunv@server ~]# vi /etc/exports /data10.0.0.0/24(rw,sync) 中间没空格 改为: /data 10.0.0.0/24(rw,sync) [iyunv@server ~]#/etc/init.d/nfs reload 重启服务成功 [iyunv@server ~]#
错误提示4: [iyunv@client yubing]# df -h 文件系统容量已用可用已用% 挂载点 /dev/sda3 19G 1.6G 16G 9% / /dev/sda1 122M 12M 104M 10% /boot tmpfs 506M 0 506M 0% /dev/shm
(卡死,不能做任何操作) [iyunv@client ~]# cd /yubing
(依然卡死)
客户端挂载了服务端的共享目录,服务端如果关闭,就会出现卡死 只能重新连接后取消挂载 [iyunv@client ~]# umount -lf/yubing [iyunv@client ~]# df -h 文件系统容量已用可用已用% 挂载点 /dev/sda3 19G 1.6G 16G 9% / /dev/sda1 122M 12M 104M 10% /boot tmpfs 506M 0 506M 0% /dev/shm [iyunv@client ~]#
如果大家有出现其他问题,希望能随时给我留言~谢谢啦~
|