大纲
一、SMB概念
二、SMB服务相关文件详解
三、SMB服务实现
一、SMB概念
服务器消息区块(英语:Server Message Block,缩写为SMB,服务器消息区块),又称网络文件共享系统(英语:Common Internet File System,缩写为CIFS),一种应用层网络传输协议,由微软开发,主要功能用是使网络上的机器能够共享计算机文件、打印机、串行端口和通讯等资源。它也提供认证的进程间通讯机能。它主要用在装有Microsoft Windows的机器上,在这样的机器上被称为Microsoft Windows Network。
经过Unix服务器厂商重新开发后,它可以用于连接Unix服务器和Windows客户机,执行打印和文件共享等任务。
与功能类似的NFS相比,NFS的消息格式是固定长度,而CIFS的消息格式大多数是可变长度,这增加了协议的复杂性。CIFS消息一般使用NetBIOS或TCP协议发送,分别使用不同的端口139或445,目前倾向于使用445端口。CIFS的消息包括一个信头(32字节)和消息体(1个或多个,可变长)。
二、SMB服务相关文件详解
1、首先主机上得安装samba服务器端
[root@CentOS5 ~]# yum install -y "samba3x" "samba3x-client" "samba3x-common"
2、/etc/samba/lmhosts文件
[root@CentOS5 ~]# cd /etc/samba/ [root@CentOS5 samba]# ls lmhosts smb.conf smbusers [root@CentOS5 samba]# cat lmhosts 127.0.0.1 localhost lmhosts(Local Machine)文件是个纯文本文件,是用来进行NETBIOS名静态解析的。 将NETBIOS名和IP地址对应起来,功能类似于DNS。只不过DNS是将域名/主机名和IP对应。
3、/etc/samba/smbusers文件
[root@CentOS5 samba]# pwd /etc/samba [root@CentOS5 samba]# cat smbusers # Unix_name = SMB_name1 SMB_name2 ... root = administrator admin nobody = guest pcguest smbguest hadoop = hauser [root@CentOS5 samba]# tail -1 /etc/passwd hadoop:x:500:500::/home/hadoop:/bin/bash 采用账户映射方式为Samba服务器提供虚拟账户,映射格式为 Unix_name = SMB_name1 SMB_name2 ...
4、/etc/samba/smb.conf文件
[global] workgroup = MYGROUP # 工作组名称 server string = Samba Server Version %v # SMB服务器描述信息 ; netbios name = MYSERVER ; interfaces = lo eth0 192.168.12.2/24 192.168.13.2/24 ; hosts allow = 127. 192.168.12. 192.168.13. # --------------------------- Logging Options ----------------------------- # logs split per machine log file = /var/log/samba/log.%m # 每个客户端的日志保存位置 # max 50KB per log file, then rotate max log size = 50 # 每个日志最大为50KB,超过就会滚动 # ----------------------- Standalone Server Options ------------------------ security = user # smb安全级别,有user,、share、server不过后两个已废弃 passdb backend = tdbsam # tdb数据库格式保存密码 #============================ Share Definitions ============================== [homes] comment = Home Directories # 注释信息 browseable = no # 用户是否可浏览 writable = yes # 用户是否有写权限 ; valid users = %S # 合法用户 ; valid users = MYDOMAIN\%S # # Un-comment the following to provide a specific roving profile share # the default is to use the user's home directory ; [Profiles] ; path = /var/lib/samba/profiles ; browseable = no ; guest ok = yes # A publicly accessible directory, but read only, except for people in # the "staff" group ; [public] ; comment = Public Stuff ; path = /home/samba ; public = yes ; writable = yes ; printable = no ; write list = +staff
三、SMB服务实现
[root@CentOS5 samba]# tail -6 smb.conf # 文件尾部添加如下信息 [My tools] # Windows上引用的UNC路径后缀 comment = Share some tools path = /share/tools # 共享文件目录 browseable = yes # 用户可看见 public = no # 是否能够被所有用户读取 writable = yes # 只读不可写 [root@CentOS5 samba]# useradd hadoop # 添加用户及samba密码,并非系统登录的密码 [root@CentOS5 samba]# smbpasswd -a hadoop New SMB password: Retype new SMB password: [root@CentOS5 samba]# testparm # 是否配置是否有错误 Load smb config files from /etc/samba/smb.conf rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384) Processing section "[homes]" Processing section "[printers]" Processing section "[My tools]" Loaded services file OK. Server role: ROLE_STANDALONE Press enter to see a dump of your service definitions [global] workgroup = MYGROUP server string = Samba Server Version %v log file = /var/log/samba/log.%m max log size = 50 idmap config * : backend = tdb cups options = raw [homes] comment = Home Directories read only = No browseable = No [printers] comment = All Printers path = /var/spool/samba printable = Yes print ok = Yes browseable = No [My tools] comment = Share some tools path = /share/tools read only = No [root@CentOS5 samba]# mkdir -p /share/tools/ # 创建共享目录 [root@CentOS5 samba]# cp /etc/fstab /share/tools/ [root@CentOS5 samba]# service ll /share/tools/ [root@CentOS5 samba]# service smb start Starting SMB services: [ OK ]