centos7搭建Samba服务

实现Linux与Windows之间文件的共享

配置网络

##配置网络命令
nmcli connection modify "ens33" ipv4.method manual ipv4.addresses "192.168.131.161/24" ipv4.gateway "192.168.131.2" ipv4.dns "114.114.114.114" connection.autoconnect yes

##关闭网络并重新启动生效
nmcli con down  ens33
nmcli con up  ens33

##验证网络是否ping通
[root@localhost ~]# ping www.baidu.com
PING www.a.shifen.com (36.152.44.95) 56(84) bytes of data.
64 bytes from 36.152.44.95 (36.152.44.95): icmp_seq=1 ttl=128 time=35.8 ms
64 bytes from 36.152.44.95 (36.152.44.95): icmp_seq=2 ttl=128 time=35.6 ms
^C
--- www.a.shifen.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1004ms
rtt min/avg/max/mdev = 35.627/35.727/35.827/0.100 ms


# 关闭SELinux

```bash
sed -i '/SELINUX/{s/permissive/disabled/}' /etc/selinux/config 
或	vim /etc/selinux/config		
		SELINUX=disabled

挂载镜像

mount /dev/sr0 /mnt/	#临时挂载

vim /etc/fstab 	##开机自启挂载;进入配置文件,并在最后一行添加下面的命令
/dev/cdrom /mnt iso9660 defaults 0 0

配置本地yum

mkdir /tmp/repo							#创建存放原先的repo文件目录
mv /etc/yum.repos.d/CentOS-* /tmp/repo/	#把原先的repo文件全部移到/tmp/repo/下
vim /etc/yum.repos.d/centos7.repo		#创建本地repo文件
	[centos]
	name=centos
	baseurl=file:///mnt
	enabled=1
	gpgcheck=0

检验本地yum源是否成功

[root@localhost ~]# yum clean all;yum repolist 
已加载插件:fastestmirror, langpacks
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
正在清理软件源: centos
Cleaning up list of fastest mirrors
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
centos                                                 | 3.6 kB     00:00     
(1/2): centos/group_gz                                   | 165 kB   00:00     
(2/2): centos/primary_db                                 | 3.2 MB   00:00     
源标识                              源名称                               状态
centos                              centos                               4,067
repolist: 4,067

安装Samba服务

yum install -y samba

开启防火墙永久放行

firewall-cmd --permanent --add-service="samba"
firewall-cmd --reload	#重新加载
firewall-cmd --list-all	#查看放行的服务

关闭防火墙及开机自启

[root@localhost ~]# systemctl  stop firewalld.service 
[root@localhost ~]# systemctl  disable firewalld.service
[root@localhost ~]# systemctl list-unit-files | grep firewall	#查看开机自启是否已关闭
firewalld.service                             disabled

匿名访问

创建共享目录并给权限

mkdir /test1
chmod 777 /test1

修改配置文件

vim /etc/samba/smb.conf
#在[global]最后添加下面这条命令
		map to guest = bad user
		
#在最后添加一下命令
[share]
        path = /test1
        public  = yes

systemctl restart smb	#重启服务
\\192.168.131.161		#在运行栏中输入

密码访问

创建共享目录并给权限

mkdir /test10
chmod 777 /test10

修改配置文件

#将用户添加进Samba用户
pdbedit -au user1

#进入配置文件在最后添加一下命令
vim /etc/samba/smb.conf
[share]
        path = /test10
        writable = yes
        valid users = user1

systemctl restart smb	#重启服务

验证

\\192.168.131.161		#在运行栏中输入,用户:user1密码是将用户添加进Samba时的密码
上一篇:编译环境搭建及ubuntu常用命令


下一篇:Centos上部署文件共享