Centos 7 Samba服务安装
搭建Samba服务器是为了实现Linux共享目录之后,在Windows可以直接访问该共享目录。
查看是否安装samba:
rpm –qa | grep samba
***************************************
samba-common-3.5.10-114.el6.x86_64
samba-winbind-clients-3.5.10-114.el6.x86_64
samba-winbind-3.5.10-114.el6.x86_64
samba-client-3.5.10-114.el6.x86_64
samba-3.5.10-114.el6.x86_64
**************************************
这里显示已安装
没有安装需要安装Samba:
本地yum源安装
以本地光盘为软件仓库创建yum源,并利用该yum源安装samba
[root@localhost ~]# mount /dev/cdrom/ /mnt/
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost ~]# rm –rf *
[root@localhost ~]# vi my.repo
在文本中加入以下内容:
[my_yum]
name = my_yum
baseurl = file:///mnt/
enable = 1
gpgcheck = 0
保存退出
[root@localhost ~]# yum install samba-common -y
然后进行Samba的安装
rpm安装
在这里我们进行rpm安装,首先将本地光盘镜像挂载到/mnt/目录下
[root@localhost ~]# mount /dev/cdrom/ /mnt/
[root@localhost ~]# ls /mnt/
EFI RELEASE-NOTES-es-ES.html RELEASE-NOTES-si-LK.html
EULA RELEASE-NOTES-fr-FR.html RELEASE-NOTES-ta-IN.html
GPL RELEASE-NOTES-gu-IN.html RELEASE-NOTES-te-IN.html
HighAvailability RELEASE-NOTES-hi-IN.html RELEASE-NOTES-zh-CN.html
images RELEASE-NOTES-it-IT.html RELEASE-NOTES-zh-TW.html
isolinux RELEASE-NOTES-ja-JP.html repodata
LoadBalancer RELEASE-NOTES-kn-IN.html ResilientStorage
media.repo RELEASE-NOTES-ko-KR.html RPM-GPG-KEY-redhat-beta
Packages RELEASE-NOTES-ml-IN.html RPM-GPG-KEY-redhat-release
README RELEASE-NOTES-mr-IN.html ScalableFileSystem
RELEASE-NOTES-as-IN.html RELEASE-NOTES-or-IN.html Server
RELEASE-NOTES-bn-IN.html RELEASE-NOTES-pa-IN.html TRANS.TBL
RELEASE-NOTES-de-DE.html RELEASE-NOTES-pt-BR.html
RELEASE-NOTES-en-US.html RELEASE-NOTES-ru-RU.html
然后我们进入/mnt/Packages目录下进行rpm安装
[root@localhost /]# cd /mnt/Packages/
[root@localhost Packages]#
[root@localhost Packages]# rpm -ivh samba-
samba-3.5.10-114.el6.x86_64.rpm
samba-client-3.5.10-114.el6.x86_64.rpm
samba-common-3.5.10-114.el6.i686.rpm
samba-common-3.5.10-114.el6.x86_64.rpm
samba-winbind-3.5.10-114.el6.x86_64.rpm
samba-winbind-clients-3.5.10-114.el6.i686.rpm
samba-winbind-clients-3.5.10-114.el6.x86_64.rpm
[root@localhost Packages]#
依次安装Samba的所有包和库文件
[root@localhost Packages]# rpm -ivh samba-3.5.10-114.el6.x86_64.rpm
[root@localhost Packages]# rpm -ivh samba-client-3.5.10-114.el6.x86_64.rpm
[root@localhost Packages]# rpm -ivh samba-common-3.5.10-114.el6.x86_64.rpm
[root@localhost Packages]# rpm -ivh samba-winbind-3.5.10-114.el6.x86_64.rpm
[root@localhost Packages]# rpm -ivh samba-winbind-clients-3.5.10-114.el6.x86_64.rpm
Samba配置
至此,我们已经将Samba安装完毕,现在进行Samba的配置。
1、 关闭selinux服务
该服务不关闭会导致Windows没有访问权限
临时关闭
setenforce 0(只对当前有效,电脑重启之后,该服务又会重新启动,所以一般选择永久关闭。)
永久关闭
打开selinux的配置文件:
vi /etc/sysconfig/selinux
将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 two values:
#targeted - Targeted processes are protected,
#mls - Multi Level Security protection.
SELINUXTYPE=targeted
重启电脑 :reboot
2、 创建共享目录
mkdir /home/share
赋予目录权限
chmod 777 /home/share
3、 添加samba服务器用户
首先创建一个普通用户
adduser fenxiang
passwd fenxiang
将该用户添加到samba服务列表中
smbpasswd –a fenxiang
[root@localhost samba]# smbpasswd -a fenxiang
New SMB password:
Retype new SMB password:
Added user fenxiang.
出现Added user *表示添加成功
4、 修改Samba配置文件
首先备份Samba配置文件:cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
打开配置文件:vi /etc/samba/smb.conf
在100行左右修改
security = user
#这里是设置samba的共享级别,share表示共享级访问,服务器不对客户机进行身份认证,user表示用户级访问,被访问的samba服务器要对客户机进行身份验证
encrypt passwords=yes/no
#指定是否使用加密口令,对于windows客户机来说,该选项应该设置为yes
在配置文件最后添加以下内容:
[share]
comment = my share
#对该共享资源的说明
path = /home/share
#共享资源的路径
valid user = fenxiang
#设置允许访问共享的用户或组的列表
writable = yes
#指定共享的路径是否可写
browseable = yes
#是否可以浏览共享目录
create mode = 0777
#指定客户机在共享目录中创建文件的默认权限
directory mode = 0777
#指定客户机共享目录中创建文件目录的默认权限
保存退出
5、 关闭防火墙
关闭防火墙
systemctl stop firewalld
关闭防火墙开机启动
systemctl disable firewalld
6、 启动samba服务
开启服务
systemctl start smb
systemctl start nmb
将服务加入到开机启动中
systemctl enable smb
systemctl enable nmb