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

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


 

NFS 配置要求:

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

2、  Oracle 端目录文件所属用户为oracleuid500 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 map per 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

[root@NFSclient1 tmp]# rm -rf tt  

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

[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

至此已经满足要求, 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为准的。


本文转自pandazhai 51CTO博客,原文链接:http://blog.51cto.com/dreamway/1045581

相关文章
|
Oracle 关系型数据库 Unix
|
1月前
|
Linux
Linux安装NFS挂载NFS卸载客户端服务端都有
Linux安装NFS挂载NFS卸载客户端服务端都有
41 0
|
1月前
|
Ubuntu 网络协议 Unix
【Linux】新唐NUC977挂载NFS实现网络文件传输
【Linux】新唐NUC977挂载NFS实现网络文件传输
|
2月前
|
Linux Shell Windows
通过Linux挂载Windows端NFS服务实现板端Linux传输文件到PC
通过Linux挂载Windows端NFS服务实现板端Linux传输文件到PC