生产中NFS案例记录---写入权限解决过程

        生产中NFS案例记录---写入权限解决过程

 

 

NFS配置要求:

1、 oracle文件写入到NFS Server端,注意权限要与oracle端一致。

2、 Oracle端目录文件所属用户为oracle, uid500 gid 501

 

格式约定:

命令显示过程   文字说明  特别注意

 

NFS挂载问题一: Client端挂载后无权限写入

一、server端配置:

[root@db-0415 ~]# useradd  -u 501 -g 500 oracle   #新建用户指定gid uid

[root@db-0415 tmp]# tail -1 /etc/passwd #确认新建用户是否符合要求

oracle:x:501:500::/home/oracle:/bin/bash

[root@db-0415 ~]# vim /etc/exports    #编辑nfs主配置文件,读写权限,所有用户映射为指定用指定匿名用户映射的gid uid.                 

/opt/tmp  10.0.0.0/16 (rw,sync,all_squash.anonuid=501,anongid=500)

[root@db-0415 ~]# exportfs  -rv     #重新加载NFS共享配置

exportfs: No options for /opt/tmp 10.0.0.0/16: suggest 10.0.0.0/16(sync) to avoid warning

exportfs: No host name given with /opt/tmp (rw,sync,all_squash,anonuid=501,anongid=500), suggest *(rw,sync,all_squash,anonuid=501,anongid=500) to avoid warning

exporting 10.0.0.0/16:/opt/tmp

exporting *:/opt/tmp

[root@db-0415 ~]# showmount  127.0.0.1  #本地查看NFS共享列表,报错

mount clntudp_create: RPC: Port mapper failure - RPC: Unable to receive

[root@db-0415 ~]# /etc/init.d/portmap start  #启动portmap

Starting portmap:                                          [  OK  ]

[root@db-0415 ~]# /etc/init.d/nfs start     #启动nfs服务,这个时候还有报错

Starting NFS services:  exportfs: No options for /opt/tmp 10.0.0.0/16: suggest 10.0.0.0/16(sync) to avoid warning

exportfs: No host name given with /opt/tmp (rw,sync,all_squash,anonuid=501,anongid=500), suggest *(rw,sync,all_squash,anonuid=501,anongid=500) to avoid warning

                                                           [  OK  ]

Starting NFS quotas:                                       [ OK  ]

Starting NFS daemon:                                      [  OK  ]

Starting NFS mountd:                                      [  OK  ]

Starting RPC idmapd:                                       [  OK  ]

[root@db-0415 ~]# chkconfig  portmap on    #配置nfs两个必须服务随机启动

[root@db-0415 ~]# chkconfig  nfs on      

[root@db-0415 ~]# showmount -e  127.0.0.1 #server端本地再次查看共享列表,似乎正常没有问题。

Export list for 127.0.0.1:

/opt/tmp (everyone)

二、Client 挂载测试无法写入:

[root@NFSclient1 ~]# mount -t  nfs 10.0.4.15:/opt/tmp /opt/oracle/tmp/ #挂载共享目录

[root@NFSclient1 ~]# cd /opt/oracle/tmp/

[root@NFSclient1 tmp]# touch tt   #测试写入报权限拒绝

touch: cannot touch `tt': Permission denied

三、开始排查NFS权限相关设置问题:

首先检查clientgid uid 与server端对应正常。

[root@NFSclient1 tmp]# su - oracle  

-bash-3.2$ id

uid=501(oracle) gid=500(oinstall) groups=500(oinstall)

-bash-3.2$ exit

logout

第二、检查client本地文件系统针对目录/opt/oracle/tmp/读写权限,并使用oracle用户写入文件测试。

[root@NFSclient1 oracle]# ll /opt/oracle/tmp/ -d  #查看tmp目录权限

drwxr-xr-x  0 abc4ftp oinstall 0 Mar 20 16:53 /opt/oracle/tmp/

[root@NFSclient1 oracle]# su - oracle

-bash-3.2$ cd /opt/oracle/  

-bash-3.2$ touch 1

-bash-3.2$ rm 1             #测试权限正常

#可是挂载以后还是报权限错误:

[root@NFSclient1 ~]#  mount -t  nfs  10.0.4.15:/opt/tmp  /opt/oracle/tmp/

[root@NFSclient1 ~]# cd /opt/oracle/tmp/

[root@NFSclient1 tmp]# touch tt

touch: cannot touch `tt': Permission denied

