linux 配置autofs

liuzhen_basis發表於2014-07-29
Autofs與Mount/Umount的不同之處在於,它是一種看守程式。如果它檢測到使用者正試圖訪問一個尚未掛接的檔案系統,它就會自動檢測該檔案系 統,如果存在,那麼Autofs會自動將其掛接。另一方面,如果它檢測到某個已掛接的檔案系統在一段時間內沒有被使用,那麼Autofs會自動將其解除安裝。 因此一旦執行了Autofs後,使用者就不再需要手動完成檔案系統的掛接和解除安裝。

以下使用 RHEL7.0進行配置

[root@LiuZhen mnt]# service autofs start

Redirecting to /bin/systemctl start  autofs.service
Failed to issue method call: Unit autofs.service failed to load: No such file or directory.

rpm沒有安裝,安裝autofsrpm

[root@LiuZhen mnt]# yum install autofs.x86_64
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Resolving Dependencies
--&gt Running transaction check
---&gt Package autofs.x86_64 1:5.0.7-40.el7 will be installed
--&gt Processing Dependency: libhesiod.so.0()(64bit) for package: 1:autofs-5.0.7-40.el7.x86_64
--&gt Running transaction check
---&gt Package hesiod.x86_64 0:3.2.1-3.el7 will be installed
--&gt Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================================
 Package                   Arch                      Version                            Repository                  Size
=========================================================================================================================
Installing:
 autofs                    x86_64                    1:5.0.7-40.el7                     testyum                    550 k
Installing for dependencies:
 hesiod                    x86_64                    3.2.1-3.el7                        testyum                     30 k

Transaction Summary
=========================================================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 579 k
Installed size: 3.6 M
Is this ok [y/d/N]: y
Downloading packages:
-------------------------------------------------------------------------------------------------------------------------
Total                                                                                    1.1 MB/s | 579 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : hesiod-3.2.1-3.el7.x86_64                                                                             1/2
  Installing : 1:autofs-5.0.7-40.el7.x86_64                                                                          2/2
  Verifying  : hesiod-3.2.1-3.el7.x86_64                                                                             1/2
  Verifying  : 1:autofs-5.0.7-40.el7.x86_64                                                                          2/2

Installed:
  autofs.x86_64 1:5.0.7-40.el7                                                                                           

Dependency Installed:
  hesiod.x86_64 0:3.2.1-3.el7                                                                                            

Complete!
[root@LiuZhen mnt]#
[root@LiuZhen mnt]#
[root@LiuZhen mnt]#

啟動服務
[root@LiuZhen mnt]# service autofs start
Redirecting to /bin/systemctl start  autofs.service
[root@LiuZhen mnt]#
[root@LiuZhen mnt]#

設定開機自啟動
[root@LiuZhen mnt]# chkconfig autofs on
Note: Forwarding request to 'systemctl enable autofs.service'.
ln -s '/usr/lib/systemd/system/autofs.service' '/etc/systemd/system/multi-user.target.wants/autofs.service'


[root@LiuZhen cd]# grep -v ^$ /etc/auto.master | grep -v "#"
/misc    /etc/auto.misc
/net    -hosts
+dir:/etc/auto.master.d
+auto.master


檢視自動掛載的光碟
[root@LiuZhen cd]# ls /misc
cd
[root@LiuZhen cd]# ls /misc/cd
addons  EULA  images    LiveOS      Packages       repodata                 RPM-GPG-KEY-redhat-release
EFI     GPL   isolinux  media.repo  release-notes  RPM-GPG-KEY-redhat-beta  TRANS.TBL


若檢視自動掛載的NFS使用以下命令

配置hosts
echo 172.16.7.1 nfsserver>> /etc/hosts

檢視自動掛載目錄
ls /net
ls /net/nfsserver

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/27771627/viewspace-1241361/,如需轉載,請註明出處,否則將追究法律責任。

相關文章