服务器配置
检测系统是否安装了 Samba相关性软件包
[root@localhost ~]# 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
Failed说明没开启,139也可以
[root@localhost ~]# netstat -antup | grep 445
同样说明也没有开启
[root@localhost ~]# systemctl start smb
Failed to start smb.service: Unit not found.
创建一个用来挂载映像文件的目录
[root@localhost ~]# mkdir -p /opt/centos
把映像文件挂载到/opt/centos目录
[root@localhost ~]# mount /dev/cdrom /opt/centos
mount: /dev/sr0 写保护,将以只读方式挂载
清屏
[root@localhost ~]# clear
转到/etc/yum.repos.d/目录
[root@localhost ~]# cd /etc/yum.repos.d/
查看信息
[root@localhost yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
移动etc/yum.repos.d的所有到/home/目录
[root@localhost yum.repos.d]# mv /etc/yum.repos.d/* /home/
进入local.repo进行编辑
[root@localhost yum.repos.d]# vim local.repo
# /etc/yum.repos.d/local.repo
# or for ONLY the media repo, do this:
# yum --disablerepo=\* --enablerepo=c6-media [command]
[centos]
name=dvd
baseurl=file:///opt/centos //特别注意本地源文件的表示,3个“/”
gpgcheck=0
enabled=1
安装前先清除缓存
[root@localhost yum.repos.d]# yum clean all
已加载插件:fastestmirror, langpacks
正在清理软件源: centos
[root@localhost yum.repos.d]# cd
列出已启用的存储库
[root@localhost ~]# yum repolist
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
centos | 3.6 kB 00:00
(1/2): centos/group_gz | 166 kB 00:00
(2/2): centos/primary_db | 3.1 MB 00:00
源标识 源名称 状态
centos centos 4,021
repolist: 4,021
使用yum 命令安装 samba服务
[root@localhost ~]# yum install samba -y
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 samba.x86_64.0.4.8.3-4.el7 将被 安装
--> 正在处理依赖关系 samba-libs = 4.8.3-4.el7,它被软件包 samba-4.8.3-4.el7.x86_64 需要
--> 正在处理依赖关系 samba-common-tools = 4.8.3-4.el7,它被软件包 samba-4.8.3-4.el7.x86_64 需要
--> 正在处理依赖关系 libxattr-tdb-samba4.so(SAMBA_4.8.3)(64bit),它被软件包 samba-4.8.3-4.el7.x86_64 需要
--> 正在处理依赖关系 libxattr-tdb-samba4.so()(64bit),它被软件包 samba-4.8.3-4.el7.x86_64 需要
--> 正在检查事务
---> 软件包 samba-common-tools.x86_64.0.4.8.3-4.el7 将被 安装
---> 软件包 samba-libs.x86_64.0.4.8.3-4.el7 将被 安装
--> 正在处理依赖关系 libpytalloc-util.so.2(PYTALLOC_UTIL_2.1.9)(64bit),它被软件包 samba-libs-4.8.3-4.el7.x86_64 需要
--> 正在处理依赖关系 libpytalloc-util.so.2(PYTALLOC_UTIL_2.1.6)(64bit),它被软件包 samba-libs-4.8.3-4.el7.x86_64 需要
--> 正在处理依赖关系 libpytalloc-util.so.2(PYTALLOC_UTIL_2.0.6)(64bit),它被软件包 samba-libs-4.8.3-4.el7.x86_64 需要
--> 正在处理依赖关系 libpytalloc-util.so.2()(64bit),它被软件包 samba-libs-4.8.3-4.el7.x86_64 需要
--> 正在检查事务
---> 软件包 pytalloc.x86_64.0.2.1.13-1.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
================================================================================
Package 架构 版本 源 大小
================================================================================
正在安装:
samba x86_64 4.8.3-4.el7 centos 680 k
为依赖而安装:
pytalloc x86_64 2.1.13-1.el7 centos 17 k
samba-common-tools x86_64 4.8.3-4.el7 centos 448 k
samba-libs x86_64 4.8.3-4.el7 centos 276 k
事务概要
================================================================================
安装 1 软件包 (+3 依赖软件包)
总下载量:1.4 M
安装大小:3.7 M
Downloading packages:
--------------------------------------------------------------------------------
总计 4.9 MB/s | 1.4 MB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : pytalloc-2.1.13-1.el7.x86_64 1/4
正在安装 : samba-libs-4.8.3-4.el7.x86_64 2/4
正在安装 : samba-common-tools-4.8.3-4.el7.x86_64 3/4
正在安装 : samba-4.8.3-4.el7.x86_64 4/4
验证中 : pytalloc-2.1.13-1.el7.x86_64 1/4
验证中 : samba-4.8.3-4.el7.x86_64 2/4
验证中 : samba-common-tools-4.8.3-4.el7.x86_64 3/4
验证中 : samba-libs-4.8.3-4.el7.x86_64 4/4
已安装:
samba.x86_64 0:4.8.3-4.el7
作为依赖被安装:
pytalloc.x86_64 0:2.1.13-1.el7 samba-common-tools.x86_64 0:4.8.3-4.el7
samba-libs.x86_64 0:4.8.3-4.el7
完毕!
ping一下看网络是否连通
[root@localhost ~]# ping
PING (39.156.66.10) 56(84) bytes of data.
64 bytes from 39.156.66.10 (39.156.66.10): icmp_seq=1 ttl=128 time=44.8 ms
64 bytes from 39.156.66.10 (39.156.66.10): icmp_seq=2 ttl=128 time=42.1 ms
64 bytes from 39.156.66.10 (39.156.66.10): icmp_seq=3 ttl=128 time=42.7 ms
64 bytes from 39.156.66.10 (39.156.66.10): icmp_seq=4 ttl=128 time=43.2 ms
^Z
- + 已停止 ping
可以再这样试一下,检查是否安装好
[root@localhost ~]# yum install samba -y
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
软件包 samba-4.8.3-4.el7.x86_64 已安装并且是最新版本
无须任何处理
所有软件包安装完毕,可以使用rpm命令再一次进行查询
[root@localhost ~]# 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-common-tools-4.8.3-4.el7.x86_64
samba-client-4.8.3-4.el7.x86_64
samba-4.8.3-4.el7.x86_64
samba-libs-4.8.3-4.el7.x86_64
启动与停止samba服务
[root@localhost ~]# systemctl start smb
[root@localhost ~]# netstat -antup|grep smb
tcp 0 0 0.0.0.0:139 0.0.0.0:* LISTEN 9704/smbd
tcp 0 0 0.0.0.0:445 0.0.0.0:* LISTEN 9704/smbd
tcp6 0 0 :::139 :::* LISTEN 9704/smbd
tcp6 0 0 :::445 :::* LISTEN 9704/smbd
查看网络
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.44.141 netmask 255.255.255.0 broadcast 192.168.44.255
inet6 fe80::6a6d:4556:ea75:3594 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:d8:fb:d3 txqueuelen 1000 (Ethernet)
RX packets 87 bytes 12566 (12.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 126 bytes 13942 (13.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.176.134 netmask 255.255.255.0 broadcast 192.168.176.255
inet6 fe80::9f1e:ab6b:c49:cd7 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:d8:fb:dd txqueuelen 1000 (Ethernet)
RX packets 11 bytes 1409 (1.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 172 bytes 17249 (16.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 64 bytes 5568 (5.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 64 bytes 5568 (5.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:4b:80:f6 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]# systemctl start nmb
[root@localhost ~]# systemctl enable nmb smb
Created symlink from /etc/systemd/system/multi-user.target.wants/nmb.service to /usr/lib/systemd/system/nmb.service.
让命令临时生效
[root@localhost ~]# setenforce 0
关闭防火墙
[root@localhost ~]# systemctl stop firewalld
重新启动
[root@localhost ~]# systemctl restart smb nmb
进入 /etc/samba/smb.conf 目录
进入vim /etc/samba/smb.conf内修改
[root@localhost ~]# vim /etc/samba/smb.conf
重启samba
[root@localhost ~]# systemctl restart smb nmb
创建用户s1并设置密码
[root@localhost ~]# useradd s1
[root@localhost ~]# passwd s1
更改用户 s1 的密码 。
新的 密码:
无效的密码: 密码是一个回文
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
重新设置s1密码
[root@localhost ~]# smbpasswd -a s1
New SMB password:
Retype new SMB password:
Mismatch - password unchanged.
Unable to get new password.
创建share目录
[root@localhost ~]# mkdir /share
转到share目录
[root@localhost ~]# cd /share
创建文件abc.txt并查看
[root@localhost share]# touch abc.txt
[root@localhost share]# ll abc.txt
-rw-r--r--. 1 root root 0 11月 9 15:34 abc.txt
[root@localhost share]# ll -d /share
drwxr-xr-x. 2 root root 21 11月 9 15:34 /share
[root@localhost share]# cd
查看网络配置
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.44.141 netmask 255.255.255.0 broadcast 192.168.44.255
inet6 fe80::6a6d:4556:ea75:3594 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:d8:fb:d3 txqueuelen 1000 (Ethernet)
RX packets 204 bytes 33721 (32.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 377 bytes 50878 (49.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.176.134 netmask 255.255.255.0 broadcast 192.168.176.255
inet6 fe80::9f1e:ab6b:c49:cd7 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:d8:fb:dd txqueuelen 1000 (Ethernet)
RX packets 11 bytes 1409 (1.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 317 bytes 38525 (37.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 64 bytes 5568 (5.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 64 bytes 5568 (5.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:4b:80:f6 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]# systemctl restart smb nmb
编辑/etc/samba/smb.conf
[root@localhost ~]# vim /etc/samba/smb.conf
[share]
comment =my share
path=/share
public=no
read only=yes
valid users=s1
[root@localhost ~]# ll -d /share/
drwxr-xr-x. 2 root root 21 11月 9 15:34 /share/
修改文件和目录的所有者和所属组
[root@localhost ~]# chown s1:root /share
[root@localhost ~]# ll -d /share/
drwxr-xr-x. 2 s1 root 21 11月 9 15:34 /share/
重启Samba服务
[root@localhost ~]# systemctl restart smb
查看历史命令
[root@localhost ~]# history
1 ifconfig
2 ifconfig
3 nmtui
4 ifconfig
5 rpm -qa|grep samba
6 netstat -antup|grep 445
7 systemctl start smb
8 mkdir -p /opt/centos
9 mount /dev/cdrom /opt/centos
10 clear
11 cd /etc/yum.repos.d/
12 ls
13 mv /etc/yum.repos.d/* /home/
14 vim local.repo
15 yum clean all
16 cd
17 yum repolist
18 yum install samba -y
19 ping
20 yum install samba -y
21 rpm -qa | grep samba
22 systemctl start smb
23 netstat -antup|grep smb
24 ifconfig
25 systemctl start nmb
26 systemctl enable nmb smb
27 setenforce 0
28 systemctl stop firewalld
29 systemctl restart smb nmb
30 vim /etc/samba/smb.conf
31 systemctl restart smb nmb
32 useradd s1
33 passwd s1
34 smbpasswd -a s1
35 mkdir /share
36 cd /share
37 touch abc.txt
38 ll abc.txt
39 ll -d /share
40 cd
41 ifconfig
42 smbpasswd -a s1
43 systemctl restart smb nmb
44 vim /etc/samba/smb.conf
45 ll -d /share/
46 chown s1:root /share
47 ll -d /share/
48 systemctl restart smb
49 history
[root@localhost ~]#
客户机配置
[root@localhost ~]# history
创建目录
1 mkdir /opt/centos
挂载
2 mount /dev/cdrom /opt/centos
转到/etc/yum.repos.d/
3 cd /etc/yum.repos.d/
查看
4 ls
移动
5 mv /etc/yum.repos.d/* /home/
6 cd
编辑local.repo
7 vim local.repo
[centos]
name=dvd
baseurl=file:///opt/centos //特别注意本地源文件的表示,3个“/”
gpgcheck=0
enabled=1
安装samba客户端
8 yum install samba-client -y
挂载Windows共享目录
9 yum install cifs-utils -y
访问服务器
10 smbclient -L 192.168.176.134 -U s1%123456
退出访问
11 exit
查看历史命令
12 history
[root@localhost ~]#
Windows客户机
Win+R
如此Samba服务器就搭建好了
注:此实验在VM上测试的服务器配置了两个网卡,一个为NAT模式,一个为主机模式
Linux客户机配置了一个网卡,模式为主机模式
Windows客户机为外部主机
注意:可以在打开机器之前安装上