[root@NFSclient1 tmp]# ll -d

drwxr-xr-x  2 oracle oinstall 4096 Mar 20 17:35 .

[root@NFSclient1 tmp]# ls

tt

[root@NFSclient1 tmp]# ll

total 0

-rw-r--r--  1 oracle oinstall 0 Mar 20 17:36 tt

[root@NFSclient1 tmp]# rm tt

rm: remove write-protected regular empty file `tt'? y

rm: cannot remove `tt': Permission denied

第三、确认NFS Serverrw权限设置,因为一直记得设置的rw权限,总觉着这没有问题。但其他方面都没有问题,配置文件参数较多需要细心再看看。

[root@db-0415 ~]# cat /etc/exports

/opt/tmp  10.0.0.0/16 (rw,sync,all_squash,anonuid=501,anongid=500)

[root@db-0415 ~]# cat /var/lib/nfs/etab  #主要记录NFS共享目录的完整权限设置值。

/opt/tmp        *(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,all_squash,no_subtree_check,secure_locks,acl,mapping=identity,anonuid=501,anongid=500)

# 乍一看似乎两个文件内容没有问题,仔细对比之发现主配置文件ip段后多了一个空格“ 10.0.0.0/16 (rw”,这个应该就是问题所在。

第四、重新编辑配置文件exports :

 

[root@db-0415 ~]# vim /etc/exports

/opt/tmp  10.0.0.0(rw,sync,all_squash,anonuid=501,anongid=500)

[root@db-0415 ~]# exportfs  -rv #重新加载NFS配置,输出已无报错。

exporting 10.0.0.0:/opt/tmp

 

[root@db-0415 tmp]# cat /var/lib/nfs/etab  #再次确认,与上面的区别

/opt/tmp       10.0.0.0/16(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,all_squash,no_subtree_check,secure_locks,acl,mapping=identity,anonuid=501,anongid=500)

第五、Client再次挂载测试:

[root@NFSclient1 ~]# mount -t  nfs 10.0.4.15:/opt/tmp /opt/oracle/tmp/

[root@NFSclient1 ~]# cd /opt/oracle/tmp/

[root@NFSclient1 tmp]# touch tt

[root@NFSclient1 tmp]# ls

test  tt

[root@NFSclient1 tmp]# ll

total 4

-rwxrwxr-x  1 oracle oinstall 5 Mar 20 18:03 test

-rw-r--r--  1 oracle oinstall 0 Mar 21 10:16 tt

[root@NFSclient1 tmp]# rm -rf test   #杀鸡用牛刀,使用rm -f即可

[root@NFSclient1 tmp]# rm -rf tt     #杀鸡用牛刀,使用rm -f即可

 #权限测试符合要求,至此问题解决。但下面还有一些细节处理。 

[root@NFSclient1 tmp]# chkconfig --list portmap #检查客户端portmap是否随机启动

portmap         0:off   1:off   2:off   3:off   4:off   5:off   6:off

[root@NFSclient1 tmp]# chkconfig portmap on    #设置随机启动

[root@NFSclient1 tmp]# chkconfig --list portmap #确认设置正确

portmap         0:off   1:off   2:on    3:on    4:on    5:on    6:off

[root@NFSclient1 tmp]# umount  /opt/oracle/tmp/ #继续后面的测试,先卸载

 

四、设置NFS随机启动挂载:

方法一:

1、编辑fstab

[root@NFSclient1 tmp]# cd /etc

