Linux NFS搭建与错误提示解决



服务端设置:

[root@server ~]# cat /etc/redhat-release   查看操作系统版本信息

CentOS release 5.5 (Final)

[root@server ~]# uname -r     查看当前系统内核版本号

2.6.18-194.el5

[root@server ~]# uname -a

Linux server 2.6.18-194.el5 #1SMP Fri Apr 2 14:58:35 EDT 2010 i686 i686 i386 GNU/Linux

[root@server ~]# rpm -aqnfs-utils portmap

nfs-utils-1.0.9-44.el5

portmap-4.0-65.2.2.1

[root@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


[root@server ~]#/etc/init.d/portmap start        启动portmap服务

Starting portmap: [  OK  ]

[root@server ~]# netstat -lnt|grep 111    查看端口,确认portmap服务启动

tcp        0     0 0.0.0.0:111                0.0.0.0:*                   LISTEN    

[root@server ~]#/etc/init.d/nfs start      启动 nfs服务

Starting NFS services:  [ OK  ]

Starting NFS quotas: [  OK  ]

Starting NFS daemon: [  OK  ]

Starting NFS mountd: [  OK  ]

[root@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...

[root@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


[root@server /]# mkdir /data   创建共享目录

[root@server /]# cd /data

[root@server data]#touch yubing.txt

[root@server data]# ll

total 4

-rw-r--r-- 1 root root 0 May 1401:11 yubing.txt

[root@server data]# echo"my name is yubing">yubing.txt

[root@server data]# catyubing.txt

my name is yubing


[root@server ~]# vi /etc/exports    

/data 10.0.0.0/24(rw,sync)

格式为:

共享目录+指定共享IP地址或地址段(rw,sync)


[root@server ~]#/etc/init.d/nfs reload     重新加载


[root@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)


[root@server ~]# showmount -e 127.0.0.1  

Export list for 127.0.0.1:

/data1 10.0.0.0/24



客户端设置:

[root@client ~]#/etc/init.d/portmap start

启动 portmap:[确定]


[root@client ~]# mkdir /yubing

[root@client ~]# cd /yubing

[root@client yubing]# ll

总计 0


[root@client ~]# mount -t nfs10.0.0.152:/data /yubing    挂载共享目录

[root@client ~]# cd /yubing

[root@client yubing]# ll

总计 4

-rw-r--r-- 1 root root 0 05-1401:11 yubing.txt



共享目录权限设置:

[root@client yubing]# ll

总计 8

-rw-r--r-- 1 root root 18 05-1401:21 yubing.txt

[root@client yubing]# cat yubing.txt          

my name is yubing                        

[root@client yubing]# echo"aaaaa">yubing.txt

-bash: yubing.txt: 权限不够

[root@client yubing]# touch yubing1.txt        无法新建文件

touch: 无法触碰yubing1.txt: 权限不够

[root@client yubing]# ls -ld/yubing

drwxr-xr-x 2 root root 409605-14 01:11 /yubing

[root@client yubing]# rm yubing.txt

rm:是否删除有写保护的一般文件yubing.txt? y     无法删除

rm: 无法删除yubing.txt: 权限不够


来到服务端进行权限更改:

[root@server data]# chown nfsnobody.nfsnobody /data

[root@server data]# ls -ld/data

drwxr-xr-x 2 nfsnobody nfsnobody 4096 May 14 01:11 /data


回到客户端查看权限:

[root@client yubing]# ls -ld/yubing

drwxr-xr-x 2 nfsnobody nfsnobody 4096 05-14 01:11 /yubing

[root@client yubing]# ll

总计 8

-rw-r--r-- 1 root root 18 05-1401:21 yubing.txt

[root@client yubing]# touchyubing1.txt       新建成功

[root@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

[root@client yubing]# echo"aaaaa">yubing.txt      此文件用户为root,无写入权限

-bash: yubing.txt: 权限不够

[root@client yubing]# echo"aaaaa">yubing1.txt

[root@client yubing]# cat yubing1.txt

aaaaa

[root@client yubing]# rm yubing.txt

rm:是否删除有写保护的一般文件yubing.txt? y

[root@client yubing]# ll

总计 8

-rw-r--r-- 1 nfsnobody nfsnobody 6 05-14 01:30 yubing1.txt

[root@client yubing]#


为什么chown nfsnobody.nfsnobody /data后客户端就有权限了呢?

在服务端我们可以看到:

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

/data 10.0.0.0/24(rw,sync)

[root@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)

[root@server ~]# grep nfsnobody /etc/passwd

nfsnobody:x:65534:65534:AnonymousNFS User:/var/lib/nfs:/sbin/nologin

(1)rw:可读写权限。

(2)ro:只读权限。

(3)sync:同步写入资料到内存与硬盘中。

(4)async:资料会先暂存于内存中,而非直接写入硬盘。

(5)no_root_squash:当登录NFS主机使用共享目录的使用者是root时,其权限将被转换成为匿名使

    用者,通常它的UIDGID都会变成nobody身份。

(6)root_squash;如果登录NFS主机使用共享目录的使用者是root,那么对于这个共享的目录来说,

    它具有root的权限。

(7)all_squash:忽略登录NFS使用者的身份,其身份都会被转换为匿名使用者,通常即nobody

(8)anonuid:通常为nobody,也可以自行设定这个UID的值,UID必须存在于/etc/passwd中。

(9)anongid:同anonuid,但是变为Group ID


再来看客户端:

[root@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)

来指定用户的UIDGID,当然服务端需存在UIDGID888的用户,客户端只要存在UIDGID888的用户,就可以拥有服务端对共享目录设置权限后的各种权限了。




错误提示解决:

错误提示1:

[root@client yubing]# mount -tnfs 10.0.0.152:/data /yubing

mount: mountto NFS server '10.0.0.152' failed: System Error: Connection refused.

挂载失败,查看服务端服务是否正常运行

[root@server ~]#/etc/init.d/portmap status

portmap is stopped

[root@server ~]#/etc/init.d/portmap start

Starting portmap: [  OK  ]

[root@server ~]#/etc/init.d/nfs status

rpc.mountd is stopped

nfsd is stopped

rpc.rquotad is stopped

[root@server ~]#/etc/init.d/nfs start

Starting NFS services:  [ OK  ]

Starting NFS quotas: [  OK  ]

Starting NFS daemon: [  OK  ]

Starting NFS mountd: [  OK  ]


[root@client yubing]# mount -tnfs 10.0.0.152:/data /yubing

[root@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:

[root@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]


[root@server ~]#/etc/init.d/portmap status

portmap is stopped

[root@server ~]#/etc/init.d/portmap start

Starting portmap: [  OK  ]

[root@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:

[root@server ~]#/etc/init.d/nfs reload

exportfs: Nooptions for /data10.0.0.0/24(rw,sync) : suggest (sync) to avoid warning


[root@server ~]#/etc/init.d/nfs reload

exportfs: No options for/data10.0.0.0/24(rw,sync) : suggest (sync) to avoid warning

[root@server ~]# vi /etc/exports

/data10.0.0.0/24(rw,sync)    中间没空格

改为:

/data 10.0.0.0/24(rw,sync)

[root@server ~]#/etc/init.d/nfs reload  重启服务成功

[root@server ~]#


错误提示4:

[root@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


(卡死,不能做任何操作)

[root@client ~]# cd /yubing


(依然卡死)


客户端挂载了服务端的共享目录,服务端如果关闭,就会出现卡死

只能重新连接后取消挂载

[root@client ~]# umount -lf/yubing

[root@client ~]# df -h

文件系统容量已用可用已用% 挂载点

/dev/sda3              19G  1.6G  16G   9% /

/dev/sda1             122M   12M 104M  10% /boot

tmpfs                 506M     0 506M   0% /dev/shm

[root@client ~]#


错误提示5

[root@syt ~]# mount -t nfs10.0.0.242:/data/r_shared /data/b_r

mount:10.0.0.242:/data/r_shared failed, reason given by server: Permission denied


NFS服务端/data/r_shared目录不存在。检查共享目录是/date/r_shared


如果大家有出现其他问题,希望能随时给我留言~谢谢啦~