Linux下的自動掛載工具:Autofs(轉載自51CTO下載)

Autofs(自動掛載工具):node

1.autofs概述:
使用mount命令或者經過啓動加載文件系統配置文件/etc/fstab進行掛載,不論使用與否都會將設備掛載到系統裏,而經過自動掛載能夠實現只有在訪問時系統纔會去掛載,一段時間不使用後系統會自動取消掛載;(自動取消掛載經過編輯/etc/sysconfig/autofs文件中的「TIMEOUT"選項)
######################################
2.autofs工具特色:
autofs工具與mount/umount的不一樣之處在於,它是一種守護程序。若是它檢測到用戶正試圖訪問一個還沒有掛載的文件系統,它就會自動檢測該文件系統。若是存在,那麼Autofs會自動將其掛載。另外一方面,若是它檢測到某個已經掛載的文件系統在一段時間內沒有被使用(默認300秒),那麼Autofs會自動將其卸載。所以運行了Autofs工具後,用戶就再也不須要手動完成文件系統的掛載和卸載動做;#######################################
3.autofs功能:
3.1完成本地目錄的自動掛載功能;
3.2完成遠程目錄到本地的自動掛載功能(映射遠程目錄到本地);
##############################################
4.autofs服務安裝以及配置文件:
root@shiyinyuan ~]# cat /etc/issue
CentOS release 6.3 (Final)
Kernel \r on an \m
#系統所使用的發行版本號CentOS 6.4;linux

[root@shiyinyuan ~]# rpm -qa | grep autofs
autofs-5.0.5-54.el6.i686
#在CentOS 6.4中默認安裝了autofs軟件包;服務器

[root@shiyinyuan ~]# yum info autofs
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Installed Packages
Name : autofs
Arch : i686
Epoch : 1
Version : 5.0.5
Release : 54.el6
Size : 3.0 M
Repo : installed
From repo : anaconda-CentOS-201207051201.i386
Summary : A tool for automatically mounting and unmounting filesystems
URL : http://wiki.autofs.net/
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.網絡

#軟件包的名稱、運行平臺,版本,大小,軟件包的下載連接和服務說明等;tcp

[root@shiyinyuan ~]# rpm -qc autofs | grep /etc
/etc/auto.master
/etc/auto.misc
/etc/auto.net
/etc/auto.smb
/etc/autofs_ldap_auth.conf
/etc/rc.d/init.d/autofs
/etc/sysconfig/autofs
#查看autofs服務的相關配置文件;
####################################################
5.autofs配置文件介紹:
1./etc/auto.master該文件是自動掛載服務的主配置文件,在文件中每一行能夠指定多個自動掛載的目錄且每行中須要指定一個已存在的目錄做爲自動掛載的主目錄,以及該主目錄中全部自動掛載子目錄的配置文件;定義了掛載的主目錄以及後續的mount動做。
備註:主目錄能夠手工建立,也能夠不建立等到autofs服務重啓動後自動建立。(建議手工)
2./etc/auto.misc 子目錄的配置文件;定義了掛載的子目錄以及被掛載的目錄(本地目錄或者是遠程服務器目錄)。關於掛載的子目錄無需手工指定,啓動autofs服務後自動生成;ide

例子1:[root@shiyinyuan ~]# grep /general /etc/auto.master
/general /etc/auto.man
返回的顯示信息分爲兩個部分:第一部分表示掛載的主目錄,第二個部分表示自動掛載子目錄的配置文件,定義了mount動做;工具

例子2:[root@shiyinyuan ~]# grep cd /etc/auto.misc
cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom
表示將/dev/cdrom 掛載到/misc/cd中;-fstype是一個可選項,用來代表所掛載的文件系統的類型和掛載選項;測試

3./etc/rc.d/init.d/autofs是autofs服務的啓動腳本文件,同時連接到了/etc/init.d/autofs文件;
4./etc/sysconfig/autofs是autofs服務的系統配置文件(全局配置),能夠修改自動卸載的時間值;
##################################################
6.案例演練
####################自動掛載本地目錄#############################
1.修改/etc/auto.master文件以下:
[root@shiyinyuan ~]# grep -v ^# /etc/auto.master
/misc /etc/auto.misc
/general /etc/auto.man #指定了一個主目錄/general
/net -hosts
+auto.master
2.創建自動掛載子配置文件(子配置文件名稱必須和主配置文件定義的名稱保持一致)
能夠經過系統提供的模板配置子配置文件/etc/auto.misc進行導入操做;
[root@shiyinyuan ~]# cp /etc/auto.misc /etc/auto.man
[root@shiyinyuan ~]# grep boss /etc/auto.man
boss -fstype=ext4 :/dev/sda6
#將本地磁盤掛載到/general/boss目錄中
3.啓動autofs服務
[root@shiyinyuan ~]# /etc/init.d/autofs restart
[root@shiyinyuan ~]# chkconfig autofs on
4.測試
[root@shiyinyuan ~]# cd /general/
[root@shiyinyuan general]# ll
total 0
############目錄是空的#################
切換到/general/boss目錄,看看是否自動掛載成功;
[root@shiyinyuan ~]# cd /general/
[root@shiyinyuan general]# ll
total 0
[root@shiyinyuan general]# cd boss
[root@shiyinyuan boss]# ll
total 16
drwx------. 2 root root 16384 Jul 21 15:27 lost+foundui

