Linux - 在 Rocky Linux 9.4 上安装和配置NFS

NFS的安装与配置

NFS服务端安装与配置

# 确认系统版本和安装NFS
[root@node100 ~]# uname -a
Linux node100 5.14.0-427.31.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Aug 14 16:15:25 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
[root@node100 ~]# 
[root@node100 ~]# cat /etc/system-release
Rocky Linux release 9.4 (Blue Onyx)
[root@node100 ~]# 
[root@node100 ~]# dnf install nfs-utils -y
......
......
Installed:
  gssproxy-0.8.4-6.el9.x86_64       keyutils-1.6.3-1.el9.x86_64 libev-4.33-5.el9.x86_64               libnfsidmap-1:2.5.4-26.el9_4.x86_64 libverto-libev-0.3.2-3.el9.x86_64
  nfs-utils-1:2.5.4-26.el9_4.x86_64 rpcbind-1.2.6-7.el9.x86_64  sssd-nfs-idmap-2.9.4-6.el9_4.1.x86_64

Complete!
[root@node100 ~]# 
[root@node100 ~]# showmount --version
showmount for 2.5.4
[root@node100 ~]# 
[root@node100 ~]# nfsstat --version
nfsstat: 2.5.4
[root@node100 ~]# 

# 创建目录、添加NFS配置并加载
[root@node100 /]# mkdir -p /nfsdir && chmod -R 777 /nfsdir
[root@node100 /]# 
[root@node100 /]# vim /etc/exports
[root@node100 ~]# cat /etc/exports
/nfsdir *(rw,sync,no_subtree_check,no_root_squash)
[root@node100 ~]# 
[root@node100 ~]# exportfs -arv
exporting *:/nfsdir
[root@node100 ~]# 

# 设为自启动并启动服务
[root@node100 ~]# systemctl enable --now nfs-server
Created symlink /etc/systemd/system/multi-user.target.wants/nfs-server.service → /usr/lib/systemd/system/nfs-server.service.
[root@node100 ~]# 
[root@node100 ~]# systemctl status nfs-server
● nfs-server.service - NFS server and services
     Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; preset: disabled)
    Drop-In: /run/systemd/generator/nfs-server.service.d
             └─order-with-mounts.conf
     Active: active (exited) since Thu 2024-10-10 20:06:45 CST; 42s ago
       Docs: man:rpc.nfsd(8)
             man:exportfs(8)
    Process: 2870 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
    Process: 2871 ExecStart=/usr/sbin/rpc.nfsd (code=exited, status=0/SUCCESS)
    Process: 2881 ExecStart=/bin/sh -c if systemctl -q is-active gssproxy; then systemctl reload gssproxy ; fi (code=exited, status=0/SUCCESS)
   Main PID: 2881 (code=exited, status=0/SUCCESS)
        CPU: 20ms

Oct 10 20:06:45 node100 systemd[1]: Starting NFS server and services...
Oct 10 20:06:45 node100 systemd[1]: Finished NFS server and services.
[root@node100 ~]#  

# 查询NFS服务器信息
[root@node100 ~]# showmount -a
All mount points on node100:
[root@node100 ~]# showmount -e
Export list for node100:
/nfsdir *
[root@node100 ~]# showmount -e 192.168.16.100
Export list for 192.168.16.100:
/nfsdir *
[root@node100 ~]#

# 查看服务端协议版本
[root@node100 ~]# nfsstat -s |grep nfs
Server nfs v4:
Server nfs v4 operations:
[root@node100 ~]#

# 查看RPC服务信息
[root@node100 ~]#  rpcinfo |grep nfs
    100003    3    tcp       0.0.0.0.8.1            nfs        superuser
    100003    4    tcp       0.0.0.0.8.1            nfs        superuser
    100227    3    tcp       0.0.0.0.8.1            nfs_acl    superuser
    100003    3    tcp6      ::.8.1                 nfs        superuser
    100003    4    tcp6      ::.8.1                 nfs        superuser
    100227    3    tcp6      ::.8.1                 nfs_acl    superuser
