一.安装服务
#安装软件包
[root@cobbler downloads]# yum install -y samba samba-client samba-common
[root@cobbler downloads]# systemctl enable smb nmb
Created symlink from /etc/systemd/system/multi-user.target.wants/smb.service to /usr/lib/systemd/system/smb.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/nmb.service to /usr/lib/systemd/system/nmb.service.
#启动smb/nmb服务并加入开机自启动
[root@cobbler downloads]# systemctl start smb nmb
[root@cobbler downloads]# systemctl status smb nmb
#查看smb/nmb的监听端口是否打开(smb服务端口TCP:139/445,nmb服务端口UDP:137/138)
[root@cobbler home]# netstat -anlpt |grep smb
tcp 0 0 0.0.0.0:139 0.0.0.0:* LISTEN 18825/smbd
tcp 0 0 0.0.0.0:445 0.0.0.0:* LISTEN 18825/smbd
tcp6 0 0 :::139 :::* LISTEN 18825/smbd
tcp6 0 0 :::445 :::* LISTEN 18825/smbd
[root@cobbler home]# netstat -anlpu | grep nmb
udp 0 0 172.17.255.255:137 0.0.0.0:* 18823/nmbd
udp 0 0 172.17.0.1:137 0.0.0.0:* 18823/nmbd
udp 0 0 192.168.28.255:137 0.0.0.0:* 18823/nmbd
udp 0 0 192.168.28.150:137 0.0.0.0:* 18823/nmbd
udp 0 0 0.0.0.0:137 0.0.0.0:* 18823/nmbd
udp 0 0 172.17.255.255:138 0.0.0.0:* 18823/nmbd
udp 0 0 172.17.0.1:138 0.0.0.0:* 18823/nmbd
udp 0 0 192.168.28.255:138 0.0.0.0:* 18823/nmbd
udp 0 0 192.168.28.150:138 0.0.0.0:* 18823/nmbd
udp 0 0 0.0.0.0:138 0.0.0.0:* 18823/nmbd
[root@cobbler home]# history
#防火墙iptables(docker使用)放行端口
[root@cobbler home]# iptables -A INPUT -p tcp --dport 443 -j ACCEPT
[root@cobbler home]# iptables -A INPUT -p tcp --dport 137 -j ACCEPT
[root@cobbler home]# iptables -A INPUT -p tcp --dport 138 -j ACCEPT
[root@cobbler home]# iptables -A INPUT -p tcp --dport 139 -j ACCEPT
[root@cobbler home]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
[root@cobbler home]# systemctl restart iptables.service
[root@cobbler home]# systemctl status iptables.service
● iptables.service - IPv4 firewall with iptables
Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled; vendor preset: disabled)
Active: active (exited) since Fri 2019-08-09 10:14:42 CST; 11s ago
Process: 19228 ExecStop=/usr/libexec/iptables/iptables.init stop (code=exited, status=0/SUCCESS)
Process: 19290 ExecStart=/usr/libexec/iptables/iptables.init start (code=exited, status=0/SUCCESS)
Main PID: 19290 (code=exited, status=0/SUCCESS)
Aug 09 10:14:42 cobbler systemd[1]: Starting IPv4 firewall with iptables...
Aug 09 10:14:42 cobbler iptables.init[19290]: iptables: Applying firewall rules: [ OK ]
Aug 09 10:14:42 cobbler systemd[1]: Started IPv4 firewall with iptables.
#创建共享目录以及添加用户
[root@cobbler downloads]# useradd turing
[root@cobbler downloads]# id turing
uid=1001(turing) gid=1001(turing) groups=1001(turing)
[root@cobbler downloads]# smbpasswd -a turing
New SMB password:
Retype new SMB password:
Added user turing.
#检测用户是否添加成功
[root@cobbler downloads]# pdbedit -L
turing:1001:
#给共享目录755权限授权
[root@cobbler home]# chmod -R 755 /home/downloads/
#修改配置文件
#检查配置文件语法
[root@cobbler home]# 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 "[downloads]"
Loaded services file OK.
Server role: ROLE_STANDALONE
#重启smb/nmb服务
[root@cobbler home]# systemctl restart smb nmb