安装centos系统
打开终端,然后su切换到root
[www@localhost ~]$ su
Password:
[root@localhost www]#
[root@localhost www]#
安装samba软件包
yum install samba
注意安装过程中需要两次输入y确认安装
[root@localhost www]# yum install samba
CentOS Linux 8 - AppStream 5.2 MB/s | 8.2 MB 00:01
CentOS Linux 8 - BaseOS 3.0 MB/s | 3.5 MB 00:01
CentOS Linux 8 - Extras 15 kB/s | 10 kB 00:00
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
samba x86_64 4.14.5-2.el8 baseos 847 k
Installing dependencies:
samba-common-tools x86_64 4.14.5-2.el8 baseos 499 k
samba-libs x86_64 4.14.5-2.el8 baseos 169 k
Transaction Summary
================================================================================
Install 3 Packages
Total download size: 1.5 M
Installed size: 4.0 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): samba-libs-4.14.5-2.el8.x86_64.rpm 472 kB/s | 169 kB 00:00
(2/3): samba-common-tools-4.14.5-2.el8.x86_64.r 1.2 MB/s | 499 kB 00:00
(3/3): samba-4.14.5-2.el8.x86_64.rpm 1.9 MB/s | 847 kB 00:00
--------------------------------------------------------------------------------
Total 1.9 MB/s | 1.5 MB 00:00
CentOS Linux 8 - BaseOS 1.6 MB/s | 1.6 kB 00:00
Importing GPG key 0x8483C65D:
Userid : "CentOS (CentOS Official Signing Key) <security@centos.org>"
Fingerprint: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65D
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : samba-libs-4.14.5-2.el8.x86_64 1/3
Installing : samba-common-tools-4.14.5-2.el8.x86_64 2/3
Installing : samba-4.14.5-2.el8.x86_64 3/3
Running scriptlet: samba-4.14.5-2.el8.x86_64 3/3
Verifying : samba-4.14.5-2.el8.x86_64 1/3
Verifying : samba-common-tools-4.14.5-2.el8.x86_64 2/3
Verifying : samba-libs-4.14.5-2.el8.x86_64 3/3
Installed:
samba-4.14.5-2.el8.x86_64 samba-common-tools-4.14.5-2.el8.x86_64
samba-libs-4.14.5-2.el8.x86_64
Complete!
配置samba共享文件smb.conf
修改/etc/samba/smb.conf,在文件结尾增加以下配置
[www]
comment = shared
path = /home/www
writeable = yes
public = yes
添加samba账户
smbpasswd -a www
注意www为samba登陆账户,www一定要是系统的账户,如果不存在无法访问
[root@localhost www]# smbpasswd -a www
New SMB password:
Retype new SMB password:
Added user www.
[root@localhost www]#
关闭系统防火墙
查看当前防火墙状态
systemctl status firewalld.service
[root@localhost www]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor p>
Active: active (running) since Sun 2021-12-05 12:09:05 CST; 3min 38s ago
Docs: man:firewalld(1)
Main PID: 1127 (firewalld)
Tasks: 2 (limit: 11087)
Memory: 23.0M
CGroup: /system.slice/firewalld.service
└─1127 /usr/libexec/platform-python -s /usr/sbin/firewalld --nofork >
Dec 05 12:09:04 localhost.localdomain systemd[1]: Starting firewalld - dynamic >
Dec 05 12:09:05 localhost.localdomain systemd[1]: Started firewalld - dynamic f>
Dec 05 12:09:05 localhost.localdomain firewalld[1127]: WARNING: AllowZoneDrifti>
[root@localhost www]#
关闭防火墙
systemctl stop firewalld.service
禁用防火墙开机启动
systemctl disable firewalld.service
root@localhost www]# systemctl disable firewalld.service
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
确认防火墙关闭
systemctl status firewalld.service
[root@localhost www]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor >
Active: inactive (dead)
Docs: man:firewalld(1)
Dec 05 12:09:04 localhost.localdomain systemd[1]: Starting firewalld - dynamic >
Dec 05 12:09:05 localhost.localdomain systemd[1]: Started firewalld - dynamic f>
Dec 05 12:09:05 localhost.localdomain firewalld[1127]: WARNING: AllowZoneDrifti>
Dec 05 12:13:06 localhost.localdomain systemd[1]: Stopping firewalld - dynamic >
Dec 05 12:13:06 localhost.localdomain systemd[1]: firewalld.service: Succeeded.
Dec 05 12:13:06 localhost.localdomain systemd[1]: Stopped firewalld - dynamic f>
lines 1-11/11 (END)
显示Stopping firewalld 和 disabled表示关闭成功
关闭selinux
编辑/etc/selinux/config文件(重启才会生效)
将SELINUX=enforcing修改为SELINUX=disabled
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
使用指令关闭selinux(立即生效)
setenforce 0
启动samba服务
systemctl start smb
或者
systemctl restart smb
注意:
最好使用restart
查看samba状态
systemctl status smb.service
[root@localhost www]# systemctl status smb.service
● smb.service - Samba SMB Daemon
Loaded: loaded (/usr/lib/systemd/system/smb.service; disabled; vendor preset>
Active: active (running) since Sun 2021-12-05 12:19:54 CST; 24min ago
Docs: man:smbd(8)
man:samba(7)
man:smb.conf(5)
Main PID: 44694 (smbd)
Status: "smbd: ready to serve connections..."
Tasks: 5 (limit: 11087)
Memory: 13.3M
CGroup: /system.slice/smb.service
├─44694 /usr/sbin/smbd --foreground --no-process-group
├─44701 /usr/sbin/smbd --foreground --no-process-group
├─44702 /usr/sbin/smbd --foreground --no-process-group
├─44706 /usr/sbin/smbd --foreground --no-process-group
└─44711 /usr/sbin/smbd --foreground --no-process-group
Dec 05 12:19:54 localhost.localdomain systemd[1]: smb.service: Succeeded.
Dec 05 12:19:54 localhost.localdomain systemd[1]: Stopped Samba SMB Daemon.
Dec 05 12:19:54 localhost.localdomain systemd[1]: Starting Samba SMB Daemon...
Dec 05 12:19:54 localhost.localdomain smbd[44694]: [2021/12/05 12:19:54.473850,>
Dec 05 12:19:54 localhost.localdomain systemd[1]: Started Samba SMB Daemon.
Dec 05 12:19:54 localhost.localdomain smbd[44694]: daemon_ready: daemon 'smbd>
lines 1-23/23 (END)
windows访问测试
WIN+r键弹出如下界面,输入samba服务器所在地址
回车之后,看到共享文件夹
双击www文件夹,输入用户名和密码,用户名为www
至此,samba服务器搭建完成