Linux 文件共享之SMB服務

大綱

一、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  ]


wKioL1Z2UsyTo6VQAANaiPWs9aU124.jpg












發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章