實驗環境:
兩台主機
node4:192.168.37.44 nfs伺服器
node2:192.168.37.22 客戶端
在nfs伺服器,先安裝nfs和rpcbind
[root@node4 fenxiang]#yuminstall rpcbind nfs -y
在nfs伺服器建立共享的目錄並將共享的目錄匯出
[root@node4 fenxiang]#mkdir /data/fenxiang/[root@node4 exports.d]#vim /etc/exports.d/fenxiang.exports #:注意一定要以exports結尾/data/fenxiang 192.168.37.22(rw,async,all_squash,anonuid=99,anongid=99
) #: rw 可讀可寫
async 非同步同步
all_squash 將所有在此資料夾建檔案的人,全部對映為apache
anonuid 設定對映人的uid,此文是對映的nobody
anongid 設定對映人的gid,此文是對映的nobody
在nfs伺服器為共享的目錄設定許可權
[root@node4 fenxiang]#setfacl -m u:nobody:rwx /data/fenxiang/ #:設定的許可權要和對映的使用者一致,否則客戶端掛載後不能寫入
在客戶端檢視並開始掛載
[root@node2 mnt]#showmount -e 192.168.37.44export list
for192.168.37.44
:/data/fenxiang 192.168.37.22
[root@node2 mnt]#vim /etc/fstab
192.168.37.44:/data/fenxiang /mnt nfs defaults 0
0[root@node2 mnt]#mount -a
現在就可以正常使用了
實現autofs掛載規則(實現家目錄共享)
在客戶端確認autofs包裝沒裝著
[root@node2 mnt]#rpm -q autofsautofs-5.0.7-99.el7.x86_64
在nfs端匯出需要共享的家目錄
[root@node4 exports.d]#vim /etc/exports.d/ma.exports/home/ma 192.168.37.22(rw,async,all_squash,anonuid=1003,anongid=1003
)#
1003 是使用者ma 的uid和gid
在客戶端配置autofs(用絕對路徑法,否則其它家目錄使用者的目錄會被覆蓋)
[root@node2 ma]#vim /etc/auto.master/- /etc/auto.ma
#: /-固定寫法
/etc/auto.ma 指定ma的配置檔案
[root@node2 ma]#vim /etc/auto.ma
/home/ma -fstype=nfs 192.168.37.44:/home/ma
# : 第一段 客戶端ma的家目錄
第二段 指定掛載的型別
第三段 nfs伺服器共享出來的目錄
重啟服務
[root@node2 ma]#systemctl restart autofs
這樣就實現了訪問時自動掛載
autofs自動掛載NFS技術
autofs它是一種看守程式。如果它檢測到使用者正試圖訪問乙個尚天掛載的檔案系統,它就會自動檢測檔案系統,如果存在,那麼autofs會自動將其掛載。如果它檢測到某個已掛載的檔案系統在一段時間內沒有被使用,那麼autofs會自動將其解除安裝。使用者不再需要手動完成檔案系統的掛載和解除安裝。本次測試自動...
NFS使用autofs自動掛載
nfs自動掛載設定在 etc fstab和 etc rc.local可能掛載不成功,假如是服務端nfs宕機還可能導致客戶端無法啟動,可以使用autofs實現自動掛載 安裝autofs yum y install autofs修改配置檔案 etc auto.master在尾部新增一行 backup e...
AUTOFS自動掛載NFS共享方法
autofs自動掛載nfs共享方法 系統環境ubuntu,安裝 sudo apt get install autofs 主要有兩個配置檔案 修改auto.master。test是要掛載到的本地目錄,etc auto.misc是掛載的配置。名稱可以修改 修改 etc auto.misc,autofst...