Samba服务器简介及自动挂载配置案例

一、简介

     Samba是一个工具套件,在Unix上实现SMB(Server Message Block)协议,或

者称之为NETBIOS/LanManager协议。SMB协议通常是被windows系列用来实现磁

盘和打印机共享。

SMB应用功能

SAMBA 最初发展的主要目就是要用来沟通Windows 与 Unix Like 这两个不同的

作业平台。最大的好处就是不必让同样的一份数据放置在不同的地方,搞到后来都不晓

得哪一份资料是最新的!而且也可以透过这样的一个档案系统上Linux 与 Windows

的档案传输变得更为简单!那么 SAMBA 可以进行哪些动作呢?

①分享档案与打印机服务;

②提供使用者登入 SAMBA 主机时的身份认证,以提供不同身份者的个别数据;

③进行 Windows 网络上的主机名称解析 (NetBIOS name)

④进行装置的分享 ( 例如 Zip, CDROM... )

Samba服务器的安全级别  

share  匿名  

user   身份验证  samba帐号库 【本地】  

server  身份验证  samba帐号库 【其他服务器】     

domain 【ads】  身份验证   dc

Smbclient 使用  

smbclinet   -L //服务器地址   -U   账号名称  

smbclient   //服务器地址/共享名称   -U 账号名称

二、案例

安装相关软件:

挂载光盘:

[root@localhost ~]# mkdir /mnt/cdrom

[root@localhost ~]# mount /dev/cdrom /mnt/cdrom

[root@localhost ~]# cd /mnt/cdrom/Server

安装软件:

[root@localhost Server]# rpm -ivh perl-Convert-ASN1-0.20-1.1.noarch.rpm

[root@localhost Server]# rpm -ivh samba-3.0.33-3.14.el5.i386.rpm

[root@localhost Server]# service smb start
启动 SMB 服务:                                            [确定]
启动 NMB 服务:                                            [确定]

[root@localhost Server]# vim /etc/samba/smb.conf

编辑结果:

263 [public]
264         comment = this is a public dir
265         path = /abc
266         browseable = yes
267         guest ok = yes
268         writable = no
269        
270

271 [smbzs]

272         comment = this is a zhangsan share
273         path = /zhangsan
274         browseable = yes
275         guest ok = no
276         valid users = zhangsan
277         writable = yes
278       

279

280 [smbls]
281         comment = this is a lisi share
282         path = /lisi
283         browseable = yes
284         guest ok = no
285         valid users = lisi
286         writable = yes
287       

创建目录:

[root@localhost ~]# mkdir /abc  /zhangsan  /lisi

[root@localhost ~]# ll -d /abc /zhangsan /lisi
drwxr-xr-x 2 root root 4096 09-19 14:44 /abc
drwxr-xr-x 2 root root 4096 09-19 14:44 /lisi
drwxr-xr-x 2 root root 4096 09-19 14:44 /zhangsan

添加本地账号:

[root@localhost ~]# useradd zhangsan

[root@localhost ~]# useradd lisi

更改属性:

[root@localhost ~]# chown zhangsan.zhangsan /zhangsan/

[root@localhost ~]# chown lisi.lisi /lisi/

[root@localhost ~]# ll -d /abc /zhangsan /lisi
drwxr-xr-x 2 root     root     4096 09-19 14:44 /abc
drwxr-xr-x 2 lisi     lisi     4096 09-19 14:44 /lisi
drwxr-xr-x 2 zhangsan zhangsan 4096 09-19 14:44 /zhangsan

修改账号库:

[root@localhost ~]# smbpasswd -a zhangsan
New SMB password:
Retype new SMB password:
Added user zhangsan.

[root@localhost ~]# smbpasswd -a lisi
New SMB password:
Retype new SMB password:
Added user lisi.

[root@localhost ~]# cd /zhangsan

[root@localhost zhangsan]# touch f1.zhangsan

[root@localhost zhangsan]# cd /abc

[root@localhost abc]# touch f1.public

[root@localhost abc]# cd /lisi

