前言
近期因爲工作上需要頻繁在不同系統平臺之間分享文件,故需要部署一個文件共享服務器,一開始考慮了採用FTP服務器,但是部署了之後總有莫名其妙的權限和文件損壞的問題,所以後來決定採用多服務的方式進行文件共享,包含http單下載服務,samba多功能服務,下面開始配置samba
1、安裝服務
1、1、部署環境信息
1.2、配置源
1.3、開始安裝
yum install samba -y
2、配置服務
2.1、配置匿名訪問
2.1.1、看一下原配置文件
[root@localhost ~]# cat /etc/samba/smb.conf
# See smb.conf.example for a more detailed config file or
# read the smb.conf manpage.
# Run 'testparm' to verify the config is correct after
# you modified it.
[global]
workgroup = SAMBA
security = user
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
[homes]
comment = Home Directories
valid users = %S, %D%w%S
browseable = No
read only = No
inherit acls = Yes
[printers]
comment = All Printers
path = /var/tmp
printable = Yes
create mask = 0600
browseable = No
[print$]
comment = Printer Drivers
path = /var/lib/samba/drivers
write list = @printadmin root
force group = @printadmin
create mask = 0664
directory mask = 0775
2.1.2、配置全局參數
使用vim命令進入配置文件進行編輯,找到全局配置
[global]
workgroup = SAMBA
security = user
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
然後插入一段內容
map to guest = bad user
效果如下
[global]
workgroup = SAMBA
security = user
map to guest = bad user
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
2.1.3、添加共享路徑
在配置文件的最下面添加下的參數
[share]
comment = this share dir
path = /share
writeable = yes
browseable = yes
guest ok = yes
- comment = this share dir ##對此共享配置信息的描述(可自定義)
- path = /share #共享路徑(可自定義)
添加完成之後就可以保存了,保存之後內容如下
[global]
workgroup = SAMBA
security = user
map to guest = bad user
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
[homes]
comment = Home Directories
valid users = %S, %D%w%S
browseable = No
read only = No
inherit acls = Yes
[printers]
comment = All Printers
path = /var/tmp
printable = Yes
create mask = 0600
browseable = No
[print$]
comment = Printer Drivers
path = /var/lib/samba/drivers
write list = @printadmin root
force group = @printadmin
create mask = 0664
directory mask = 0775
[share]
comment = this share dir
path = /share
writeable = yes
browseable = yes
guest ok = yes
2.1.4、配置權限
從上面的配置中可得知,此時的共享路徑是
/share/
所以現在要新建此路徑,並配置相關權限(請依次執行一下指令)
mkdir -p /share
chown nobody:nobody /share/
chmod -R 777 /share/
sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/sysconfig/selinux
sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
systemctl stop firewalld
setenforce 0
2.1.5、啓動服務
systemctl restart smb nmb
2.1.6、驗證
按win+R運行指令
\\192.168.0.111
回車,此時已成功進入共享
然後嘗試上傳文件,成功