安装samba服务器有两种方法:通过rpm包安装、通过yum安装,本文中使用rpm包安装,当然也会介绍怎么通过yum安装。
推荐使用yum安装,省心方便!
系统:CentOS Linux release 7.6.1810 (Core)
挂载磁盘镜像到 /mnt/cdrom
目录
[root@192 thrfur]# mkdir /mnt/cdrom
[root@192 thrfur]# mount -t auto /dev/cdrom /mnt/cdrom
mount: /dev/sr0 is write-protected, mounting read-only
[root@192 thrfur]#
需要以下安装包才能使用samba服务:
samba-4.8.3-4.el7.x86_64.rpm
//服务器端软件,主要提供samba服务器的守护程序,共享文档,日志的轮替
samba-common-4.8.3-4.el7.noarch.rpm
//主要提供samba服务器的设置文件与设置文件语法检验程序testparm
samba-client-4.8.3-4.el7.x86_64.rpm
//客户端软件,主要提供linux主机作为客户端时,所需要的工具指令集
samba-common-tools-4.8.3-4.el7.x86_64.rpm
查询一下本机是否安装了samba:
[root@192 thrfur]# rpm -qa | grep samba
samba-common-4.8.3-4.el7.noarch
samba-client-libs-4.8.3-4.el7.x86_64
samba-common-libs-4.8.3-4.el7.x86_64
samba-client-4.8.3-4.el7.x86_64
samba-common-tools-4.8.3-4.el7.x86_64
[root@192 thrfur]#
可以看到本机安装了所需安装包的其中两个,也就是我只需要安装 samba-4.8.3-4.el7.x86_64.rpm
就可以了
查询一下磁盘镜像内的安装包:
[root@192 thrfur]# cd /mnt/cdrom/Packages
[root@192 Packages]# ls *samba*
samba-4.8.3-4.el7.x86_64.rpm
samba-client-4.8.3-4.el7.x86_64.rpm
samba-client-libs-4.8.3-4.el7.x86_64.rpm
samba-common-4.8.3-4.el7.noarch.rpm
samba-common-libs-4.8.3-4.el7.x86_64.rpm
samba-common-tools-4.8.3-4.el7.x86_64.rpm
samba-krb5-printing-4.8.3-4.el7.x86_64.rpm
samba-libs-4.8.3-4.el7.x86_64.rpm
samba-python-4.8.3-4.el7.x86_64.rpm
samba-winbind-4.8.3-4.el7.x86_64.rpm
samba-winbind-modules-4.8.3-4.el7.x86_64.rpm
[root@192 Packages]#
好了,有我们需要的安装包,下面逐一开始安装所需要的安装包:
[root@192 Packages]# rpm -ivh samba-4.8.3-4.el7.x86_64.rpm
warning: samba-4.8.3-4.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
error: Failed dependencies:
libxattr-tdb-samba4.so()(64bit) is needed by samba-0:4.8.3-4.el7.x86_64
libxattr-tdb-samba4.so(SAMBA_4.8.3)(64bit) is needed by samba-0:4.8.3-4.el7.x86_64
samba-common-tools = 4.8.3-4.el7 is needed by samba-0:4.8.3-4.el7.x86_64
samba-libs = 4.8.3-4.el7 is needed by samba-0:4.8.3-4.el7.x86_64
[root@192 Packages]#
这是出错了吗?是的,缺少依赖。解决办法就是加一个 --nodeps
参数阻止检查依赖:
[root@192 Packages]# rpm -ivh --nodeps samba-4.8.3-4.el7.x86_64.rpm
warning: samba-4.8.3-4.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:samba-0:4.8.3-4.el7 ################################# [100%]
[root@192 Packages]#
安装完成。现在就可以开始进入配置samba服务的过程了。在配置samba服务之前,我再介绍如何通过yum安装samba服务。
//使用yum安装samba服务
[root@192 thrfur]# yum -y install samba samba-common samba-client
好了,下面开始进入samba服务的配置。
编辑 /etc/samba/smb.conf
文件,在末尾添加如下内容:
[thrfur]
comment = thrfur.com //描述
path = /home/thrfur //samba目录
public = yes //公开
browseable = yes //共享目录可被浏览
writeable = yes //可写
保存后退出,下面讲解一下每个选项的含义:
- workgroup:在Windows中显示的工作组
- netbios name:在Windows中显示出来的计算机名。
- server string:就是samba服务器说明,可自行定义。
- security:验证和登陆方式,share表示不需要用户名和密码,另外一种为user验证方式,需要用户名和密码。
- [thrfur]:表示共享名。
- path:共享的目录。
- writeable:共享目录是否可写。
- browseable:共享目录是否可被浏览
- guest ok:是否允许匿名用户以gust身份登陆。
下面将 thrfur 账号添加到samba 共享用户中:
//如果出现 smbpasswd: command not found 那么说明没有安装samba-common-tools
[root@192 thrfur]# smbpasswd -a thrfur
New SMB password:
Retype new SMB password:
Added user thrfur.
[root@192 thrfur]#
设置samba开机启动和开启samba服务:
[root@192 thrfur]# systemctl start smb
[root@192 thrfur]# systemctl start nmb
[root@192 thrfur]# systemctl enable smb
[root@192 thrfur]# systemctl enable nmb
查看本机IP地址:
[root@192 thrfur]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.34.129 netmask 255.255.255.0 broadcast 192.168.169.255
//192.168.34.129即为本机地址
inet6 fe80::351a:e68a:556d:bebd prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:91:06:b2 txqueuelen 1000 (Ethernet)
RX packets 369063 bytes 535408801 (510.6 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 95285 bytes 5827266 (5.5 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
在Windows端运行窗口输入:\\192.168.169.129
,输入CentOS上设置的thrfur的账号和密码,即可访问。
Window端无法连接,则需关闭CentOS端的防火墙
[root@192 thrfur]# systemctl stop firewalld #停止firewall
[root@192 thrfur]# systemctl disable firewalld #禁止firewall开机启动
[root@192 thrfur]# firewall-cmd --state #查看默认防火墙状态
Window端无权限访问,则需关闭CentOS端的SELinux
//重启后失效的关闭
[root@192 thrfur]# setenforce 0