一、NFS服務簡介
NFS全稱network file system 網絡檔案系統,基于核心的檔案系統,由sun公司開發,通過使用NFS,使用者和程式可以像通路本地檔案一樣通路遠端系統上的檔案,它基于rpc實作(rpc是remote procedure call protocol 遠端過程調用)。RPC采用C/S模式,客戶機請求程式調用程序發送一個有程序參數的調用資訊到服務程序,然後等待應答資訊。在伺服器端,程序儲存睡眠狀态直到調用資訊到達為止。當一個調用資訊到達,伺服器獲得程序參數,計算結果,發送答複資訊,然後等待下一個調用資訊,最後,用戶端調用程序接收答複資訊,獲得程序結果,然後調用執行繼續進行。
NFS優勢:節省本地存儲空間,将常用的資料,如home目錄存放在NFS伺服器上且可以通過網絡通路,本地終端将可減少自身存儲空間的使用。
二、NFS工作原理

如上圖所示,使用者需要通路本地的資源,可通過本地檔案系統通路,本地磁盤的資源,如果使用者通路NFS伺服器上的資源,則使用者需要通過rpc服務,通過網絡去通路NFS伺服器,當使用者的通路請求到達NFS伺服器時,首先到達NFS伺服器的tcp/ip協定棧,然後通過詢問NFS伺服器上的rpc服務,rpc服務在NFS伺服器上的作用是當NFS啟動時,NFS服務所監聽的端口有很多且是随機,不固定,rpc的作用就是記錄這些端口,如果有人來通路NFS服務了,它就把NFS的端口資訊告訴用戶端,然後用戶端通過rpc給定端口資訊,進而實作通路NFS服務。NFS服務收到用戶端的請求,然後通過本地檔案系統,通路對應本地磁盤上的檔案,進而實作了完成用戶端的通路和響應。
三、NFS服務實作
1、軟體包資訊
[root@test ~]# yum info nfs-utils
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
可安裝的軟體包
名稱 :nfs-utils
架構 :x86_64
時期 :1
版本 :1.3.0
釋出 :0.65.el7
大小 :412 k
源 :base/7/x86_64
簡介 : NFS utilities and supporting clients and daemons for the kernel NFS server
網址 :http://sourceforge.net/projects/nfs
協定 : MIT and GPLv2 and GPLv2+ and BSD
描述 : The nfs-utils package provides a daemon for the kernel NFS server and
: related tools, which provides a much higher level of performance than the
: traditional Linux NFS server used by most users.
:
: This package also contains the showmount program. Showmount queries the
: mount daemon on a remote host for information about the NFS (Network File
: System) server on the remote host. For example, showmount can display the
: clients which are mounted on that host.
:
: This package also contains the mount.nfs and umount.nfs program.
[root@test ~]#
說明:NFS它是檔案系統,在核心已經支援,且已經有它的驅動,我們裝包的原因是,用軟體去管理NFS檔案系統,因為使用者是沒有辦法直接和核心互動的。從上面的資訊也可了解到nfs-utils的介紹它是NFS實用程式和支援NFS核心伺服器的客戶機和守護程序。
2、安裝nfs-utils
[root@test ~]# yum install nfs-utils
……省略部分資訊
依賴關系解決
============================================================================================================
Package 架構 版本 源 大小
============================================================================================================
正在安裝:
nfs-utils x86_64 1:1.3.0-0.65.el7 base 412 k
為依賴而安裝:
gssproxy x86_64 0.7.0-26.el7 base 110 k
keyutils x86_64 1.5.8-3.el7 base 54 k
libbasicobjects x86_64 0.1.1-32.el7 base 26 k
libcollection x86_64 0.7.0-32.el7 base 42 k
libini_config x86_64 1.3.1-32.el7 base 64 k
libnfsidmap x86_64 0.25-19.el7 base 50 k
libpath_utils x86_64 0.2.1-32.el7 base 28 k
libref_array x86_64 0.1.5-32.el7 base 27 k
libtirpc x86_64 0.2.4-0.16.el7 base 89 k
libverto-tevent x86_64 0.2.5-4.el7 base 9.0 k
quota x86_64 1:4.01-19.el7 base 179 k
quota-nls noarch 1:4.01-19.el7 base 90 k
rpcbind x86_64 0.2.0-48.el7 base 60 k
tcp_wrappers x86_64 7.6-77.el7 base 78 k
事務概要
============================================================================================================
安裝 1 軟體包 (+14 依賴軟體包)
……省略部分資訊
說明:可以看到nfs-utils依賴這些包,其中rpcbind就是nfs啟動時所使用的端口它會記錄起來,一旦有用戶端通路,它就把nfs的端口資訊告訴給用戶端
3、寫配置檔案,讓其用戶端允許通路本地的資源
[root@test ~]# mkdir /nfsdir
[root@test ~]# cat >> /etc/exports << EOF
> /nfsdir 192.168.0.0/24(rw)
> EOF
[root@test ~]# cat /etc/exports
/nfsdir 192.168.0.0/24(rw)
[root@test ~]#
說明:nfs服務的配置檔案是/etc/exports 和/etc/exports.d/*.exports,以上定義了/nfsdir目錄允許192.168.0.0/24當使用者通路,相當與把/nfsdir給共享出來了
4、啟動服務
[root@test ~]# systemctl status rpcbind nfs-server
● rpcbind.service - RPC bind service
Loaded: loaded (/usr/lib/systemd/system/rpcbind.service; enabled; vendor preset: enabled)
Active: inactive (dead)
● nfs-server.service - NFS server and services
Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; disabled; vendor preset: disabled)
Active: inactive (dead)
[root@test ~]# systemctl start nfs-server
[root@test ~]# systemctl status rpcbind nfs-server
● rpcbind.service - RPC bind service
Loaded: loaded (/usr/lib/systemd/system/rpcbind.service; enabled; vendor preset: enabled)
Active: active (running) since 三 2020-01-29 23:52:08 CST; 2s ago
Process: 4754 ExecStart=/sbin/rpcbind -w $RPCBIND_ARGS (code=exited, status=0/SUCCESS)
Main PID: 4756 (rpcbind)
Tasks: 1
Memory: 1.1M
CGroup: /system.slice/rpcbind.service
└─4756 /sbin/rpcbind -w
1月 29 23:52:08 test systemd[1]: Starting RPC bind service...
1月 29 23:52:08 test systemd[1]: Started RPC bind service.
● nfs-server.service - NFS server and services
Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; disabled; vendor preset: disabled)
Active: active (exited) since 三 2020-01-29 23:52:08 CST; 1s ago
Process: 4787 ExecStartPost=/bin/sh -c if systemctl -q is-active gssproxy; then systemctl reload gssproxy ; fi (code=exited, status=0/SUCCESS)
Process: 4771 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)
Process: 4768 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
Main PID: 4771 (code=exited, status=0/SUCCESS)
Tasks: 0
Memory: 0B
CGroup: /system.slice/nfs-server.service
1月 29 23:52:08 test systemd[1]: Starting NFS server and services...
1月 29 23:52:08 test systemd[1]: Started NFS server and services.
[root@test ~]#
說明:可看到在rpcbind 服務沒有啟動的情況下,直接啟動nfs-server ,它會把rpcbind給一并啟動起來,因為nfs-server依賴rpcbind服務。這個是在centos7上是這樣的,centos7上有服務依賴解決,如果啟動服務所依賴的服務沒有啟動,它會激活所依賴的服務,然後啟動服務。在centos6上就沒有這樣的功能,在centos6上如果rpcbind沒有啟動起來,則nfs服務是啟動不了的。
5、在用戶端檢視共享目錄以及挂載nfs共享出來的目錄
[root@test-node1 ~]#showmount -e 192.168.0.99
Export list for 192.168.0.99:
/nfsdir 192.168.0.0/24
[root@test-node1 ~]#mount 192.168.0.99:/nfsdir /mnt
[root@test-node1 ~]#df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root
51475068 4746696 44106932 10% /
tmpfs 959580 0 959580 0% /dev/shm
/dev/sda1 487652 45302 416750 10% /boot
/dev/mapper/VolGroup-lv_home
251354900 69264 238510828 1% /home
192.168.0.99:/nfsdir 27560960 13935872 13625088 51% /mnt
[root@test-node1 ~]#
說明:可看到nfs伺服器共享出來的目錄在服務端是可以檢視得到的,這裡需要注意用戶端也需要安裝nfs-utils才可以用showmount指令來檢視共享目錄。nfs同ftp服務不一樣,ftp共享出來的目錄,我們是看不出來它在伺服器上的具體路徑,而nfs是可以看到的。
四、測試在客戶建立檔案寫入資料,看服務端的本地目錄的變化
[root@test-node1 ~]#cd /mnt
[root@test-node1 mnt]#ls
[root@test-node1 mnt]#touch clientfile
touch: cannot touch `clientfile': Permission denied
[root@test-node1 mnt]#
說明:預設我們配置的nfs是允許對寫,為什麼在用戶端沒法建立檔案呢?它告訴我們權限拒絕這到底是為什麼呢?我們在伺服器上用exportfs -v來檢視nfs加載的配置内容
[root@test ~]# exportfs -v
/nfsdir 192.168.0.0/24(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,root_squash,no_all_squash)
[root@test ~]#
說明:從上面的資訊可以看到我們雖然配置了允許192.168.0.0/24這個網段的所有主機對其/nfsdir有讀寫權限(rw),但是它還有預設配置了root_squash,這個權限表示用戶端root賬号權限在NFS伺服器上會壓榨,也就是說用戶端的root到NFS伺服器上就不是root權限了,那用戶端的root到nfs伺服器上是什麼權限呢?
[root@test ~]# chmod 777 /nfsdir
[root@test ~]#
說明:把NFS共享出來的目錄修改成777權限,然後在用戶端在建立檔案看看建立的檔案的所有者群組就可以知道用戶端的root到NFS伺服器上是被映射成那個使用者了
[root@test-node1 ~]#cd /mnt
[root@test-node1 mnt]#ls
[root@test-node1 mnt]#touch rootfile
[root@test-node1 mnt]#ll
total 0
-rw-r--r-- 1 nfsnobody nfsnobody 0 Jan 30 00:21 rootfile
[root@test-node1 mnt]#
說明:可看到用戶端的root在共享目錄裡建立的檔案是nfsnobody的所有者群組,那麼我們隻需要在服務端把共享目錄的權限設定成nfsnobody這個使用者可讀寫權限,用戶端root就可在裡面建立檔案了。
[root@test ~]# chmod 755 /nfsdir
[root@test ~]# ll /nfsdir -d
drwxr-xr-x 2 root root 22 1月 30 00:21 /nfsdir
[root@test ~]# setfacl -m u:nfsnobody:rwx /nfsdir
[root@test ~]# getfacl /nfsdir
getfacl: Removing leading '/' from absolute path names
# file: nfsdir
# owner: root
# group: root
user::rwx
user:nfsnobody:rwx
group::r-x
mask::rwx
other::r-x
[root@test ~]#
說明:設定了/nfsdir這個共享目錄nfsnobody使用者有讀寫執行權限,那麼用戶端的root使用者在共享目錄建立檔案是否還有問題呢?
[root@test-node1 mnt]#pwd
/mnt
[root@test-node1 mnt]#touch rootfile2
[root@test-node1 mnt]#ll
total 0
-rw-r--r-- 1 nfsnobody nfsnobody 0 Jan 30 00:21 rootfile
-rw-r--r-- 1 nfsnobody nfsnobody 0 Jan 30 00:27 rootfile2
[root@test-node1 mnt]#
說明:可看到用戶端root使用者在共享目錄裡是可以正常的建立檔案的,那麼用戶端普通使用者是否也可以呢?試一試
[root@test-node1 mnt]#su - qiuhom
[qiuhom@test-node1 ~]$cd /mnt
[qiuhom@test-node1 mnt]$ll
total 0
-rw-r--r-- 1 nfsnobody nfsnobody 0 Jan 30 00:21 rootfile
-rw-r--r-- 1 nfsnobody nfsnobody 0 Jan 30 00:27 rootfile2
[qiuhom@test-node1 mnt]$touch qiuhomfile
touch: cannot touch `qiuhomfile': Permission denied
[qiuhom@test-node1 mnt]$
說明:用戶端的普通使用者為什麼就不能在共享目錄裡建立檔案呢?我們在來看看服務端的配置
[root@test ~]# exportfs -v
/nfsdir 192.168.0.0/24(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,root_squash,no_all_squash)
[root@test ~]#
說明:雖然服務端允許用戶端的root映射成nfsnobody,但是後面又設定了no_all_squash,這個權限表示所有的使用者不壓榨,也就是說root使用者壓榨,其他使用者不壓榨,也就說除root使用者,其他使用者都不映射成nfsnobody使用者。那麼其他使用者在NFS服務端映射成那個使用者了呢?用上面的方法,把服務端共享的目錄修改成777權限,然後用戶端用普通用在其共享目錄建立檔案,看看裡面建立的檔案的所有者群組就知道了
[root@test ~]# chmod 777 /nfsdir
[root@test ~]#
==================================
[qiuhom@test-node1 mnt]$touch qiuhomfile
[qiuhom@test-node1 mnt]$ll
total 0
-rw-rw-r-- 1 qiuhom qiuhom 0 Jan 30 00:35 qiuhomfile
-rw-r--r-- 1 nfsnobody nfsnobody 0 Jan 30 00:21 rootfile
-rw-r--r-- 1 nfsnobody nfsnobody 0 Jan 30 00:27 rootfile2
[qiuhom@test-node1 mnt]$
說明:把服務端的共享目錄權限更改為777後用戶端的普通用在其裡面建立檔案的所有者群組都變成了用戶端的普通用名稱,但是這是在用戶端檢視的資訊是這樣的,我們在服務端檢視是不是這樣的呢?
[root@test ~]# ll /nfsdir
總用量 0
-rw-rw-r-- 1 503 503 0 1月 30 00:35 qiuhomfile
-rw-r--r-- 1 nfsnobody nfsnobody 0 1月 30 00:21 rootfile
-rw-r--r-- 1 nfsnobody nfsnobody 0 1月 30 00:27 rootfile2
[root@test ~]#
說明:怎麼在服務端檢視剛才用戶端普通使用者建立的檔案所有者群組是503呢?我們在來看看用戶端普通使用者的uid就明白了
[qiuhom@test-node1 mnt]$id qiuhom
uid=503(qiuhom) gid=503(qiuhom) groups=503(qiuhom)
[qiuhom@test-node1 mnt]$
說明:是不是明白了,普通用在nfs服務端陪映射成以普通使用者uid和gid的使用者了,如果服務端有對應uid使用者和gid組,則服務端就會顯示器名稱,如果沒有則顯示器uid和gid,這個是服務端配置了root_squash和no_all_squash 是這樣的。
五、nfs配置檔案格式說明
1、nfs配置檔案格式
需要共享的目錄路徑 允許通路的主機或網段1(選項) 主機或網段2(選項)……
2、“#”井号表示注釋
3、單個主機可以是ipv4位址,ipv6位址,FQDN(域名)
4、網段支援兩種掩碼格式如:192.168.0.0/24 或者192.168.0.0/255.255.255.0
5、通配符支援域名,不支援ip,如:*.test.com
6、支援NIS域的主機組,如:@group_name
7、anonymous:表示使用*通配所有用戶端
六、配置檔案每個條目指定目錄導出到的哪些主機,及相關的權限和選項說明
1、預設選項:(ro,sync,root_squash,no_all_squash)
2、ro,rw 隻讀和讀寫
3、async 異步,資料變化後不立即寫磁盤,性能高
4、sync(1.0.0後為預設)同步,資料在請求時立即寫入共享
5、 no_all_squash (預設)保留共享檔案的UID和GID
6、 all_squash 所有遠端使用者(包括root)都變成nfsnobody
7、 root_squash (預設)遠端root映射為nfsnobody,UID為65534,早期版本是4294967294 (nfsnobody)
8、no_root_squash 遠端root映射成root使用者
9、anonuid和anongid 指明匿名使用者映射為特定使用者UID群組GID,而非nfsnobody,可配合all_squash使用
七、NFS工具使用
rpcinfo:檢視rpc資訊
qiuhom@test-node1 mnt]$rpcinfo -p 192.168.0.99
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
100024 1 udp 38042 status
100024 1 tcp 45458 status
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 37177 nlockmgr
100021 3 udp 37177 nlockmgr
100021 4 udp 37177 nlockmgr
100021 1 tcp 40293 nlockmgr
100021 3 tcp 40293 nlockmgr
100021 4 tcp 40293 nlockmgr
[qiuhom@test-node1 mnt]$
說明:-p選項指定檢視指定伺服器上rpcbind所注冊的端口資訊,若-p後面不指定主機表示檢視本機的端口注冊資訊
[qiuhom@test-node1 mnt]$rpcinfo -s 192.168.0.99
program version(s) netid(s) service owner
100000 2,3,4 local,udp,tcp,udp6,tcp6 portmapper superuser
100005 3,2,1 tcp6,udp6,tcp,udp mountd superuser
100024 1 tcp6,udp6,tcp,udp status 29
100003 4,3 udp6,tcp6,udp,tcp nfs superuser
100227 3 udp6,tcp6,udp,tcp nfs_acl superuser
100021 4,3,1 tcp6,udp6,tcp,udp nlockmgr superuser
[qiuhom@test-node1 mnt]$
說明:-s選項表示檢視rpc注冊的程式,若不跟主機位址,則表示檢視本機rpc注冊的程式資訊
exportfs:維護導出的NFS檔案系統表
[root@test ~]# exportfs -v
/nfsdir 192.168.0.0/24(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,root_squash,no_all_squash)
[root@test ~]
說明:-v選項表示檢視本機所有NFS共享詳情
[root@test ~]# cat /etc/exports
/nfsdir 192.168.0.0/24(rw)
[root@test ~]# cat > /etc/exports
/nfsdir *
^C
[root@test ~]# cat /etc/exports
/nfsdir *
[root@test ~]# exportfs -r
exportfs: No options for /nfsdir *: suggest *(sync) to avoid warning
[root@test ~]# exportfs -v
/nfsdir <world>(sync,wdelay,hide,no_subtree_check,sec=sys,ro,secure,root_squash,no_all_squash)
[root@test ~]#
說明:-r選項表示不重新開機重讀配置檔案,并共享目錄,如果配置檔案中沒有明确寫明是同步寫磁盤還是異步寫磁盤,它重讀配置檔案的時候它會警告我們建議加上sync
[root@test ~]# exportfs -v
/nfsdir <world>(sync,wdelay,hide,no_subtree_check,sec=sys,ro,secure,root_squash,no_all_squash)
[root@test ~]# cat > /etc/exports
/nfsdir *(rw,all_squash)
^C
[root@test ~]# cat /etc/exports
/nfsdir *(rw,all_squash)
[root@test ~]# exportfs -a
[root@test ~]# exportfs -v
/nfsdir <world>(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,root_squash,all_squash)
[root@test ~]#
說明:-a選項表示重讀配置并輸出本機所有共享,如果停止本機的共享,使用-a會恢複所有共享
[root@test ~]# exportfs -au
[root@test ~]# exportfs -v
[root@test ~]#
說明:-au選項表示停止所有共享
showmount -e hostname:檢視指定主機上的共享目錄情況
[root@test ~]# showmount -e 192.168.0.99
Export list for 192.168.0.99:
/nfsdir *
[root@test ~]# showmount -e
Export list for test:
/nfsdir *
[root@test ~]#
說明:-e後面若不跟主機位址,則表示檢視本機的恭喜那個目錄情況
八、用戶端NFS挂載說明
基于安全考慮,建議使用nosuid,nodev,noexec挂載選項
NFS相關的挂載選項:
fg(預設)前台挂載,bg背景挂載
hard(預設)持續請求,soft 非持續請求
intr 和hard配合,請求可中斷
rsize和wsize 一次讀和寫資料最大位元組數,rsize=32768
_netdev 無網絡不挂載
示例:
mount -o rw,nosuid,fg,hard,intr 172.16.0.1:/testdir /mnt/nfs/
開機挂載:編輯/etc/fstab檔案在檔案最後添加,如:172.16.0.1:/public /mnt/nfs nfs defaults 0 0
九、NFS實作僞根
1、建立目錄
[root@test ~]# mkdir /root/dir{1,2} -pv
mkdir: 已建立目錄 "/root/dir1"
mkdir: 已建立目錄 "/root/dir2"
[root@test ~]# mkdir /test/dir{1,2} -pv
mkdir: 已建立目錄 "/test"
mkdir: 已建立目錄 "/test/dir1"
mkdir: 已建立目錄 "/test/dir2"
[root@test ~]#
2、編寫/etc/fstab檔案,在其檔案中填寫如下内容
[root@test ~]# tail -n 2 /etc/fstab
/root/dir1 /test/dir1 none bind 0 0
/root/dir2 /test/dir2 none bind 0 0
[root@test ~]#
3、編寫/etc/exports檔案,在其檔案中添加如下内容
[root@test ~]# cat /etc/exports
/test *(fsid=0,rw,crossmnt)
/test/dir1 192.168.0.0/24(rw,all_squash)
/test/dir2 192.168.0.0/24(rw,all_squash)
[root@test ~]#
4、挂載所有目錄,并重讀NFS配置
[root@test ~]# mount -a
[root@test ~]# mount |tail -n 2
/dev/mapper/centos-root on /test/dir1 type xfs (rw,relatime,attr2,inode64,noquota)
/dev/mapper/centos-root on /test/dir2 type xfs (rw,relatime,attr2,inode64,noquota)
[root@test ~]# exportfs -r
[root@test ~]# exportfs -v
/test/dir1 192.168.0.0/24(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,root_squash,all_squash)
/test/dir2 192.168.0.0/24(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,root_squash,all_squash)
/test <world>(sync,wdelay,hide,crossmnt,no_subtree_check,fsid=0,sec=sys,rw,secure,root_squash,no_all_squash)
[root@test ~]#
說明:到此服務端的配置就完成了,接下來在用戶端挂載即可
5、用戶端挂載僞根
[root@test-node1 ~]#mkdir xxx
[root@test-node1 ~]#mount 192.168.0.99:/ ./xxx/
[root@test-node1 ~]#df
df: `/mnt': Stale file handle
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root
51475068 4746736 44106892 10% /
tmpfs 959580 0 959580 0% /dev/shm
/dev/sda1 487652 45302 416750 10% /boot
/dev/mapper/VolGroup-lv_home
251354900 69268 238510824 1% /home
192.168.0.99:/ 27560960 13935360 13625600 51% /root/xxx
[root@test-node1 ~]#ls xxx/
dir1 dir2
[root@test-node1 ~]#
說明:如果用戶端需要實作開機挂載,則需要在/etc/fstab下寫明挂載關系和挂載選項即可,如:192.168.0.99:/ /root/xxx/ nfs ro 0 0
十、配置NFS使用固定端口
編輯配置檔案/etc/sysconfig/nfs在其最後添加RQUOTAD_PORT=875(端口可以根據實際情況來定)修改後的檔案如下幾項内容
[root@test ~]# grep "PORT" /etc/sysconfig/nfs
LOCKD_TCPPORT=32803
LOCKD_UDPPORT=32769
MOUNTD_PORT=892
STATD_PORT=662
STATD_OUTGOING_PORT=2020
RQUOTAD_PORT=875
[root@test ~]#
說明:除了以上端口外,防火牆配置還需要開放tcp和udp的111端口和2049端口共4個端口。配置了以上配置檔案後,然後重新開機nfs-server服務,nfs注冊的端口就不會變了,如下所示
[root@test ~]# systemctl restart nfs-server
[root@test ~]# rpcinfo -p
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
100024 1 udp 38042 status
100024 1 tcp 45458 status
100005 1 udp 892 mountd
100005 1 tcp 892 mountd
100005 2 udp 892 mountd
100005 2 tcp 892 mountd
100005 3 udp 892 mountd
100005 3 tcp 892 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 32769 nlockmgr
100021 3 udp 32769 nlockmgr
100021 4 udp 32769 nlockmgr
100021 1 tcp 32803 nlockmgr
100021 3 tcp 32803 nlockmgr
100021 4 tcp 32803 nlockmgr
[root@test ~]# systemctl restart nfs-server
[root@test ~]# rpcinfo -p
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
100024 1 udp 38042 status
100024 1 tcp 45458 status
100005 1 udp 892 mountd
100005 1 tcp 892 mountd
100005 2 udp 892 mountd
100005 2 tcp 892 mountd
100005 3 udp 892 mountd
100005 3 tcp 892 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 32769 nlockmgr
100021 3 udp 32769 nlockmgr
100021 4 udp 32769 nlockmgr
100021 1 tcp 32803 nlockmgr
100021 3 tcp 32803 nlockmgr
100021 4 tcp 32803 nlockmgr
[root@test ~]#
十一、NFS實作自動挂載
1、用戶端安裝autofs軟體包
[root@test-centos7-node1 ~]# yum info autofs
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Available Packages
Name : autofs
Arch : x86_64
Epoch : 1
Version : 5.0.7
Release : 69.el7
Size : 808 k
Repo : my_base/7/x86_64
Summary : A tool for automatically mounting and unmounting filesystems
License : GPLv2+
Description : autofs is a daemon which automatically mounts filesystems when you use
: them, and unmounts them later when you are not using them. This can
: include network filesystems, CD-ROMs, floppies, and so forth.
[root@test-centos7-node1 ~]# yum install -y autofs
Loaded plugins: fastestmirror
epel | 5.3 kB 00:00:00
my_base | 3.6 kB 00:00:00
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package autofs.x86_64 1:5.0.7-69.el7 will be installed
--> Processing Dependency: libtirpc.so.1()(64bit) for package: 1:autofs-5.0.7-69.el7.x86_64
--> Processing Dependency: libhesiod.so.0()(64bit) for package: 1:autofs-5.0.7-69.el7.x86_64
--> Running transaction check
---> Package hesiod.x86_64 0:3.2.1-3.el7 will be installed
---> Package libtirpc.x86_64 0:0.2.4-0.10.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================================================================
Package Arch Version Repository Size
================================================================================================================================
Installing:
autofs x86_64 1:5.0.7-69.el7 my_base 808 k
Installing for dependencies:
hesiod x86_64 3.2.1-3.el7 my_base 30 k
libtirpc x86_64 0.2.4-0.10.el7 my_base 88 k
Transaction Summary
================================================================================================================================
Install 1 Package (+2 Dependent packages)
Total download size: 927 k
Installed size: 5.3 M
Downloading packages:
(1/3): hesiod-3.2.1-3.el7.x86_64.rpm | 30 kB 00:00:00
(2/3): libtirpc-0.2.4-0.10.el7.x86_64.rpm | 88 kB 00:00:00
(3/3): autofs-5.0.7-69.el7.x86_64.rpm | 808 kB 00:00:00
--------------------------------------------------------------------------------------------------------------------------------
Total 1.9 MB/s | 927 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
Installing : libtirpc-0.2.4-0.10.el7.x86_64 1/3
Installing : hesiod-3.2.1-3.el7.x86_64 2/3
Installing : 1:autofs-5.0.7-69.el7.x86_64 3/3
Verifying : 1:autofs-5.0.7-69.el7.x86_64 1/3
Verifying : hesiod-3.2.1-3.el7.x86_64 2/3
Verifying : libtirpc-0.2.4-0.10.el7.x86_64 3/3
Installed:
autofs.x86_64 1:5.0.7-69.el7
Dependency Installed:
hesiod.x86_64 0:3.2.1-3.el7 libtirpc.x86_64 0:0.2.4-0.10.el7
Complete!
[root@test-centos7-node1 ~]#
說明:從上面的資訊可以知道autofs這個包的主要功能就是自動挂載和解除安裝檔案系統的工具
2、檢視autofs的配置檔案
[root@test-centos7-node1 ~]# rpm -ql autofs|grep etc
/etc/auto.master
/etc/auto.master.d
/etc/auto.misc
/etc/auto.net
/etc/auto.smb
/etc/autofs.conf
/etc/autofs_ldap_auth.conf
/etc/sysconfig/autofs
[root@test-centos7-node1 ~]#
說明:可以看到autofs的組配置檔案是/etc/auto.master 當然也可以把配置檔案放到/etc/auto.master.d/下
3、檢視主配置檔案中定義的内容
[root@test-centos7-node1 ~]# cat /etc/auto.master
#
# Sample auto.master file
# This is a 'master' automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
#
/misc /etc/auto.misc
#
# NOTE: mounts done from a hosts map will be mounted with the
# "nosuid" and "nodev" options unless the "suid" and "dev"
# options are explicitly given.
#
/net -hosts
#
# Include /etc/auto.master.d/*.autofs
# The included files must conform to the format of this file.
#
+dir:/etc/auto.master.d
#
# Include central master map if it can be found using
# nsswitch sources.
#
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.
#
+auto.master
[root@test-centos7-node1 ~]#
說明:以上主配置檔案定義了/misc 目錄下的子目錄挂載政策的子配置檔案是/etc/auto.misc。我們可以這樣了解,/etc/auto.master這個檔案定義了挂載點的父目錄位置,以及該父目錄下面的子目錄挂載政策的配置檔案存放路徑和名稱。也就是說我們要實作自動挂載,我們需要把挂載點分成兩部分,第一部分是挂載點的父目錄在哪裡,這個需要在/etc/auto.master裡面定,除此之外,我們還需要在/etc/master下面定義挂載點的父目錄下的子目錄挂載政策的配置檔案的路徑以及名稱。當然這個路徑和名稱可以根據自己的情況來寫,通常情況下我們放在/etc/下面。了解了/etc/auto.master的配置檔案規則,我們可以清楚的知道/misc 這個目錄下的子目錄挂載規則是存放在/etc/auto.misc裡,接下來我們再來看看這個子配置檔案
[root@test-centos7-node1 ~]# cat /etc/auto.misc
#
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# Details may be found in the autofs(5) manpage
cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom
# the following entries are samples to pique your imagination
#linux -ro,soft,intr ftp.example.org:/pub/linux
#boot -fstype=ext2 :/dev/hda1
#floppy -fstype=auto :/dev/fd0
#floppy -fstype=ext2 :/dev/fd0
#e2floppy -fstype=ext2 :/dev/fd0
#jaz -fstype=ext2 :/dev/sdc1
#removable -fstype=ext2 :/dev/hdd
[root@test-centos7-node1 ~]#
說明:這個之配置檔案除了注釋以外就隻有一行,從上面的描述,我們不難了解子配置檔案中的這個配置是什麼意思。結合上面說的 這個之配置檔案是/misc目錄下的子目錄挂載政策的配置。以上配置表示在/misc/cd目錄挂載對應的裝置上 /dev/cdrom 檔案系統是iso9660 以隻讀,nosuid,nodev選項挂載。看了以上的配置我們就很容易了解,centos7上的"神奇的目錄",之是以我們在不通路/misc/cd 的時候是看不到挂載的,一旦通路就有挂載自動挂上去了 ,它的實作原理就是通過autofs自動挂載實作的。了解了上面的配置我們就可以寫自己的挂載政策實作自動挂載
4、NFS自動挂載實作
4.1相對路徑法
首先解釋下說明叫相對路徑法,相對路徑就是我們上面說的/misc/cd 這個挂載點例子,它是把挂載點分成了了basename和dirname兩部分來配置的,是以說在組配置檔案中(/etc/auto.master)需要定義dirname路徑以及basename子目錄挂載政策的配置檔案路徑和名稱。然後在對應的之配置檔案中寫清楚挂載政策和子目錄的關系即可
将192.168.0.99:/nfsdir 自動挂載到本機的/auto/nfs/目錄下
4.1.1、編輯組配置檔案定義父目錄 和子目錄配置檔案的路徑和名稱
[root@test-centos7-node1 ~]# grep nfs /etc/auto.master
/auto /etc/nfs_auto.txt
[root@test-centos7-node1 ~]#
說明:以上内容是我們自己行家挂載點父目錄和子目錄配置檔案的路徑和名稱,這個子配置檔案的名稱沒有什麼要求,可以随意寫。
4.1.2、在對應子配置檔案中寫子目錄挂載政策
[root@test-centos7-node1 ~]# cat /etc/nfs_auto.txt
nfs -fstype=nfs,rw,vers=3 192.168.0.99:/nfsdir
[root@test-centos7-node1 ~]#
說明:配置好子目錄的挂載政策後就實作了自動挂載。這裡還需要注意一點的是,我們在用戶端實作自動挂載的前提是NFS可以在用戶端挂載,如果用戶端都看不到NFS共享出來的目錄,當然也不能實作自動挂載
4.1.3、在用戶端檢視是否能夠看到NFS共享出來的目錄
[root@test-centos7-node1 ~]# showmount -e 192.168.0.99
Export list for 192.168.0.99:
/test *
/test/dir2 192.168.0.0/24
/test/dir1 192.168.0.0/24
/nfsdir 192.168.0.0/24
[root@test-centos7-node1 ~]#
說明:可看到在用戶端是可以看到服務端的nfs共享的目錄,接下來我們啟動autofs服務檢視挂載情況
[root@test-centos7-node1 ~]# systemctl status autofs
● autofs.service - Automounts filesystems on demand
Loaded: loaded (/usr/lib/systemd/system/autofs.service; disabled; vendor preset: disabled)
Active: inactive (dead)
[root@test-centos7-node1 ~]# systemctl start autofs
[root@test-centos7-node1 ~]# systemctl status autofs
● autofs.service - Automounts filesystems on demand
Loaded: loaded (/usr/lib/systemd/system/autofs.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2020-01-28 18:13:19 CST; 1min 21s ago
Process: 3862 ExecStart=/usr/sbin/automount $OPTIONS --pid-file /run/autofs.pid (code=exited, status=0/SUCCESS)
Main PID: 3864 (automount)
CGroup: /system.slice/autofs.service
└─3864 /usr/sbin/automount --pid-file /run/autofs.pid
Jan 28 18:13:17 test-centos7-node1 automount[3864]: master_add_map_source: map source used without taking reference
Jan 28 18:13:17 test-centos7-node1 automount[3864]: master_add_map_source: map source used without taking reference
Jan 28 18:13:17 test-centos7-node1 automount[3864]: open_sss_lib:78: lookup(sss): failed to open /usr/lib64/sssd/modules...ctory
Jan 28 18:13:19 test-centos7-node1 automount[3864]: problem reading master map, maximum wait exceeded
Jan 28 18:13:19 test-centos7-node1 automount[3864]: /usr/sbin/automount: warning: could not read at least one map source...g ...
Jan 28 18:13:19 test-centos7-node1 automount[3864]: master_add_map_source: map source used without taking reference
Jan 28 18:13:19 test-centos7-node1 automount[3864]: master_add_map_source: map source used without taking reference
Jan 28 18:13:19 test-centos7-node1 automount[3864]: master_add_map_source: map source used without taking reference
Jan 28 18:13:19 test-centos7-node1 automount[3864]: open_sss_lib:78: lookup(sss): failed to open /usr/lib64/sssd/modules...ctory
Jan 28 18:13:19 test-centos7-node1 systemd[1]: Started Automounts filesystems on demand.
Hint: Some lines were ellipsized, use -l to show in full.
[root@test-centos7-node1 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 48209924 3116852 45093072 7% /
devtmpfs 1922828 0 1922828 0% /dev
tmpfs 1932652 20 1932632 1% /dev/shm
tmpfs 1932652 8800 1923852 1% /run
tmpfs 1932652 0 1932652 0% /sys/fs/cgroup
/dev/sda1 2086912 137672 1949240 7% /boot
tmpfs 386532 0 386532 0% /run/user/0
[root@test-centos7-node1 ~]#
說明:我們啟動autofs後,我們定義的自動挂載好像沒有自動挂載到對應的目錄。這個時候我們來直接通路我們定義的挂載點看看有什麼情況
[root@test-centos7-node1 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 48209924 3116816 45093108 7% /
devtmpfs 1922828 0 1922828 0% /dev
tmpfs 1932652 20 1932632 1% /dev/shm
tmpfs 1932652 8800 1923852 1% /run
tmpfs 1932652 0 1932652 0% /sys/fs/cgroup
/dev/sda1 2086912 137672 1949240 7% /boot
tmpfs 386532 0 386532 0% /run/user/0
[root@test-centos7-node1 ~]# ls /
auto boot etc lib media mnt opt proc run srv tmp var
bin dev home lib64 misc net patch root sbin sys usr www
[root@test-centos7-node1 ~]# ls /auto/
[root@test-centos7-node1 ~]# cd /auto/nfs
[root@test-centos7-node1 nfs]# ll
total 0
[root@test-centos7-node1 nfs]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 48209924 3116996 45092928 7% /
devtmpfs 1922828 0 1922828 0% /dev
tmpfs 1932652 20 1932632 1% /dev/shm
tmpfs 1932652 8804 1923848 1% /run
tmpfs 1932652 0 1932652 0% /sys/fs/cgroup
/dev/sda1 2086912 137672 1949240 7% /boot
tmpfs 386532 0 386532 0% /run/user/0
192.168.0.99:/nfsdir 27560960 13929472 13631488 51% /auto/nfs
[root@test-centos7-node1 nfs]#
說明:可看到我們去通路我們定義的挂載點,就能夠立即将NFS給挂載到系統上,其實過上一段時間我們不通路我們的挂載點,它還會自動解除安裝掉,我們一旦去通路挂載點,它又會立刻觸發挂載,把對應的資源給挂載到系統上;這裡再說一下,如果子配置檔案的挂載目錄和NFS的共享目錄相同 ,我們可以用*來通配,如:NFS伺服器共享的目錄是192.168.0.99:/nfsdir 用戶端挂載的目錄為/misc/nfsdir 這種挂載點的basename和nfs伺服器上共享的目錄的basename相同時。我們在子配置檔案中還可以寫成 * -fstype=nfs,rw,vers=3 192.168.0.99:/&
[root@test-centos7-node1 ~]# cat /etc/nfs_auto.txt
* -fstype=nfs,rw,vers=3 192.168.0.99:/&
[root@test-centos7-node1 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 48209924 3117020 45092904 7% /
devtmpfs 1922828 0 1922828 0% /dev
tmpfs 1932652 20 1932632 1% /dev/shm
tmpfs 1932652 8776 1923876 1% /run
tmpfs 1932652 0 1932652 0% /sys/fs/cgroup
/dev/sda1 2086912 137672 1949240 7% /boot
tmpfs 386532 0 386532 0% /run/user/0
[root@test-centos7-node1 ~]# cd /auto/nfsdir
[root@test-centos7-node1 nfsdir]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 48209924 3117020 45092904 7% /
devtmpfs 1922828 0 1922828 0% /dev
tmpfs 1932652 20 1932632 1% /dev/shm
tmpfs 1932652 8776 1923876 1% /run
tmpfs 1932652 0 1932652 0% /sys/fs/cgroup
/dev/sda1 2086912 137672 1949240 7% /boot
tmpfs 386532 0 386532 0% /run/user/0
192.168.0.99:/nfsdir 27560960 13929472 13631488 51% /auto/nfsdir
[root@test-centos7-node1 nfsdir]#
說明:這種寫法我們在通路其挂載點的時候,需要清楚知道服務端共享目錄的名稱才可以,這種寫法是可以比對多個共享目錄的,隻要挂載點和NFS伺服器共享目錄路徑有相同的,都可以比對上。如下所示
[root@test-centos7-node1 ~]# showmount -e 192.168.0.99
Export list for 192.168.0.99:
/test *
/test/dir2 192.168.0.0/24
/test/dir1 192.168.0.0/24
/nfsdir 192.168.0.0/24
[root@test-centos7-node1 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 48209924 3116956 45092968 7% /
devtmpfs 1922828 0 1922828 0% /dev
tmpfs 1932652 20 1932632 1% /dev/shm
tmpfs 1932652 8776 1923876 1% /run
tmpfs 1932652 0 1932652 0% /sys/fs/cgroup
/dev/sda1 2086912 137672 1949240 7% /boot
tmpfs 386532 0 386532 0% /run/user/0
192.168.0.99:/nfsdir 27560960 13929728 13631232 51% /auto/nfsdir
[root@test-centos7-node1 ~]# cd /auto/test/
[root@test-centos7-node1 test]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 48209924 3116956 45092968 7% /
devtmpfs 1922828 0 1922828 0% /dev
tmpfs 1932652 20 1932632 1% /dev/shm
tmpfs 1932652 8776 1923876 1% /run
tmpfs 1932652 0 1932652 0% /sys/fs/cgroup
/dev/sda1 2086912 137672 1949240 7% /boot
tmpfs 386532 0 386532 0% /run/user/0
192.168.0.99:/nfsdir 27560960 13929472 13631488 51% /auto/nfsdir
192.168.0.99:/test 27560960 13929472 13631488 51% /auto/test
[root@test-centos7-node1 test]# ls
dir1 dir2
[root@test-centos7-node1 test]# cd /auto/test/dir2
[root@test-centos7-node1 dir2]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 48209924 3116956 45092968 7% /
devtmpfs 1922828 0 1922828 0% /dev
tmpfs 1932652 20 1932632 1% /dev/shm
tmpfs 1932652 8776 1923876 1% /run
tmpfs 1932652 0 1932652 0% /sys/fs/cgroup
/dev/sda1 2086912 137672 1949240 7% /boot
tmpfs 386532 0 386532 0% /run/user/0
192.168.0.99:/test 27560960 13929472 13631488 51% /auto/test
192.168.0.99:/test/dir2 27560960 13929472 13631488 51% /auto/test/dir2
[root@test-centos7-node1 dir2]#
4.2、絕對路徑法
絕對路徑法就是在主配置檔案中(/etc/auto.master)檔案中用/-來表示不再主配置檔案中定義父目錄名稱,然後在後面指定子配置檔案的路徑和名稱即可,也就是說和相對路徑法不同的是,把絕對路徑和挂載政策都寫在子配置檔案中。
接下來我們把192.168.0.99:/ 挂載到本地的 /a/b/c/d/目錄下
4.2.1、編輯主配置檔案
[root@test-centos7-node1 ~]# grep "path" /etc/auto.master
/- /etc/mount_all_path.txt
[root@test-centos7-node1 ~]#
4.2.2、在子配置檔案中寫挂載政策
[root@test-centos7-node1 ~]# cat /etc/mount_all_path.txt
/a/b/c/d/ -fstype=nfs,rw,all_squash 192.168.0.99:/
[root@test-centos7-node1 ~]#
說明:我們寫好子配置檔案後,是需要重新開機autofs服務。然後通過通路挂載點,看看它是否能夠挂載NFS共享出來的目錄呢
[root@test-centos7-node1 ~]# systemctl restart autofs
[root@test-centos7-node1 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 48209924 3116996 45092928 7% /
devtmpfs 1922828 0 1922828 0% /dev
tmpfs 1932652 20 1932632 1% /dev/shm
tmpfs 1932652 8776 1923876 1% /run
tmpfs 1932652 0 1932652 0% /sys/fs/cgroup
/dev/sda1 2086912 137672 1949240 7% /boot
tmpfs 386532 0 386532 0% /run/user/0
[root@test-centos7-node1 ~]# ls /a/b/c/d/
dir1 dir2
[root@test-centos7-node1 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 48209924 3116996 45092928 7% /
devtmpfs 1922828 0 1922828 0% /dev
tmpfs 1932652 20 1932632 1% /dev/shm
tmpfs 1932652 8776 1923876 1% /run
tmpfs 1932652 0 1932652 0% /sys/fs/cgroup
/dev/sda1 2086912 137672 1949240 7% /boot
tmpfs 386532 0 386532 0% /run/user/0
192.168.0.99:/ 27560960 13929472 13631488 51% /a/b/c/d
[root@test-centos7-node1 ~]#
說明:我們通過通路挂載點也實作了自動挂載。其實autofs對自動挂載NFS提前有在主配置檔案中定義,我們可以不用任何配置,裝好autofs軟體包後,直接cd NFS伺服器的主機位址就可實作自動挂載
[root@test-centos7-node1 ~]# grep ^"\/net" /etc/auto.master
/net -hosts
[root@test-centos7-node1 ~]#
說明:這個配置就是表示我們在通過網絡挂載資源的時候,可以直接通路/net/對方ip位址即可,當然這種都是用在區域網路裡,NFS不建議用在網際網路。
[root@test-centos7-node1 ~]# umount /a/b/c/d/
[root@test-centos7-node1 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 48209924 3116948 45092976 7% /
devtmpfs 1922828 0 1922828 0% /dev
tmpfs 1932652 20 1932632 1% /dev/shm
tmpfs 1932652 8776 1923876 1% /run
tmpfs 1932652 0 1932652 0% /sys/fs/cgroup
/dev/sda1 2086912 137672 1949240 7% /boot
tmpfs 386532 0 386532 0% /run/user/0
[root@test-centos7-node1 ~]# cd 192.168.0.99
-bash: cd: 192.168.0.99: No such file or directory
[root@test-centos7-node1 ~]# ls /net/
[root@test-centos7-node1 ~]# ls /net/192.168.0.99
nfsdir test
[root@test-centos7-node1 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 48209924 3116952 45092972 7% /
devtmpfs 1922828 0 1922828 0% /dev
tmpfs 1932652 20 1932632 1% /dev/shm
tmpfs 1932652 8776 1923876 1% /run
tmpfs 1932652 0 1932652 0% /sys/fs/cgroup
/dev/sda1 2086912 137672 1949240 7% /boot
tmpfs 386532 0 386532 0% /run/user/0
[root@test-centos7-node1 ~]#
說明:這種方式用df指令是看不到它的挂載情況的,我們需要用mount指令是可以檢視到挂載詳情。如下所示
[root@test-centos7-node1 ~]# mount |tail
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)
mqueue on /dev/mqueue type mqueue (rw,relatime)
/dev/sda1 on /boot type xfs (rw,relatime,attr2,inode64,noquota)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=386532k,mode=700)
/etc/auto.misc on /misc type autofs (rw,relatime,fd=7,pgrp=4091,timeout=300,minproto=5,maxproto=5,indirect,pipe_ino=28437)
/etc/nfs_auto.txt on /auto type autofs (rw,relatime,fd=13,pgrp=4091,timeout=300,minproto=5,maxproto=5,indirect,pipe_ino=29313)
/etc/mount_all_path.txt on /a/b/c/d type autofs (rw,relatime,fd=19,pgrp=4091,timeout=300,minproto=5,maxproto=5,direct,pipe_ino=26610)
-hosts on /net type autofs (rw,relatime,fd=24,pgrp=4091,timeout=300,minproto=5,maxproto=5,indirect,pipe_ino=26615)
-hosts on /net/192.168.0.99/nfsdir type autofs (rw,relatime,fd=24,pgrp=4091,timeout=300,minproto=5,maxproto=5,offset,pipe_ino=26615)
-hosts on /net/192.168.0.99/test type autofs (rw,relatime,fd=24,pgrp=4091,timeout=300,minproto=5,maxproto=5,offset,pipe_ino=26615)
[root@test-centos7-node1 ~]#
說明:以上的所有操作都建立在用戶端上的操作,且用戶端是能夠看到其NFS伺服器上的共享目錄的前提才可以實作自動挂載。
作者:Linux-1874
出處:https://www.cnblogs.com/qiuhom-1874/
本文版權歸作者和部落格園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接配接,否則保留追究法律責任的權利.