nfs
1、服务端配置
1. master 节点安装 nfs
yum install -y nfs-utils
//apt-get install nfs-kernel-server
//systemctl status nfs-kernel-server
//systemctl restart nfs-kernel-server
//systemctl enable nfs-kernel-server
2. 创建 nfs 目录
mkdir -p /data/nfsdata
3. 编辑 export 文件
vim /etc/exports
/data/nfsdata *(rw,sync,no_wdelay,no_root_squash)
/data/nfsdata 18.11.1.0/24(rw,sync,no_wdelay,no_root_squash) 18.11.2.0/24(rw,sync,no_wdelay,no_root_squash)
#选项说明
ro 共享目录只读;
rw 共享目录可读可写;
all_squash 所有访问用户都映射为匿名用户或用户组;
no_all_squash(默认) 访问用户先与本机用户匹配,匹配失败后再映射为匿名用户或用户组;
root_squash(默认) 将来访的root用户映射为匿名用户或用户组;
no_root_squash 来访的root用户保持root帐号权限;
anonuid=<UID> 指定匿名访问用户的本地用户UID,默认为nfsnobody(65534);
anongid=<GID> 指定匿名访问用户的本地用户组GID,默认为nfsnobody(65534);
secure(默认) 限制客户端只能从小于1024的tcp/ip端口连接服务器;
insecure 允许客户端从大于1024的tcp/ip端口连接服务器;
sync 将数据同步写入内存缓冲区与磁盘中,效率低,但可以保证数据的一致性;
async 将数据先保存在内存缓冲区中,必要时才写入磁盘;
wdelay(默认) 检查是否有相关的写操作,如果有则将这些写操作一起执行,这样可以提高效率;
no_wdelay 若有写操作则立即执行,应与sync配合使用;
subtree_check(默认) 若输出目录是一个子目录,则nfs服务器将检查其父目录的权限;
no_subtree_check 即使输出目录是一个子目录,nfs服务器也不检查其父目录的权限,这样可以提高效率;
4. 修改配置启动文件
cat > /etc/systemd/system/sockets.target.wants/rpcbind.socket << EOF
[Unit]
Description=RPCbind Server Activation Socket
[Socket]
ListenStream=/var/run/rpcbind.sock
ListenStream=0.0.0.0:111
ListenDatagram=0.0.0.0:111
[Install]
WantedBy=sockets.target
EOF
5. 配置生效
# 不用重启 nfs 服务,配置文件就会生效
exportfs -arv
6. 查看内核支持的文件系统
cat /proc/filesystems |grep nfsd
rpcinfo -p
systemctl status rpcbind.service
7. 启动 rpcbind、nfs 服务
systemctl status rpcbind
systemctl restart rpcbind
systemctl enable rpcbind
systemctl status nfs
systemctl restart nfs
systemctl enable nfs
8. showmount 测试
# 查询本机 nfs 共享目录情况
[root@gz0zTI ~]# showmount -e localhost
Export list for 127.0.0.1:
/data/nfsdata *
# 查询本机共享目录连接情况
showmount -a localhost
2、客户端配置
1. agent 节点安装 nfs
yum install -y nfs-utils
2. mount 挂载
mount -t nfs 18.10.84.36:/data/nfsdata /agent/data -osoft,timeo=5,retrans=5,retry=1,intr,vers=3
// 设备忙强制卸载
umount -l
3、nfs 常见故障排除
1. The rpcbind failure error
现象:
nfs mount: server1:: RPC: Rpcbind failure
RPC: Timed Out
nfs mount: retrying: /mntpoint
原因:
第一,可能因为客户机的 hosts 文件中存在错误的 ip 地址、主机名或节点名组合
第二,服务器因为过载而暂时停止服务
2. The server not responding error
现象:
NFS server server2 not responding, still trying
原因:
第一,网络不通,用 ping 命令检测一下
第二,服务器关机
3. The NFS client fails a reboot error
现象:
启动客户机后停住了,不断显示如下提示信息:
Setting default interface for multicast: add net 224.0.0.0: gateway:
client_node_name.
原因:
在 etc/vfstab 的 mount 选项中使用了 fg 而又无法成功 mount 服务器上的资源,改成 bg 或将该行注释掉,直到服务器可用为止
4. The service not responding error
现象:
nfs mount: dbserver: NFS: Service not responding
nfs mount: retrying: /mntpoint
原因:
第一,当前级别不是级别 3,用 who –r 查看,用 init 切换
第二,NFS Server 守护进程不存在,用 ps –ef | grep nfs 检查,用 /etc/init.d/nfs.server start 启动
5. The program not registered error
现象:
nfs mount: dbserver: RPC: Program not registered
nfs mount: retrying: /mntpoint
原因:
第一,当前级别不是级别3
第二,mountd 守护进程没有启动,用 /etc/init.d/nfs.server 脚本启动 NFS 守护进程
第三,看 /etc/dfs/dfstab 中的条目是否正常
6. The stale file handle error
现象:
stale NFS file handle
原因:
服务器上的共享资源移动位置了,在客户端使用 umount 和 mount 重新挂接就可以了
7. The unknown host error
现象:
nfs mount: sserver1:: RPC: Unknown host
原因:
hosts 文件中的内容不正确
8. The mount point error
现象:
mount: mount-point /DS9 does not exist.
原因:
该挂接点在客户机上不存在,注意检查命令行或 /etc/vfstab 文件中相关条目的拼写
9. The no such file error
现象:
No such file or directory.
原因:
该挂接点在服务器上不存在,注意检查命令行或 /etc/vfstab 文件中相关条目的拼写
10. No route to host
现象:
[root@msa30 sysconfig]# mount 10.10.11.211:/opt/b2b-data/xmldb /b2b-web1/b2b-data/xmldb -t nfs -o rw
mount: mount to NFS server '10.10.11.211' failed: System Error: No route to host.
原因:
防火墙被打开,关闭防火墙
11. Not owner
现象:
[root@msa30:/founder/shell]# mount -F nfs -o rw 10.10.2.3:/mnt/b2b/b2b-data/resinfo2 /data/b2b-data/resinfo2
nfs mount: mount: /data/b2b-data/resinfo2: Not owner
原因:
这是 Solaris 10 版本挂载较低版本 nfs 时报的错误
解决:
需要用 -o vers=3 参数
示例:
[root@msa30:/founder/shell]# mount -F nfs -o vers=3 10.10.2.3:/mnt/b2b/b2b-data/resinfo2 /data/b2b-data/resinfo2
12. RPC: Program not registered & retrying
现象:
nfs mount: 10.10.2.3: : RPC: Program not registered
nfs mount: retrying: /data/b2b-data/resinfo2
原因:
没有启动 NFS 共享端服务
解决:需要重新启动 share 端的 NFS 服务,
Linux:
mount: RPC: Program not registered
service nfs restart
13. can't contact portmapper: RPC: Remote system error - Connection refused
现象:
exportfs -a
can't contact portmapper: RPC: Remote system error - Connection refused
原因:
出现这个错误信息是由于 SEVER 端的 PORTMAP 没有启动
解决:
service portmap start
service pcmcia start
14. NFSD 没有启动起来
首先要确认 NFS 输出列表存在,否则 nfsd 不会启动。可用 exportfs 命令来检查,如果 exportfs 命令没有结果返回或返回不正确,则需要检查 /etc/exports 文件
15. mountd 进程没有启动
mountd 进程是一个远程过程调用 (RPC) ,其作用是对客户端要求安装(mount)文件系统的申请作出响应。mountd 进程通过查找 /etc/xtab 文件来获知哪些文件系统可以被远程客户端使用。另外,通过 mountd 进程,用户可以知道目前有哪些文件系统已被远程文件系统装配,并得知远程客户端的列表。查看 mountd 是否正常启动起来可以使用命令 rpcinfo 进行查看,在正常情况下在输出的列表中应该象这样的行:
100005 1 udp 1039 mountd
100005 1 tcp 1113 mountd
100005 2 udp 1039 mountd
100005 2 tcp 1113 mountd
100005 3 udp 1039 mountd
100005 3 tcp 1113 mountd
如果没有起来的话可以检查是否安装了 PORTMAP 组件
rpm -qa|grep portmap
16. fs type nfs no supported by kernel
kernel 不支持 nfs 文件系统,重新编译一下 KERNEL 就可以解决
17. mount: localhost:/home/test failed, reason given by server: Permission denied
这个提示是当 client 要 mount nfs server 时可能出现的提示,意思是说本机没有权限去 mount nfs server 上的目录。解决方法当然是去修改 NFS SERVER 咯
还有就是被防火墙阻挡,这个原因很多人都忽视了,在有严格要求的网络环境中,我们一般会关闭linux上的所有端口,当需要使用哪个端口的时候才会去打开。而NFS默认是使用111端口,所以我们先要检测是否打开了这个端口,另外也要检查 TCP_Wrappers 的设定
参考文献:
固定 NFS 启动端口便于 iptables 设置
http://www.haiyun.me/archives/centos-nfs-port.html
NFS 挂载及写入故障
http://www.cnblogs.com/linuxzkq/p/NFS.html
nfs 只能挂载为 nobody 的解决方法
http://www.361way.com/nfs-mount-nobody/2616.html
生产中 NFS 案例记录---写入权限解决过程
http://blog.sina.com.cn/s/blog_506ed9e6010113z2.html
------------------------------- THE END -------------------------------