1. 创建挂载脚本
root@oms:~# nano /etc/init.d/mount-cifs2.sh #!/bin/bash # 定义挂载参数 CIFS_SERVER=//192.168.180.3/bjyzj/kf/photos/U8Photos MOUNT_POINT=/usr/u8files/U8Photos USERNAME=devuser1 PASSWORD2=$(cat /etc/secrets/cifs-password2) # 检查挂载点是否存在,如果不存在则创建 if [ ! -d "$MOUNT_POINT" ]; then mkdir -p "$MOUNT_POINT" fi # 尝试挂载CIFS共享 mount -t cifs "$CIFS_SERVER" "$MOUNT_POINT" -o username="$USERNAME",password="$PASSWORD2",file_mode=0777,dir_mode=0777 # 检查挂载是否成功 if [ $? -eq 0 ]; then echo "CIFS共享已成功挂载到 $MOUNT_POINT" else echo "挂载CIFS共享失败" fi
2. 设置密码文件
# 创建一个包含密码的文件 echo '********' > /etc/secrets/cifs-password2 # 使用chattr命令保护文件,使其不可变 sudo chattr +i /etc/secrets/cifs-password2 # 在你的脚本中读取密码 PASSWORD2=$(cat /etc/secrets/cifs-password2)
3. 使用systemd管理脚本
root@oms:~# nano /etc/systemd/system/mount-cifs2.service [Unit] Description=Mount CIFS Share at boot After=network.target [Service] Type=simple ExecStart=/etc/init.d/mount-cifs2.sh Restart=on-failure [Install] WantedBy=multi-user.target
4. 重新加载systemd
配置
root@oms:~# systemctl daemon-reload
5. 创建 \usr\u8files\U8Photos 目录
root@oms:~# mkdir -p \usr\u8files\U8Photos
6. 启动服务并设置为开机自启
root@oms:~# systemctl enable --now mount-cifs2
标签:CIFS,POINT,mount,oms,etc,开机,挂载,看牙 From: https://www.cnblogs.com/linuxgg/p/18770236