CentOS下使用autofs自动开机挂载共享文件

2017-11-25  本文已影响0人  沐辰老爹

第一步当然是安装各种需要的软件包

sudo yum install samba-client samba-common autofs 

完成后你应该会在/etc下发现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协议),该文件如果不存在则第四步中创建。

第三步创建文件夹

sudo mkdir /mnt/share_data  #即第二步中设置的本地路径

第四步创建并修改/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调用
://*.*.*.*/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,我们会发现一个folder_name的文件夹,进入并查看是否挂载成功

cd /mnt/share_data
ls
cd folder_name
ls
上一篇 下一篇

猜你喜欢

热点阅读