-
網絡文件系統:在互聯網中共享服務器中文件資源。
-
使用nfs服務需要安裝:nfs-utils 以及 rpcbind
-
nfs-utils : 提供nfs服務的程序
-
rpcbind :管理nfs所有進程端口號的程序
?nfs的部署
? ? 1.客戶端和服務端都安裝nfs-utils和rpcbind
#安裝nfs的軟件rpcbind和nsf-utils
[root@server ~]# dnf install rpcbind -y[root@server ~]# dnf install nsf-utils -y#關閉網絡和內核防護墻(get查看狀態)
[root@server ~]# setenforce 0
[root@server ~]# getenforce
Permissive#開啟服務
[root@server ~]# systemctl enable --now rpcbind
[root@server ~]# systemctl enable --now nfs-server.service(客戶端無需此步驟)
Created symlink /etc/systemd/system/multi-user.target.wants/nfs-server.service → /usr/lib/systemd/system/nfs-server.service.
#檢查狀態
[root@server ~]# systemctl status nfs-server.service
(安裝方法2?
[root@client ~]# dnf install nfs-utils -y安裝依賴關系:rpcbind x86_64
? ?)
2.服務器設置
#編輯共享目錄配置文件(即/etc/exports)
[root@server ~]# mkdir /nfs_share (創建共享的目錄,名字隨便)
)
[root@server ~]# vim /etc/exports
...
/nfs_share 172.25.254.200(ro,sync)# ro表示read only只讀 sync表示同步,就是編輯了什么內容立即同步給對方
...#更新狀態(刷新服務端后客戶端可以掛載共享目錄)
[root@server ~]# exportfs -rv#在/nfs_share中創建一個文件
[root@server ~]# echo "hello nfs" > /nfs_share/hellonfs
3.客戶端設置?
# 查看服務端是否開啟了共享
[root@client ~]# showmount -e 192.168.25.100
Export list for 192.168.25.100:
/nfs_share 192.168.25.200 # 這里表示服務端將自己的/nfs_share 共享給了192.168.25.200# 將服務端的共享目錄掛在到本地即可使用共享目錄
[root@client ~]# mount 192.168.25.100:/nfs_share /mnt
(將/nfs_share 掛載到/mnt)
#檢查(查看共享目錄中是否存在服務端共享的文件)
[root@client ~]# ls /mnt
hellonfs
[root@client ~]# cat /mnt/hellonfs
hello nfs
[root@client ~]#
自動掛載客戶端
?
安裝 autofs即可自動掛載nfs服務器共享出來的目錄:
-
當我們進入到/net/xxx.xxx.xxx.xxx目錄中,autofs會自動將該ip中的共享目錄掛載到/net/xxx.xxx.xxx.xxx路徑下
-
當我們超過300秒不去對共享目錄做任何操作后,會自動卸載。
# 安裝autofs
[root@Client /]# dnf install autofs -y# 啟動autofs
[root@Client /]# systemctl start autofs.service# 進入/net/192.168.25.100
[root@Client /]# cd net
[root@Client net]# ls
# 進入該ip對應的目錄時,自動將該ip的共享目錄掛載到/net/172.25.254.100/nfs_share
[root@Client net]# cd 172.25.254.100
[root@Client 172.25.254.100]# ls
nfs_share
[root@Client nfs_share]# pwd (用于顯示當前工作目錄的絕對路徑)
/net/172.25.254.100/nfs_share# 修改自動卸載的超時時間
[root@Client ~]# vim /etc/autofs.conf
....
# minutes to be consistent with earlier autofs releases.
#
timeout = 300 該時間就是超時長,可以修改為用戶需要的超時長
#
# master_wait - set the default maximum number of retries (actual
....
指定自動掛載的目錄
1.修改auto.matser配置文件,確定主目錄的掛載位置,及其相關的子目錄配置文件
[root@Client nfs_share]# vim /etc/auto.master11 # options are explicitly given.12 #13 /net -hosts14 /nfs /etc/autofs.nfs_share #/nfs 主目錄掛載位置 /etc/autofs.nfs_share 子目錄的配置文件15 #16 # Include /etc/auto.master.d/*.autofs
2.編輯子目錄的配置文件 /etc/autofs.nfs_share
[root@Client nfs_share]# vim /etc/autofs.nfs_share
...nfs_share -rw 172.25.254.100:/nfs_share#nfs_share表示要掛載在:/nfs/nfs_share
#-rw:表示可讀可寫
#172.25.254.100:/nfs_share 表示文件服務器上共享目錄位置信息
...
3.重啟自動掛載服務
[root@Client nfs_share]# systemctl restart autofs.service
# 讀取遠程文件服務器上的內容
[root@Client nfs_share]# ls /nfs
nfs_share
[root@Client nfs_share]# cat /nfs/nfs_share/hellonfs.txt
hellonfs