參考:https://www.cnblogs.com/muscleape/p/6385583.html
分幾步走:
- 防火牆關閉
[[email protected] ~]$ systemctl stop firewalld.service
[[email protected] ~]$ systemctl disable firewalld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
- 檢視SeLinux狀态
臨時關閉SeLinux[[email protected] ~]$ sestatus SELinux status: enabled SELinuxfs mount: /sys/fs/selinux SELinux root directory: /etc/selinux Loaded policy name: targeted Current mode: enforcing Mode from config file: enforcing Policy MLS status: enabled Policy deny_unknown status: allowed Max kernel policy version: 28
[[email protected] ~]# setenforce 0
永久關閉SeLinux,需要重新開機機器
修改配置檔案/etc/selinux/config,将SELINU置為disabled
- 安裝samba服務
檢視安裝結果:[[email protected] ~]$ sudo yum install samba 已加載插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com 正在解決依賴關系 .............................. 不再贅述
檢視samba狀态:[[email protected] ~]$ rpm -qa | grep samba samba-common-4.8.3-6.el7_6.noarch samba-common-tools-4.8.3-6.el7_6.x86_64 samba-client-libs-4.8.3-6.el7_6.x86_64 samba-4.8.3-6.el7_6.x86_64 samba-common-libs-4.8.3-6.el7_6.x86_64 samba-client-4.8.3-6.el7_6.x86_64 samba-libs-4.8.3-6.el7_6.x86_64
啟動samba,并再次檢視:[[email protected] ~]$ service smb status Redirecting to /bin/systemctl status smb.service ● smb.service - Samba SMB Daemon Loaded: loaded (/usr/lib/systemd/system/smb.service; disabled; vendor preset: disabled) Active: inactive (dead) Docs: man:smbd(8) man:samba(7) man:smb.conf(5)
設定samba開機自啟動:[[email protected] ~]$ systemctl start smb [[email protected] ~]$ service smb status Redirecting to /bin/systemctl status smb.service ● smb.service - Samba SMB Daemon Loaded: loaded (/usr/lib/systemd/system/smb.service; disabled; vendor preset: disabled) Active: active (running) since 一 2019-09-16 14:07:00 CST; 14s ago Docs: man:smbd(8) man:samba(7) man:smb.conf(5) Main PID: 45643 (smbd) Status: "smbd: ready to serve connections..." CGroup: /system.slice/smb.service ├─45643 /usr/sbin/smbd --foreground --no-process-group ├─45649 /usr/sbin/smbd --foreground --no-process-group ├─45650 /usr/sbin/smbd --foreground --no-process-group └─45652 /usr/sbin/smbd --foreground --no-process-group 9月 16 14:07:00 localhost.localdomain systemd[1]: Starting Samba SMB Daemon... 9月 16 14:07:00 localhost.localdomain smbd[45643]: [2019/09/16 14:07:00.4849... 9月 16 14:07:00 localhost.localdomain systemd[1]: Started Samba SMB Daemon. 9月 16 14:07:00 localhost.localdomain smbd[45643]: daemon_ready: STATUS=da... Hint: Some lines were ellipsized, use -l to show in full.
[[email protected] ~]$ systemctl enable smb Created symlink from /etc/systemd/system/multi-user.target.wants/smb.service to /usr/lib/systemd/system/smb.service.
-
再來就是搞samba配置檔案
配置檔案是/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 workgroup = MYGROUP server string = Samba Server Version %v log file = /var/log/samba/log.%m max log size = 50 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 [zuoypshare] comment = zuoyp share path = /mnt/data/zuoyp browseable = yes writeable = yes guest ok = yes public = yes
各個參數的含義大家可以自行查資料,這裡僅提供配置檔案内容。
其中最後一項[zuoypshare]是我自己添加的,我的共享目錄的内容,包括comment—注釋,path—路徑等等。其中這個path就是你使用samba通路的共享檔案夾。另外,這個[zuoypshare]字段要留意下,後面使用windows下映射磁盤時需要它的名字。
你可以在/mnt/data/zuoyp這個目錄下,随便touch幾個檔案,等會友善看。
比如:
搞定後,重新開機samba服務,檢視狀态centos7下搭建samba
測試smb.conf配置是否正确[[email protected] zuoyp]$ systemctl restart smb [[email protected] zuoyp]$ systemctl status smb
[[email protected] zuoyp]$ testparm Load smb config files from /etc/samba/smb.conf rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384) Processing section "[homes]" Processing section "[printers]" Processing section "[print$]" Processing section "[zuoypshare]" Loaded services file OK. Server role: ROLE_STANDALONE Press enter to see a dump of your service definitions # Global parameters [global] log file = /var/log/samba/log.%m max log size = 50 printcap name = cups security = USER server string = Samba Server Version %v workgroup = MYGROUP idmap config * : backend = tdb cups options = raw [homes] browseable = No comment = Home Directories inherit acls = Yes read only = No valid users = %S %D%w%S [printers] browseable = No comment = All Printers create mask = 0600 path = /var/tmp printable = Yes [print$] comment = Printer Drivers create mask = 0664 directory mask = 0775 force group = @printadmin path = /var/lib/samba/drivers write list = @printadmin root [zuoypshare] comment = zuoyp share guest ok = Yes path = /mnt/data/zuoyp read only = No [[email protected] zuoyp]$ smbc smbcacls smbclient smbcontrol smbcquotas [[email protected] zuoyp]$ smbc smbcacls smbclient smbcontrol smbcquotas
下一步就是在windows下映射了,但在這之前你必須要做一件事:
為你的目前使用者配置samba密碼:
如果你不做這一步,那麼你在映射輸入密碼時,就會一直提示密碼錯誤。[[email protected] zuoyp]$ sudo smbpasswd -a zuoyp [sudo] zuoyp 的密碼: New SMB password: Retype new SMB password: Added user zuoyp.
- windows下映射驅動器
centos7下搭建samba xx.xx.xx.xx是你虛拟機的ip位址,zuoypshare就是上面說到的samba配置時的标簽名。然後點選完成,輸入你上一步設定的使用者名和samba密碼即可通路啦。centos7下搭建samba centos7下搭建samba