前提條件,確保兩個ip可以正常通訊
確認服務端是否安裝nfs-utils和rpcbind
[root@localhost /]# rpm -qa|grep “nfs”
nfs4-acl-tools-0.3.3-17.el7.x86_64
libnfsidmap-0.25-19.el7.x86_64
nfs-utils-1.3.0-0.61.el7.x86_64
[root@localhost /]# rpm -qa|grep “rpc”
xmlrpc-c-client-1.32.5-1905.svn2451.el7.x86_64
libtirpc-0.2.4-0.10.el7.x86_64
rpcbind-0.2.0-47.el7.x86_64
xmlrpc-c-1.32.5-1905.svn2451.el7.x86_64
mkdir /data/sharestore 建立共享目錄
chmod -Rf 777 /data/sharestore 確保其他使用者對該目錄具備讀寫許可權(該步驟可以不執行)
服務端配置
cat /etc/exports
/data/sharestore *(insecure,rw,no_root_squash,no_all_squash,async)
exports引數相關可以參考:https://blog.csdn.net/qq_36357820/article/details/78488077
cat /etc/sysconfig/nfs|grep -v `#`
LOCKD_TCPPORT=32803
LOCKD_UDPPORT=32769
RPCNFSDARGS=”-N 4″
MOUNTD_PORT=10892
STATD_PORT=10662
STATD_OUTGOING_PORT=12020
GSS_USE_PROXY=”yes”
systemctl restart rpcbind
systemctl restart nfs-server
systemctl enable rpcbind
systemctl enable nfs-server
exportfs -r 使配置檔案立即生效
客戶端配置:
確認是否安裝:nfs-common 該包提供showmount等功能
執行:dpkg-query -l nfs-common
出現以下資訊說明已安裝
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==================================================-==============================-==============================-=========================================================================================================
ii nfs-common 1:1.2.8-6ubuntu1.2 amd64 NFS support files common to client and server
mkdir /nfsfile 建立掛載目錄
chmod -Rf 777 /nfsfile(具備讀寫許可權即可,可以不給777)
showmount -e 服務端ip(如果出現服務端共享的目錄資訊說明目錄共享成功)
rpcinfo -p 服務端ip地址 —檢視服務端rpc程式(該命令不指定ip地址可以用於獲取本地rpc程式)
program vers proto port service
100000 4 tcp 111 portmapper
100000 3 tcp 111 portmapper
100000 2 tcp 111 portmapper
100000 4 udp 111 portmapper
100000 3 udp 111 portmapper
100000 2 udp 111 portmapper
100005 1 udp 20048 mountd
100005 1 tcp 20048 mountd
100005 2 udp 20048 mountd
100005 2 tcp 20048 mountd
100005 3 udp 20048 mountd
100005 3 tcp 20048 mountd
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100227 3 tcp 2049 nfs_acl
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100227 3 udp 2049 nfs_acl
100021 1 udp 31206 nlockmgr
100021 3 udp 31206 nlockmgr
100021 4 udp 31206 nlockmgr
100021 1 tcp 31241 nlockmgr
100021 3 tcp 31241 nlockmgr
100021 4 tcp 31241 nlockmgr
客戶端iptables配置策略如下(需要開放的埠請參考以上查詢到的rpc程式資訊)
iptables -I INPUT -p tcp -s x.x.x.x –dport 111 -j ACCEPT(x.x.x.x為服務端ip地址)
iptables -I INPUT -p udp -s x.x.x.x –dport 111 -j ACCEPT
iptables -I INPUT -p tcp -s x.x.x.x –dport 2049 -j ACCEPT
iptables -I INPUT -p udp -s x.x.x.x –dport 2049 -j ACCEPT
iptables -I INPUT -p tcp -s x.x.x.x –dport 20048 -j ACCEPT
iptables -I INPUT -p udp -s x.x.x.x –dport 20048 -j ACCEPT
iptables -I INPUT -p tcp -s x.x.x.x –dport 31206 -j ACCEPT
iptables -I INPUT -p udp -s x.x.x.x –dport 31206 -j ACCEPT
掛載命令:mount -t nfs 服務端ip地址:/home/nfs /home/nfs
執行df -h查詢目錄是否掛載成功
如涉及系統升級導致掛載失敗問題可以參考如下:
https://blog.csdn.net/qq_30951423/article/details/85890581
Ubuntu 18.04 nfs 預設為協議3和協議4,但是預設啟動的是協議2的形式
如:/data/sharestore *(insecure,rw,no_root_squash,no_all_squash,async)
若想要求 nfs 支援協議2,就在/etc/default/nfs-kernel-server末尾加一句:
RPCNFSDOPTS=”–nfs-version 2,3,4 –debug –syslog”
vim /etc/default/nfs-kernel-server
RPCNFSDOPTS=”–nfs-version 2,3,4 –debug –syslog”