目的:
为局域网内 Linux 文件服务器提供容灾备份,需要将文件服务器中的文件备份到 Win10 机器
实验环境:
文件服务器:CentOS 7.9 IP:192.168.47.129,运行于VMware;
备 份 机:Win10 IP:192.168.47.1
一、 配置win10
1、开启win10中SMB功能
查找“启用或关闭 windows 功能”,调出“windows 功能”面板,勾选SMB三项内容,确定,重启电脑。
2、设置共享文件夹
右键点击“我的电脑”》》管理,选择“用户”》》右键点击右边空白处》》选择“新用户”。
创建新用户:backup,密码:123456
创建新文件夹share,在“共享”面板中打开“特定用户”,下拉选择用户backup,添加,设置backup权限为“读取/写入”,确定共享,完成共享设置。
3、在share文件夹中新建文件:win10.txt
二、配置CentOS
1、安装cifs
[root@localhost ~]# [root@localhost ~]# yum install -y cifs-utils
……
Installed:
cifs-utils.x86_64 0:6.2-10.el7
……
Complete!
2、挂载win10的共享文件夹share
[root@localhost ~]# mkdir /mnt/win_share
[root@localhost ~]# mount -t cifs -o username=backup,password=123456 //192.168.47.1/share/ /mnt/win_share
[root@localhost ~]# ll /mnt/win_share
总用量 0
-rwxr-xr-x 1 root root 0 8月 30 10:09 win10.txt
[root@localhost ~]#
出现win10.txt,表示成功挂载。
3、设置开机自动挂载
[root@localhost ~]# vi /etc/fstab
在最后插入一行:
//192.168.47.1/share/ /mnt/win_share cifs username=backup,password=123456 0 0
存盘退出。
输入reboot,重新启动CentOS。
输入命令:ls /mnt/win_share,出现win10.txt,表示开机自动挂载成功。
三、效果测试
1、在win10共享文件夹share中修改文件:win10.txt
保存后,在 CentOS中查看效果
[root@localhost ~]# cat /mnt/win_share/win10.txt
我来自win10共享文件夹share
[root@localhost ~]#
2、CentOS中添加文件:linux.txt
[root@localhost ~]# vim /mnt/win_share/linux.txt
我来自linux服务器文件夹/mnt/win_share
~
~
~
:wq
[root@localhost ~]# ll /mnt/win_share
总用量 1
-rwxr-xr-x 1 root root 48 8月 30 10:58 linux.txt
-rwxr-xr-x 1 root root 38 8月 30 10:51 win10.txt
[root@localhost ~]#
查看win10中效果
四、测试中遇到的坑
在win10中添加用户backup时,由于系统中默认的密码选项“用户下次登录时须更改密码”是勾选状态,没有改变,就确定了添加,挂载时出现错误,不成功。
[root@localhost ~]# mount -t cifs -o username=backup,password=123456 //192.168.47.1/share /mnt/win_share
mount error(127): Key has expired
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
处理方式是删除用户backup,再重新添加,确定前将密码选项改为“密码永不过期”