[root@shiyinyuan boss]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 ext4 9.9G 6.1G 3.4G 65% /
tmpfs tmpfs 504M 0 504M 0% /dev/shm
/dev/sda1 ext4 1008M 54M 903M 6% /boot
/dev/sda5 ext4 788M 17M 731M 3% /test
/dev/sda6 ext4 1016M 34M 932M 4% /general/boss.net

測試成功!!

#####################映射遠程服務器目錄#######################

環境信息:網絡中有FTP服務器提供匿名上傳和下載服務,NFS服務器提供目錄的共享服務;經過autofs功能映射到FTP服務器根目錄以及NFS服務器的共享目錄;(服務器IP地址10.1.210.12)

FTP服務器相關配置:
1.修改配置文件開啓匿名用戶上傳功能:
anonymous_enbale=YES 啓用匿名用戶
anon_upload_enable=YES 啓用匿名用戶上傳功能
anon_mkdir_write_enbale=YES 打開匿名用戶建立文件夾的功能

2.賦予匿名用戶上傳使用的文件夾以寫權限:
chmod 777 /var/ftp/pub 修改文件目錄權限爲777;
或者不改變權限的狀況下,指定文件的全部者chown ftp /var/ftp/pub

注意:不可將匿名用戶家目錄(/var/ftp)設置爲777權限,只能設置子目錄,不然vsftpd將禁止訪問匿名用戶的家目錄;
匿名用戶的家目錄:
[root@tangsir ~]# cat /etc/passwd | grep ftp
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin

3.啓動FTP服務以及開機運行
[root@www ~]# /etc/init.d/vsftpd restart
Shutting down vsftpd: [ OK ]
Starting vsftpd for vsftpd: [ OK ]
[root@www ~]# chkconfig vsftpd on

VSFTPD常見問題總結:
關於防火牆問題:
在INPUT鏈中寫入兩條規則運行ftp經過;
#iptables -A INPUT -p tcp --dport 20 -j ACCEPT
#iptables -A INPUT -p tcp --dport 21 -j ACCEPT
#service iptables save 注意要保存規則設置;

關於selinux的設置:(不解決這個問題ftp沒法創建數據鏈接)
1,查看ftp的布爾值;
getsebool -a | grep ftp
2,設置ftp服務具備寫權限的布爾值,使之永久生效;
setsebool -P allow_ftpd_anon_write on
3,設置上下文權限;
ls -Zd /var/ftp/pub
chcon -t public_content_rw_t /var/ftp/pub
4,重啓,reboot

在vsftpd服務中於Selinux有關的配置:
1.setsebool -P ftp_home_dir=1
當FTP受權用戶登陸到FTP服務器時容許vsftpd將用戶引導到用戶家目錄;
2.setsebool -P allow_ftpd_anon_write=1 ; chcon -R -t /var/ftp
表示容許隱名用戶上傳文件到vsftpd服務器上;

NFS服務器配置:
建立/etc/exports配置文件以下:
/cisco 10.1.210.0/24(rw,sync)

啓動服務:
/etc/init.d/rpc start
/etc/init.d/nfs start
chkconfig nfs on

##########

本地autofs服務配置信息(本地IP地址10.1.210.1)

1.修改/etc/auto.master文件以下:
[root@shiyinyuan ~]# grep -v ^# /etc/auto.master
/misc /etc/auto.misc
/general /etc/auto.man #指定了一個主目錄/general
/net -hosts
+auto.master
2.創建自動掛載自配置文件(子配置文件名稱必須和主配置文件定義的名稱保持一致)
能夠經過系統提供的模板配置子配置文件/etc/auto.misc進行導入操做;
[root@shiyinyuan ~]# cp /etc/auto.misc /etc/auto.man
[root@shiyinyuan ~]# grep nfs /etc/auto.man
nfs -fstype=nfs,rw 10.1.210.12:/cisco
[root@shiyinyuan ~]# grep pub /etc/auto.man
pub -ro,soft,intr 10.1.210.12:/var/ftp/pub

#將遠程目錄掛載到本地/general/pub目錄中;
3.啓動autofs服務
[root@shiyinyuan ~]# /etc/init.d/autofs restart
[root@shiyinyuan ~]# chkconfig autofs on
4.測試
[root@shiyinyuan ~]# cd /general/
[root@shiyinyuan general]# ll
total 0
[root@shiyinyuan general]# cd nfs
[root@shiyinyuan nfs]# ll
total 10080
-rw-r--r--. 1 nobody nobody 0 Jul 25 2014 cisco
-rw-r--r--. 1 nobody nobody 0 Jul 25 2014 h3c
-rw-------. 1 nobody nobody 10315662 Jul 25 2014 haoren.pdf
-rw-r--r--. 1 nobody nobody 0 Jul 25 2014 juniper
-rw-r--r--. 1 nobody nobody 71 Jul 25 2014 success.txt
-rw-r--r--. 1 nobody nobody 0 Jul 25 2014 Unix

##################測試成功#############################

相關文章
相關標籤/搜索