CentOS7.6配置NFS服务

系统环境:CentOS Linux release 7.6.1810 (Core)
关闭防火墙、selinux
一、安装
nfs客户端和服务端都安装nfs-utils包,同时自动安装rpcbind。安装后会创建nfsnobody用户和组,uid和gid都是65534。
yum -y install nfs-utils

vim /etc/exports
/data/nfs/upload 192.168.0.0/16(rw,no_root_squash,no_all_squash,sync)
/data/nfs/text 192.168.0.0/16(rw,no_root_squash,no_all_squash,sync)
/data/nfs/staticac 192.168.0.0/16(rw,no_root_squash,no_all_squash,sync)
/data/ccs 192.168.0.0/16(rw,no_root_squash,no_all_squash,sync)
/data/ccss1 10.0.0.0/8(rw,no_root_squash,no_all_squash,sync)
/data/ccss1 192.168.16.0/20(rw,no_root_squash,no_all_squash,sync)
二、启动服务
systemctl start rpcbind.service
systemctl enable rpcbind.servic
systemctl start nfs.service
systemctl enable nfs.service
三、Linux客户端挂载

1、直接挂载
# mount -t nfs nfs.st.local:/var/nfs /mnt
例:

mount -o vers=3 192.168.16.1:/data/nfs/upload /home/www/htdocs/Html/upload

也可将挂载配置写入fstab文件中,与普通磁盘挂载一样,挂载时同样可以指定权限,只是类型为nfs。

2、autofs挂载
# yum -y install autofs
# vi /etc/auto.master #添加一行
/- /etc/auto.mount # vi /etc/auto.mount #添加一行
/mnt -fstype=nfs,rw nfs.st.local:/var/nfs #启动服务
# systemctl start autofs
# systemctl enable autofs

查看客户端挂载情况:
showmount --all
四、故障解决
1、nfs只能挂载为nobody
同时修改服务端、客户端/etc/idmapd.conf中的Domain为一样的值,随后重启rpcidmapd服务,或重启所有服务
2、客户端无法卸载nfs目录
umount.nfs4: /var/nfs: device is busy
执行fuser -km /var/nfs/,然后再执行umount
fuser -cu /data/www/web_online/htdocs/Html/text
fuser -ck /data/www/web_online/htdocs/Html/text

这个是查哪个进程在操作这个目录,如果有正在读写这个目录的进程,是无法umount的。只有kill了,才能umount

[root@localhost /]# umount /data/
umount.nfs: /data: device is busy

通过这条命令查看:
[root@localhost /]# fuser -m -v /data/
                     用户     进程号 权限   命令
/data/:              root       2798 ..c.. bash
                     root       2996 ..c.. su
如上所示,有两个进程占用了,将其kill掉,再重新取消挂载。
[root@localhost /]# kill -9 2798
[root@localhost /]# kill -9 2996
[root@localhost /]# umount /data/
[root@localhost /]#
成功!

centos查看nfs版本

服务器端使用:

nfsstat -s

客户端使用:

nfsstat -c

 

参考:https://www.cnblogs.com/st-jun/p/7742560.html

打赏

Share This!

在线客服
我们将24小时内回复。
2024-04-24 07:33:11
您好,有任何疑问请与我们联系!
您的工单我们已经收到,我们将会尽快跟您联系!
取消

选择聊天工具: