Samba是SMB的一种实现方法,主要用来实现Linux系统的文件和打印服务。Linux用户通过配置使用Samba服务器可以实现与Windows用户的资源共享。守护进程smbd和nmbd是Samba的核心,在全部时间内运行。nmbd程序使得通过企图计算机可以浏览Linux服务器。
公司有一台pc配置很低,也是845的老主板40g硬盘用来装系统又挂了一个80g数据用来存储软件,想了想废物利用,就自己动手搞了一个samba共享服务器存放一下常用的软件,系统装的是最小安装,只装server base基本的包,系统为centos5.5,系统安装好之后就是用yum来安装samba包,yum是个好东西所有的依赖问题都给你解决。。
1.yum -y install samba
Installing for dependencies:
libsmbclient i386 3.0.33-3.29.el5_6.2 updates 908 k
perl-Convert-ASN1 noarch 0.20-1.1 base 42 k
samba-common i386 3.0.33-3.29.el5_6.2 updates 6.7 M
Transaction Summary
==============================================================================================================================================
Install 4 Package(s)
Upgrade 0 Package(s)
Total download size: 24 M
Downloading Packages:
(1/4): perl-Convert-ASN1-0.20-1.1.noarch.rpm | 42 kB 00:00
(2/4): libsmbclient-3.0.33-3.29.el5_6.2.i386.rpm | 908 kB 00:00
(3/4): samba-common-3.0.33-3.29.el5_6.2.i386.rpm | 6.7 MB 00:02
(4/4): samba-3.0.33-3.29.el5_6.2.i386.rpm | 16 MB 00:05
----------------------------------------------------------------------------------------------------------------------------------------------
Total 2.7 MB/s | 24 MB 00:08
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID e8562897
updates/gpgkey | 1.5 kB 00:00
Importing GPG key 0xE8562897 "CentOS-5 Key (CentOS 5 Official Signing Key) <[email protected]>" from /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : libsmbclient 1/4
Installing : perl-Convert-ASN1 2/4
Installing : samba-common 3/4
Installing : samba 4/4
Installed:
samba.i386 0:3.0.33-3.29.el5_6.2
Dependency Installed:
libsmbclient.i386 0:3.0.33-3.29.el5_6.2 perl-Convert-ASN1.noarch 0:0.20-1.1 samba-common.i386 0:3.0.33-3.29.el5_6.2
Complete!
2.安装好samba之后就是替换/etc/samba/smb.conf文件
这个文件我事先在windows上写好,然后用ssh传到/etc/samba目录,把原来的mv /etc/samba/smb.conf smbbackup.conf备份一下,然后ssh拷贝到这台机器上去。smb.conf内容如下:如果要修改可以另行修改里面添加了打印参数。
[global]
workgroup = WORKGROUP
netbios name = centos
unix charset = gb2312
dos charset = gb2312
security = user
server string = Samba Server
printcap name = /etc/printcap
load printers = yes
cups options = raw
log file = /var/log/samba/%m.log
max log size = 0
encrypt passwords = yes
smb passwd file = /etc/samba/smbpasswd
socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192
local master = no
interfaces = 192.168.xxx.xxx/24 //这个可以自己修改。
dns proxy = no
[homes]
comment = Home Directories
browseable = no
writable = yes
valid users =%S
create mode = 0664
directory mode = 0775
[printers]
comment = All Printers
path = /var/spool/samba
browseable = no
public = yes
guest ok = yes
writable = no
printable = yes
printer admin = root
[print$]
comment = printer Drivers
path = /etc/samba/drivers
browseable = yes
guest ok = yes
read only = yes
write list = root
[software]
comment =Public stuff
path =/home/samba/software
public = yes
writable = yes
printable = no
write list = @staff
3.拷贝好smb.conf到/etc/samba/中去之后,用testparm看一下参数是否正确。
[root@localhost ~]# testparm
Load smb config files from /etc/samba/smb.conf
Processing section "[homes]"
Processing section "[printers]"
WARNING: The "printer admin" option is deprecated
Processing section "[print$]"
Processing section "[software]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions
[global]
dos charset = gb2312
unix charset = gb2312
netbios name = CENTOS
server string = Samba Server
interfaces = 192.168.xxx.xxx/24
log file = /var/log/samba/%m.log
max log size = 0
socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192
printcap name = /etc/printcap
local master = No
dns proxy = No
cups options = raw
[homes]
comment = Home Directories
valid users = %S
read only = No
create mask = 0664
directory mask = 0775
browseable = No
[printers]
comment = All Printers
path = /var/spool/samba
printer admin = root
guest ok = Yes
printable = Yes
browseable = No
[print$]
comment = printer Drivers
path = /etc/samba/drivers
write list = root
guest ok = Yes
[software]
comment = Public stuff
path = /home/samba/software
write list = @staff
read only = No
guest ok = Yes
提示ok就没问题了。
4.然后重新启动一下samba服务
[root@localhost ~]# service smb start
Starting SMB services: [ OK ]
Starting NMB services: [ OK ]
ok提示成功!
5.在/home目录下建立一个samba目录mkdir samba
然后mkdir /home/samba/software目录
然后给主有读写执行权限(rwx),组和其它为读和执行的权限(rx)
本人比较喜欢数字表示方法chmod 755 /home/samba,chmod 755 /home/samba/software然后用ll看一下权限。
[root@localhost home]# ls -l samba/
total 4
drwxr-xr-x 3 zhh jsb 4096 Aug 6 00:00 software//这个为目录主有rwx,组有rx,其它为rw
权限好了然后就是添加samba用户,samba用户和系统自带的不是同一个密码哦
6.添加用户
假如我建立一个jsb的组,zhh为主
groupadd jsb
useradd -G jsb zhh//把zhh用户加入jsb组中
chown -R zhh.jsb /etc/samba/software//执行完命令后最好用ll查看一下主和组和其它的
useradd -G jsb guest//添加一个guest用户
smbpasswd -a guest//没密码的直接回车两次。
最后就是smbpasswd -a zhh//这个权限比较大所以需要设置相应的密码。
设置好密码后就可以用windows开始菜单运行中\\xxx.xxx.xxx.xxx来访问了。
7.因为添加了另外一块ide硬盘主要是用来存储软件的,所以拿到硬盘先格式化一下。
fdisk -l
Disk /dev/hda: 40.0 GB, 40020664320 bytes
255 heads, 63 sectors/track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 13 104391 83 Linux
/dev/hda2 14 144 1052257+ 82 Linux swap / Solaris
/dev/hda3 145 4865 37921432+ 83 Linux
Disk /dev/hdb: 80.0 GB, 80026361856 bytes
16 heads, 63 sectors/track, 155061 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Device Boot Start End Blocks Id System
/dev/hdb1 1 155061 78150712+ 83 Linux
以上第二块硬盘我已经格式化好了,其实挺简单直接用fdisk /dev/hdb来格式化就可以了n--p--回车--回车--w写入然后就可以看到/dev/hdb1了,然后建立文件系统mkfs -t ext3 /dev/hdb1就可以格式化为ext3文件了,然后再vi /etc/fstab中添加
/dev/hdb1 /home/samba/software ext3 defaults,grpquota,usrquota 1 2
后面defaults的grpquota,usrquota 表示磁盘限额,可以不添加吧
/dev/hdb1 /home/samba/software ext3 defaults 0 0
完成之后就是reboot一下系统看一下是否有错误,然后终端mount看一下
[root@localhost test]# mount
/dev/hda3 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/hda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
/dev/hdb1 on /home/samba/software type ext3 (rw,grpquota,usrquota)//看到了已经挂起
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
8.以上完成之后基本上就是测试一下就可以了,samba共享服务器搭建好了就这么简单明了,如果想查看iostat直接用yum -y install sysstat包就可以了,不过还可以用sar具体参数用法就不多了网上也挺多的。
[root@localhost test]# iostat -x
Linux 2.6.18-194.el5 (localhost.localdomain) 08/06/2011
avg-cpu: %user %nice %system %iowait %steal %idle
0.13 0.03 0.15 0.22 0.00 99.48
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util//最主要的参数
hda 0.10 2.88 0.16 0.43 6.37 26.48 55.62 0.03 51.03 2.40 0.14
hda1 0.01 0.00 0.00 0.00 0.02 0.00 28.66 0.00 8.90 8.51 0.00
hda2 0.02 0.00 0.00 0.00 0.02 0.00 45.83 0.00 7.54 7.54 0.00
hda3 0.07 2.88 0.16 0.43 6.32 26.48 55.69 0.03 51.15 2.39 0.14
hdb 6.30 3.47 0.32 0.14 69.06 28.86 214.70 0.02 36.59 3.31 0.15
hdb1 6.30 3.47 0.31 0.14 69.05 28.86 214.76 0.02 36.61 3.31 0.15