在PVE上部署SMB服务

有些朋友喜欢在PVE上安装黑群晖当文件服务器。由于中间隔了VMM,个人觉得性能太低。还是喜欢直接在pve主机上安装smb文件共享服务。

1、安装samba服务

apt update && apt install samba -y

2、设置配置文件

可以在/etc/samba/smb.conf末尾中添加

#添加一个iso共享库
[iso]                                  //此处是路径,例如//10.13.14.2/iso
   comment = this is a iso             //描述
   path =  /var/lib/vz/template        //共享的文件夹
   guest ok = no                       //不允许访客
   browseable = no                     //不允许浏览
   write list = root                   //运行root读写

懒人可以一键开启

cat >>/etc/samba/smb.conf <<EOF
[iso]                                 
   comment = this is a iso           
   path =  /var/lib/vz/template   
   guest ok = no                   
   browseable = no                  
   write list = root 
EOF

3、添加用户

smbpasswd -a root

4、重启smb服务

systemctl restart smbd 

5、验证

6、如果不想使用root用户

在实际环境中,可能 有多个用户,当然不能将root共享出去。

6.1 新建账户

#新增系统用户
useradd smbuser1
useradd smbuser2
useradd smbuser3

#新增smb用户
smbpasswd -a smbuser1
smbpasswd -a smbuser2
smbpasswd -a smbuser3

6.2 创建共享文件夹

mkdir /var/smb/smbuser1 -p
mkdir /var/smb/smbuser2 -p
mkdir /var/smb/smbuser3 -p

并且在目录里面,创建文件

6.3 修改文件夹权限

chown -R smbuser1 /var/smb/smbuser1/
chown -R smbuser2 /var/smb/smbuser2/
chown -R smbuser3 /var/smb/smbuser3/

6.4 添加配置文件

在 /etc/samba/smb.conf 中添加

[smbuser1]                                 
   comment = smbuser1  files           
   path =  /var/smb/smbuser1  
   guest ok = no                   
   browseable = no                  
   write list = smbuser1

[smbuser2]                                 
   comment = smbuser2  files           
   path =  /var/smb/smbuser2  
   guest ok = no                   
   browseable = no                  
   write list = smbuser2

[smbuser3]                                 
   comment = smbuser3  files           
   path =  /var/smb/smbuser3  
   guest ok = no                   
   browseable = no                  
   write list = smbuser3
cat >> /etc/samba/smb.conf <<EOF
[smbuser1]                                 
   comment = smbuser1  files           
   path =  /var/smb/smbuser1  
   guest ok = no                   
   browseable = no                  
   write list = smbuser1

[smbuser2]                                 
   comment = smbuser2  files           
   path =  /var/smb/smbuser2  
   guest ok = no                   
   browseable = no                  
   write list = smbuser2

[smbuser3]                                 
   comment = smbuser3  files           
   path =  /var/smb/smbuser3  
   guest ok = no                   
   browseable = no                  
   write list = smbuser3
EOF
#重启服务
systemctl restart smbd 

6.5 验证一下

搭建好的速度

Author: 佛西

Leave a Reply

Your email address will not be published.