Debian配置SMB服务-lnxserver3

文章目录

  • 赛题
      • 2.3.4、配置SMB服务
  • 1.安装服务
  • 2.添加samba用户配置权限
  • 3.修改配置文件并重启服务
  • 4.用户权限测试
  • 5.数据库定时备份到目录
    • 1、挂载lnxserver3备份目录
    • 2、创建定时计划
    • 3、验证测试

赛题

2.3.4、配置SMB服务

· 安装Samba组件

· 创建Samba共享目录为/var/skills46,共享名为skills46;

· user01,user02,用户都能通过输入用户名和密码(Skills46)登录并访问共享文件夹;

· user01能够查看和删除所有人的文件;user02能够查看所有人的文件,但不能删除别人的文件;

· 通过物理机访问共享目录,根据配置上传,下载文件进行测试操作;

· lnxserver1 数据库备份文件每天定时复制到/var/skills46/backup。

1.安装服务

root@lnxserver3:~# apt install -y samba smbclient

2.添加samba用户配置权限

root@lnxserver3:~# useradd user01
root@lnxserver3:~# useradd user02
root@lnxserver3:~# smbpasswd -a user01
New SMB password:
Retype new SMB password:
Added user user01.
root@lnxserver3:~# smbpasswd -a user02
New SMB password:
Retype new SMB password:
Added user user02.
root@lnxserver3:~# mkdir -p /var/skills46/backup
root@lnxserver3:~# chmod 777 -R /var/skills46
root@lnxserver3:~# chmod o+t -R /var/skills46
root@lnxserver3:~# chown user01 -R /var/skills46/

3.修改配置文件并重启服务

root@lnxserver3:~# vim /etc/samba/smb.conf
[skills46]
        path = /var/skills46
        writeable = yes
        valid users = user01,user02
root@lnxserver3:~# systemctl restart smbd.service 

4.用户权限测试

root@lnxserver3:~# smbclient //127.0.0.1/skills46 -U user01
Enter WORKGROUP\user01's password: 
Try "help" to get a list of possible commands.
smb: \> mkdir user01test
smb: \> ls
  .                                   D        0  Tue Feb 14 06:31:44 2023
  ..                                  D        0  Tue Feb 14 06:25:55 2023
  user01test                          D        0  Tue Feb 14 06:31:44 2023

                19525456 blocks of size 1024. 14535904 blocks available
smb: \> q
root@lnxserver3:~# smbclient //127.0.0.1/skills46 -U user02
Enter WORKGROUP\user02's password: 
Try "help" to get a list of possible commands.
smb: \> ls
  .                                   D        0  Tue Feb 14 06:31:44 2023
  ..                                  D        0  Tue Feb 14 06:25:55 2023
  user01test                          D        0  Tue Feb 14 06:31:44 2023

                19525456 blocks of size 1024. 14535904 blocks available
smb: \> rmdir user01test\
NT_STATUS_ACCESS_DENIED removing remote directory file \user01test\
smb: \> 

5.数据库定时备份到目录

如何挂载samba 分区?

[Copy to clipboard]CODE:# mkdir /mnt/share

mount -t smbfs -o username=root,password=abc,codepage=936,

iocharset=gb2312 //192.168.1.100/share /mnt/share

如果中文显示不正常请尝试UTF-8编码。当然可以写到fstab中实现自动挂载。

1、挂载lnxserver3备份目录

root@lnxserver1:~# mkdir /mnt/backup
root@lnxserver1:~# apt install -y cifs-utils
root@lnxserver1:~# mount -o username=user01,password=Skills46 //172.0.10.122/skills46/backup /mnt/backup/      
root@lnxserver1:~# df -Th
Filesystem                     Type      Size  Used Avail Use% Mounted on
//172.0.10.122/skills46/backup cifs       19G  4.8G   14G  26% /mnt/backup

2、创建定时计划

root@lnxserver1:~# vim /mysqlbk.sh 
mysqldump -uroot -pSkills46 wordpress > /var/www/backup/"`date +%Y%m%d%H%M%S`".sql
mount -o username=user01,password=Skills46 //172.0.10.122/skills46/backup /mnt/backup/
cp -a /var/www/backup/"`date +%Y%m%d%H%M%S`".sql /mnt/backup/
root@lnxserver1:~# vim /etc/crontab 
0  0    * * *   root    /mysqlbk.sh

3、验证测试

手动执行查看测试

root@lnxserver1:~# sh /mysqlbk.sh 
mount: /mnt/backup: //172.0.10.122/skills46/backup already mounted on /mnt/backup.
root@lnxserver1:~# ls -l /var/www/backup/
-rw-r--r-- 1 root root 46155 Feb 16 15:23 20230216152353.sql
root@lnxserver1:~# ls -l /mnt/backup/
total 1024
-rwxr-xr-x 1 root root 46155 Feb 14 20:24 20230216152353.sql
root@lnxserver3:~# ls -l /var/skills46/backup/
total 48
-rwxr----- 1 user01 user01 46155 Feb 14 07:24 20230216152353.sql
root@lnxserver3:~# 

你可能感兴趣的:(服务器,网络,运维,linux)