CentOS下使用autofs自動開機掛載共享文件

第一步當(dāng)然是安裝各種需要的軟件包

sudo yum install samba-client samba-common autofs 

完成后你應(yīng)該會在/etc下發(fā)現(xiàn)auto.cifs auto.master或者auto.smb

第二步配置auto.master文件

#
# Sample auto.master file
# This is a 'master' automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
#
/misc   /etc/auto.misc
#
# NOTE: mounts done from a hosts map will be mounted with the
#   "nosuid" and "nodev" options unless the "suid" and "dev"
#   options are explicitly given.
#
/net    -hosts
#
# Include /etc/auto.master.d/*.autofs
# The included files must conform to the format of this file.
#
+dir:/etc/auto.master.d
#
# Include central master map if it can be found using
# nsswitch sources.
#
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.
#
+auto.master
#############################################################
/mnt/share_data /etc/auto.cifs --timeout=600 --ghost

注意添加最后一行;/mnt/share_data代表掛載的本地路徑,/etc/auto.cifs以cifs形式自動掛載windows共享(一般而言windows共享使用的是cifs協(xié)議),該文件如果不存在則第四步中創(chuàng)建。

第三步創(chuàng)建文件夾

sudo mkdir /mnt/share_data  #即第二步中設(shè)置的本地路徑

第四步創(chuàng)建并修改/etc/auto.cifs

# 添加一行
folder_name -fstype=cifs,rw,noperm,credentials=/etc/my_cred.txt ://*.*.*.*/share

folder_name即在本地的/mnt/share_data目錄下的文件夾名稱,未來該目錄則為掛載的具體目錄
credentials=/etc/my_cred.txt一般windows共享需要用戶名密碼,為了方便我們不講用戶名密碼直接寫入文件,而是另存到其他文件由auto.cifs調(diào)用
://*.*.*.*/share為windows的共享地址及目錄

第五步配置用戶名密碼文件

sudo vim /etc/my_cred.txt

# add those lines
-----------
# /etc/my_cred.txt
username=your_username
password=your_password

第六步重啟查看是否掛載成功

sudo service autofs restart

完成上述步驟,進入/mnt/share_data,我們會發(fā)現(xiàn)一個folder_name的文件夾,進入并查看是否掛載成功

cd /mnt/share_data
ls
cd folder_name
ls
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容