Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

Linux 下 NFS 搭配 autofs 實現自動掛載

NFS 共享目錄若每次都要手動 mount,顯得繁瑣且不便管理。本文示範如何透過 autofs 服務,讓客戶端在真正存取共享目錄時才自動掛載,做到「按需掛載、閒置卸載」。

環境準備

準備兩台 CentOS 6.5 服務器:

· NFS 服務端:IP 為 192.168.100.100
· NFS 客戶端:IP 為 192.168.100.101

服務端配置

先安裝 NFS 相關套件:

[root@nfsserver ~]# yum install nfs-utils rpcbind -y

建立共享目錄並編輯 exports 配置:

[root@nfsserver ~]# mkdir /data/share
[root@nfsserver ~]# vim /etc/exports
/data/share 192.168.100.0/24(rw,sync,anonuid=555,anongid=555,all_squash)

檢查共享是否生效:

[root@nfsserver ~]# showmount -e 192.168.100.100
Export list for 192.168.100.100:
/data/share 192.168.100.0/24

客戶端安裝並啟動服務

[root@nfsclient ~]# yum install rpcbind nfs-utils -y
[root@nfsclient ~]# yum install autofs -y
[root@nfsclient ~]# /etc/init.d/rpcbind start
[root@nfsclient ~]# /etc/init.d/autofs start

配置 autofs 自動掛載

編輯主配置 /etc/auto.master,指定掛載點與掛載動作對應的映射文件:

[root@nfsclient ~]# vim /etc/auto.master
/mnt /etc/auto.misc timeout=60

其中 /mnt 為掛載點,/etc/auto.misc 為掛載動作定義。接著編輯映射文件,加入共享目錄定義:

[root@nfsclient ~]# vim /etc/auto.misc
nfsdata -fstype=nfs 192.168.100.100:/data/share

重啟並驗證

[root@nfsclient ~]# /etc/init.d/autofs restart
[root@nfsclient ~]# cd /mnt/nfsdata
[root@nfsclient nfsdata]# ls -l
-rw-r--r-- 1 oldgirl oldgirl 0 Aug 27 00:14 andy
-rw-r--r-- 1 oldgirl oldgirl 0 Aug 27 00:10 oldboy
[root@nfsclient nfsdata]# df -h
192.168.100.100:/data/share 38G 1.9G 34G 6% /mnt/nfsdata

可見共享目錄已隨存取自動掛載,整個流程無需手動 mount,管理更為省心。

Copyright © Linux教程網 All Rights Reserved