[root@node100 ~]# 

NFS客户端安装与配置

[root@k8s-node1 ~]# dnf install nfs-utils -y
[root@k8s-node1 ~]# 
[root@k8s-node1 ~]# nfsstat --version
nfsstat: 2.5.4
[root@k8s-node1 ~]# showmount --version
showmount for 2.5.4
[root@k8s-node1 ~]# 
[root@k8s-node1 ~]# mkdir -p /nfsdir && chmod -R 777 /nfsdir
[root@k8s-node1 ~]# 
[root@k8s-node1 ~]# showmount -e 192.168.16.100
Export list for 192.168.16.100:
/nfsdir *
[root@k8s-node1 ~]#
[root@k8s-node1 ~]# nfsstat -c |grep nfs
Client nfs v4:
[root@k8s-node1 ~]#  
[root@k8s-node1 ~]# vim /etc/fstab
[root@k8s-node1 ~]# cat /etc/fstab |grep nfsdir
192.168.16.100:/nfsdir /nfsdir                                   nfs     defaults         0 0
[root@k8s-node1 ~]#  
[root@k8s-node1 ~]# systemctl daemon-reload
[root@k8s-node1 ~]# mount -a
[root@k8s-node1 ~]# 
[root@k8s-node1 ~]# df -h |grep nfsdir
192.168.16.100:/nfsdir   30G   17G   14G  56% /nfsdir
[root@k8s-node1 ~]# 

临时挂载命令: mount -t nfs4 -o rw,nfsvers=4 192.168.16.100:/nfsdir /nfsdir

问题处理

问题现象: 报错信息“clnt_create: RPC: Unable to receive”和“mount.nfs: Protocol not available”

[root@k8s-node2 ~]# cat /etc/fstab  |grep nfsdir
192.168.16.100:/nfsdir /nfsdir                                    nfs     defaults        0 0
[root@k8s-node2 ~]# 
[root@k8s-node2 ~]# showmount -e 192.168.16.100
clnt_create: RPC: Unable to receive
[root@k8s-node2 ~]# 
[root@k8s-node2 ~]# mount -a
mount.nfs: Protocol not available
[root@k8s-node2 ~]#

问题分析与处理:错误信息提示协议不可用

# 查看客户端nfs协议版本为v4
[root@k8s-node1 ~]# nfsstat -c |grep nfs
Client nfs v4:
[root@k8s-node1 ~]# 

# 查看服务端nfs协议版本,没有得到版本信息,认为问题出在服务端
[root@node100 ~]# nfsstat -v |grep nfc
[root@node100 ~]# 
[root@node100 ~]# nfsstat -s |grep nfc
[root@node100 ~]# 

# 检查服务端状态和日志,未发现异常信息
systemctl status nfs-server
journalctl -u nfs-server
grep nfs-server /var/log/messages

# 检查/etc/exports的配置,发现格式错误,更新并加载
[root@node100 /]# vim /etc/exports
[root@node100 ~]# cat /etc/exports
/nfsdir *(rw,sync,no_subtree_check,no_root_squash)
[root@node100 ~]# 
[root@node100 ~]# exportfs -arv
exporting *:/nfsdir

# 查看nfs状态已恢复正常
[root@node100 ~]# showmount -e 192.168.16.100
Export list for 192.168.16.100:
/nfsdir *
[root@node100 ~]#
[root@node100 ~]# nfsstat -s |grep nfs
Server nfs v4:
Server nfs v4 operations:
[root@node100 ~]#

# 如果仍未恢复正常,重启整个NFS服务器,再查看状态
“重启治百病”

参考信息

posted @ 2016-12-28 17:57  Anliven  阅读(307)  评论(0编辑  收藏  举报