[root@NFSclient1 etc]# cp fstab fstab.bak$(date +%F)  #备份fstab文件

[root@NFSclient1 etc]# vim fstab              #编辑fstab加入以下内容

10.0.4.15:/opt/tmp on /opt/oracle/tmp type nfs (rw,bg,hard,nointr,rsize=32768,wsize=32768,tcp,nfsvers=3,timeo=600,actimeo=0,addr=10.0.4.15)  

2、确认修改内容

[root@NFSclient1 etc]# diff fstab fstab.bak2012-03-21  

10d9

< 10.0.4.15:/opt/tmp      /opt/oracle/tmp/        nfs    rw,bg,hard,nointr,rsize=32768,wsize=32768,tcp,vers=3,timeo=600,actimeo=0             0 0

3、挂载测试。

[root@NFSclient1 etc]# mount -a  #fstab文件挂载文件系统,同时也是对刚才编辑内容的检查,如果没有报错就证明一切正常。此步骤很关键,若配置有误,没及时检查发现问题,系统重启后可能无法正常进入系统。

[root@NFSclient1 etc]# mount  #再次确认挂载内容正常。

………………省略内容………………

10.0.4.15:/opt/tmp on /opt/oracle/tmp type nfs (rw,bg,hard,nointr,rsize=32768,wsize=32768,tcp,nfsvers=3,timeo=600,actimeo=0,addr=10.0.4.15)

#再次确认权限正常

[root@NFSclient1 etc]# cd /opt/oracle/tmp/

[root@NFSclient1 tmp]# touch test

[root@NFSclient1 tmp]# ll

total 0

-rw-r--r--  1 oracle oinstall 0 Mar 21 10:30 test

[root@NFSclient1 tmp]# rm test

rm: remove regular empty file `test'? y

方法二(生产中推荐的方式):

避免系统无法正常启动,推荐将挂载命令写入rc.local

echo ' /bin/mount  -t nfs -o rw,bg,hard,nointr,rsize=32768,wsize=32768,tcp,vers=3,timeo=600,actimeo=0 10.0.4.15:/opt/tmp /opt/oracle/tmp' >> /etc/rc.local

 

至此已经满足要求,NFS配置完毕。

问题一解决过程涉的知识点:

NFS Serverclient端的配置

1、修改NFS挂载匿名账户。

2NFS挂载权限问题分析解决过程。

3、设置NFS开机自动挂载。

4、创建指定uidgid用户

5NFS服务相关命令mountshowmontexportfschkconfig

6、记录NFS server完整权限的配置文件/var/lib/nfs/etab

 

挂载问题二: Client端挂载后一直不动要等很久才有错误输出,原因因为没有启动portmap服务。

[root@study ~]# mount -t  nfs 10.0.4.15:/opt/tmp /mnt 

mount.nfs: Input/output error

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

portmap is stopped

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

Starting portmap:                                          [  OK  ]

[root@study ~]# mount -t  nfs 10.0.4.15:/opt/tmp /mnt

[root@study ~]# chkconfig portmap on

问题二结论:

NFS client 必须要启用portmap服务

NFS server 必须要先启动portmap服务然后启用nfs服务。

注意设置随机启动。

 

 

总结:

NFS权限需要注意三个条件:

1、用户账户的UID GID及对应用户名组名。

2NFS服务器端主配置文件/etc/exports允许读写权限。

3、文件系统需要具有读写的权限,特别说明这个权限不是以用户名组名为根据,了解文件系统的同学应该知道,这个权限是比对uidgid


老男孩 点评:

 注意:
1、杀鸡不用牛刀,这个要注意!
[root@NFSclient1 tmp]# rm -rf test
[root@NFSclient1 tmp]# rm -rf tt  
2、另外,nfs放fstab里不是很妥。
老男孩 点评!http://oldboy.blog.51cto.com 


本文出自 “Dreamway的linux博客” 博客,请务必保留此出处http://blog.sina.com.cn/s/blog_506ed9e6010113z2.html 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值