[root@localhost lisi]# touch f1.lisi

[root@localhost ~]# service smb restart
关闭 SMB 服务:                                            [确定]
关闭 NMB 服务:                                            [确定]
启动 SMB 服务:                                            [确定]
启动 NMB 服务:                                            [确定]

测试:
 
linux客户端测试:
 
[root@localhost ~]# smbclient //192.168.145.100/smbzs -U zhangsan
Password:
Domain=[LOCALHOST] OS=[Unix] Server=[Samba 3.0.33-3.14.el5]
smb: \> dir
. D 0 Mon Aug 20 00:45:38 2012
.. D 0 Mon Aug 20 00:27:53 2012
f1.zhangsan 0 Mon Aug 20 00:32:09 2012
111 D 0 Mon Aug 20 00:45:36 2012
新建 文本文档.txt A 0 Sun Sep 16 15:41:35 2012
 
38752 blocks of size 262144. 25762 blocks available
smb: \> !dir
01 abcd b d3 f1 inittab install.log.syslog nn passwd qq3 useradd.sh
abc anaconda-ks.cfg d2 Desktop f3 install.log mbox nxl qq2 test.sh
smb: \> dir
. D 0 Mon Aug 20 00:45:38 2012
.. D 0 Mon Aug 20 00:27:53 2012
f1.zhangsan 0 Mon Aug 20 00:32:09 2012
111 D 0 Mon Aug 20 00:45:36 2012
新建 文本文档.txt A 0 Sun Sep 16 15:41:35 2012
 
38752 blocks of size 262144. 25762 blocks available
smb: \> put install.log
putting file install.log as \install.log (637.2 kb/s) (average 637.2 kb/s)
smb: \> dir
. D 0 Mon Aug 20 00:59:16 2012
.. D 0 Mon Aug 20 00:27:53 2012
f1.zhangsan 0 Mon Aug 20 00:32:09 2012
111 D 0 Mon Aug 20 00:45:36 2012
新建 文本文档.txt A 0 Sun Sep 16 15:41:35 2012
install.log A 35236 Mon Aug 20 00:59:17 2012
 
38752 blocks of size 262144. 25762 blocks available
smb: \> mget f1.zhangsan
Get file f1.zhangsan? y
getting file \f1.zhangsan of size 0 as f1.zhangsan (0.0 kb/s) (average 0.0 kb/s)
smb: \> !dir
01 abcd b d3 f1 f3 install.log mbox nxl qq2 test.sh
abc anaconda-ks.cfg d2 Desktop f1.zhangsan inittab install.log.syslog nn passwd qq3 useradd.sh
smb: \>

 

挂载到本地

建立挂载点

[root@localhost ~]# mkdir /mnt/smb

[root@localhost ~]# mount -t cifs //192.168.145.100/smbzs /mnt/smb -o username=zhangsan
Password:
 
查看
 
[root@localhost ~]# mount
/dev/sda2 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/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/hdc on /mnt/cdrom type iso9660 (ro)
//192.168.20.20/smbzs on /mnt/smb type cifs (rw,mand)
 
进入目录查看信息
 
[root@localhost ~]# cd /mnt/smb/
 
[root@localhost smb]# ll
总计 36
drwxr-xr-x 2 502 502 0 08-20 00:45 111
-rw-r--r-- 1 root root 0 08-20 00:32 f1.zhangsan
-rwxr--r-- 1 502 502 35236 08-20 00:59 install.log
-rwxr--r-- 1 502 502 0 2012-09-16 新建 文本文档.txt
 
 
开机自启动挂载
 
 
[root@localhost ~]# vim /etc/fstab
//192.168.20.20/smbzs /mnt/smb cifs defaults,username=zhangsan%123 0 0
 
[root@localhost ~]# mount -a
 
[root@localhost ~]# mount
/dev/sda2 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/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/hdc on /mnt/cdrom type iso9660 (ro)
//192.168.20.20/smbzs on /mnt/smb type cifs (rw,mand)

你可能感兴趣的:(samba,smb,nmb,自动挂载)