前段时间,加入了学校的一个实验室。后来学长让我们小组在5天之内搭建出一个基于虚拟用户的samba共享服务。要求是实验室三个小组的成员能够访问所有共享资料,但不能上传和删除。每个组的组长可以上传和删除本组资料。另外需要使用虚拟用户实现。一开始,大家都有点懵,然后就在网上找资料,最后基本确定了一个实现方案。

  刚开始给了一台服务器装机,乍一看,这服务器有年头了,大箱子似的,是浪潮的一款比较老的机器,04年进的学校,古董级别的,哈哈。于是,我们小组的人开始装机了,但是中间遇到了许多问题。仔细一研究,这东西还不支持usb(本来打算用U盘装的),又试了光盘,还是不行。最后无奈选择了网络安装,搭建PXE安装。后来又发现它的cpu不支持64位系统,于是又搞了个32位装好了。不料系统没有装在第一块盘,我们又把第四块磁盘放在第一个卡槽(装机时只有第四块盘的指示灯亮着),这下机器才好了。真是一番周折。这时,头觉得这机器太老了,不用这台机器了。给了我们一台DELL 6850的机器。这机器就是好,松松搞定。不过,这机器把U盘假想为本地硬盘启动(在BIOS中可以设置)。接下来说一下samba的具体配置:

实验环境:rhel enterprise 6.5

 

selinux disabled

 

一、下载安装包

 

yum install -y samba samba-common samba-client

 

二、配置文件

 

vim  /etc/samba/smb.conf    ### 注释掉不需要的共享目录homes,printers

spacer.gif 

[global]

 

...

 

username map = /etc/samba/smbusers   ##启用 samba 用户映射文件

 

###以下为优化参数,详情查看此处 http://www.arm9home.net/simpl e/index.php?t22607.html  http://cubie.cc/forum.php?mod=viewthrea d&tid=3714

 

socket options = TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=1048576 SO_SNDBUF=1048576

aio read size = 65536 aio write size = 65536 aio write behind = true

 

write cache size = 2097152 max xmit = 65536

 

large readwrite = yes


spacer.gif

use sendfile = yes

min receivefile size = 16384 getwd cache = true

follow symlinks = no wide links = no

log level = 0

 

[share]

 

comment = infor center path = /data

writable = yes guest ok = no

 

vim /etc/samba/smbusers  ###添加 samba 用户映射

spacer.gif 

system = vsystem net = vnet

 

deve = vdeve

 

common = user1 user2 user3 user4

 

 

 

创建共享目录

mkdir /data

 

mkdir /data/(develop,system,network) chown system:system /data/system chown network:network /data/network chown develop:develop /data/develop

usermod-aG  (system,net,deve)  common  ## systemnetdeve分别作为 common 的附加组加上去

useradd-M  (system ,net, deve ,common) -s /sbin/nologin

smbpasswd-a  (system,net,deve,common)  ##添加samba 用户信息

 

三、设置防火墙

 

iptables -F;iptables -Xiptables -Z  ##清除防火墙规则

 

设置默认规则:

 

iptables -P INPUT DROP iptables -P OUTPUT ACCEPT iptables -P FORWARD ACCEPT iptables -A INPUT -i lo -j ACCEPT

设置开启的端口

 

iptables -A INPUT -p tcp --dport 139 -j ACCEPT iptables -A INPUT -p tcp --dport 445 -j ACCEPT iptables -A INPUT -p udp --dport 137 -j ACCEPT iptables -A INPUT -p udp --dport 138 -j ACCEPT

 

iptables -A INPUT -p tcp --dport 510 -j ACCEPT  ## ssh 端口设为 510并开启,防止安全隐患 

vim /etc/ssh/sshd_config

spacer.gif 

PORT 510

 

PermitRootLogin no   ###禁止 root 登陆

 

开启所有服务

/etc/init.d/sshd restart

/etc/init.d/iptables save

/etc/init.d/iptables restart   ##保存防火墙规则


/etc/init.d/smb start   ###开启服务

 

/etc/init.d/nmb start   ###开启服务