一、安装cifs-utils

sudo yum -y install cifs-utils

二、挂载远程samba共享

mount -t cifs //ip/*** /root/*** -o vers=2.0,username=用户名,password=密码,file_mode=0777,dir_mode=0777
  • //ip/*** 远程目录
  • /root/*** 本地目录(需要本地存在该目录)
  • username 用户名
  • password 密码
  • file_mode 文件权限
  • dir_mode 目录权限

即可挂载远程共享目录

三、设置开机自动挂载

编辑文件/etc/rc.d/rc.local

sudo vim /etc/rc.d/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local

将挂载命令添加到文件中,然后保存退出。

在centos7中/etc/rc.d/rc.local文件权限被降低了,因此需要为其添加执行权限

sudo chmod +x /etc/rc.d/rc.local

这样即可实现开机自动挂载远程目录。

最后更新于 2023-07-15