RedHat : SAMBA 服务

来源:互联网 发布:全球云计算开源峰会 编辑:程序博客网 时间:2024/06/05 06:39


从在 VirtualBox 刚装好的 RedHat 开始,首先安装 samba,检查 samba 是否已经安装

[root@com5 Desktop]# rpm -qa | grep sambasamba-winbind-3.6.9-151.el6.x86_64samba-winbind-clients-3.6.9-151.el6.x86_64samba4-libs-4.0.0-55.el6.rc4.x86_64samba-client-3.6.9-151.el6.x86_64samba-common-3.6.9-151.el6.x86_64

配置 yum 源为 ISO 文件

在virtualBox 菜单中选择 Devices --> CD/DVD Devices --> choose a virtual CD/DVD disk file...   找到 ISO 文件

找到 ISO 文件所在路径,进入 /media 目录 tab 提示出目录以避免路径字符转义问题,将路径/RHEL_6.4\ x86_64\ Disc\ 1/ 复制到repo文件

修改 /etc/yum.repos.d/rhel-source.repo 文件,添加一个ISO 文件所在路径,将其他yum源禁用

[iso]name=use ISO installbaseurl=file:///media/RHEL_6.4\ x86_64\ Disc\ 1/enabled=1gpgcheck=0

安装 samba,设置smb服务开机自启动

[root@com5 Desktop]# yum install samba[root@com5 Desktop]# rpm -qa | grep sambasamba-3.6.9-151.el6.x86_64samba-winbind-3.6.9-151.el6.x86_64samba-winbind-clients-3.6.9-151.el6.x86_64samba4-libs-4.0.0-55.el6.rc4.x86_64samba-client-3.6.9-151.el6.x86_64samba-common-3.6.9-151.el6.x86_64[root@com5 yum.repos.d]# chkconfig  | grep smbsmb            0:off1:off2:off3:off4:off5:off6:off[root@com5 yum.repos.d]# chkconfig smb on[root@com5 yum.repos.d]# chkconfig  | grep smbsmb            0:off1:off2:on3:on4:on5:on6:off

创建共享目录和文件

[root@com5 /]cd /[root@com5 /]mkdir smbshare[root@com5 /]# echo sambaData > /smbshare/file1.data[root@com5 /]# ll smbshare/total 4-rw-r--r--. 1 root root 10 Dec 28 05:22 file1.data[root@com5 /]# ll -d smbshare/drwxr-xr-x. 2 root root 4096 Dec 28 05:22 smbshare

添加访问用户

[root@com5 /]# useradd smbuser1[root@com5 /]# smbpasswd -a smbuser1New SMB password:Retype new SMB password:Added user smbuser1.[root@com5 /]# 

编辑 /etc/samba/smb.conf 文件,在最后添加下面两行,分别为共享名和共享目录

[shareA]path = /smbshare

重启 smb 服务

[root@com5 samba]# service smb restart

在 Windows 中访问 SMB 共享目录: 在浏览器中访问 SMB 服务IP, \\192.168.1.111,输入添加的用户 smbuser1 和密码

可以看到在 /etc/samba/smb.conf 中配置的 shareA 目录,但无权限访问。

在主机中测试,同样无法访问

[apache@indigo ~]$ uname -aLinux indigo 3.10.10-200.fc19.x86_64 #1 SMP Thu Aug 29 19:05:45 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux[apache@indigo ~]$ smbclient -L //192.168.1.111 -U smbuser1%smbuser1Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.9-151.el6]Sharename       Type      Comment---------       ----      -------shareA          Disk      IPC$            IPC       IPC Service (Samba Server Version 3.6.9-151.el6)smbuser1        Disk      Home DirectoriesDomain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.9-151.el6]Server               Comment---------            -------Workgroup            Master---------            -------[root@indigo apache]# mount -t cifs //192.168.1.111 /tmp/smbshare/ -o username=smbuser1,password=smbuser1[root@indigo smbmount]# cd /tmp/smbmount/[root@indigo smbmount]# llls: reading directory .: Permission deniedtotal 0
这个访问问题是由于 SeLinux 阻挡了,解决办法有三个: 关闭SeLinux,临时修改SeLinux boolean值或修改共享目录的属性

方法一、关闭 Selinux:

[root@com5 Desktop]# setenforce 0

方法二、修改 Selinux boolean  值,只要查看可能需要修改哪些值,最多将他们全部修改即可,例如下面如设置了 samba_export_all_rw 一个值,客户端便可以访问了

[root@com5 Desktop]# getsebool -a | grep sambasamba_create_home_dirs --> offsamba_domain_controller --> offsamba_enable_home_dirs --> offsamba_export_all_ro --> offsamba_export_all_rw --> offsamba_portmapper --> offsamba_run_unconfined --> offsamba_share_fusefs --> offsamba_share_nfs --> offsanlock_use_samba --> offuse_samba_home_dirs --> offvirt_use_samba --> off[root@com5 Desktop]# setsebool samba_export_all_rw=1[root@com5 Desktop]# getsebool -a | grep sambasamba_create_home_dirs --> offsamba_domain_controller --> offsamba_enable_home_dirs --> offsamba_export_all_ro --> offsamba_export_all_rw --> onsamba_portmapper --> offsamba_run_unconfined --> offsamba_share_fusefs --> offsamba_share_nfs --> offsanlock_use_samba --> offuse_samba_home_dirs --> offvirt_use_samba --> off[root@com5 Desktop]# 

方法三、修改共享目录的标签

在文件 /etc/samba/smb.conf 中已经告诉我们该怎么做了,拿过来运行一下就可以了

[root@com5 samba]# chcon -R -t samba_share_t /smbshare/[root@com5 samba]# ls -ldZ /smbshare/drwxr-xr-x. root root unconfined_u:object_r:samba_share_t:s0 /smbshare/[root@com5 samba]# 
以上即为 SMB 的最简配置


0 0
原创粉丝点击