2015年1月4日星期日

Linux_099:RHEL6下安装Samba服务

环境:RHEL 6.6

RHEL6默认没有安装Samba服务,需要手工安装。
首先挂载RHEL 6.6 iso,然后进入Packages目录。

1. 安装samba
# rpm -ivh samba-3.6.23-12.el6.x86_64.rpm
warning: samba-3.6.23-12.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                ########################################### [100%]
   1:samba                  ########################################### [100%]

2. 安装samba-client
# rpm -ivh samba-client-3.6.23-12.el6.x86_64.rpm
warning: samba-client-3.6.23-12.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                ########################################### [100%]
    package samba-client-0:3.6.23-12.el6.x86_64 is already installed

3. 创建共享目录,并改变目录属主为nobody
(1)# mkdir -p /share/docs
(2)# chown nobody:nobody /share/docs -R

4. 修改/etc/samba/smb.conf,修改后内容如下:

[global]
workgroup = WORKGROUP
server string = MaPing Samba Server Version %v
netbios name = RHEL 6.6 Server
log file = /var/log/samba/log.%m
security = share
[public]
comment = shared docs
path = /share/docs
public = yes
browseable = yes
writeable = yes

5. 设置防火墙,开启port:139和port:445
# vim /etc/sysconfig/iptables
修改后的文件内容如下:
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 20 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 23 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 139 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 445 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

6.  disable SELinux
# vim /etc/selinux/config
修改后的文件内容如下:

# 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


7. 重启samba服务
 (1)service  smb restart
 (2)chkconfig --level 35 smb on

8. 在Windows 7 机器上访问共享目录
(1)可以直接在地址栏输入:\\192.168.0.105\public
(2)在命令行窗口输入:net view \\192.168.0.105,连接成功后,会输出Server以及共享目录信息。
执行 net use H: \\192.168.0.105\public,将共享目录映射为驱动器H。
试一试,应该可以向共享目录中读写文件。

9. 在Linux 机器上访问共享目录
smbclient //192.168.0.105/public

参考文献:
1. http://www.it165.net/os/html/201312/7021.html

没有评论: