centos6.2架設samba服務器

文件服務器有很多:nfs,ftp,sftp,samba等,要採用那種服務器要看各自的需求而定。samba服務器的特點是提供了windows的網絡鄰居訪問功能,適用於一般的局域網文件共享,還具有共享打印機的功能。

 

對於centos要先下載幾個軟件:

samba:提供與samba服務器相關的smbd,nmbd服務程序和logrotate等文件

samba-clietn:提供linux可以作爲samba client端的相關工具命令

samba-common:提供samba服務器和客戶端的數據配置文件和命令

這些軟件都可用yum下載即可

 

在架設samba之前,首先要明白幾個專有名詞:

hostname:計算名,可以在/etc/sysconfig/network修改

workgroup:工作組名,要共享計算機必須要在同一工作組內

netbios name:等同於windows的計算機名,我叫它作組內域名,默認爲hostname,但可以修改

 

現在可以修改samba配置文件,主要是smb.cof文件,它是由samba-common軟件提供的,主要分爲兩部分:

[global] #全局參數配置

workgroup = *** #組名

netbios name = *** #組內域名,可以不用,默認爲hostname

server string = ******* #對這個samba服務器的介紹

log file = /var/log/samba/log.%m #日誌存儲文件,%m代表netbios主機名

max log size = 50 #日誌文件最大的kbytes數

security = user    #使用samba服務器本身的用戶密碼,改選項可以改爲share(共享),domain(samba client 密碼)

passdb backend = tdbsam #數據庫格式

 load printers = no #這個是打印機共享的,我沒要

主要的全局參數就這些,可以開啓samba服務器了

#各個資源的共享配置

[homes]  #比較特殊的目錄,爲各個用戶的家目錄,一般只能自己看見
        comment = Home Directories  #目錄說明
        browseable = no              #是否允許所有用戶看見該目錄
        writable = yes                 #是否可以寫入

[mnt]    #這是我共享的目錄名
        comment = win7 
        path = /mnt             #目錄路徑
        browseable = yes  
        writable = yes
        write list = @root     #可以擁有該目錄權限的用戶組

配置文件已經足夠開啓samba了,並共享了家目錄和/mnt目錄,現在要檢查一下文件是否有錯,可以用testparm命令,如下:

  1. root@www sysconfig]# testparm 
  2. Load smb config files from /etc/samba/smb.conf 
  3. rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384) 
  4. Processing section "[homes]" 
  5. Processing section "[printers]" 
  6. Processing section "[mnt]" 
  7. Processing section "[media]" 
  8. Loaded services file OK. 

這樣在“[共享目錄]”之前沒有信息證明沒有錯誤,可以開啓服務。

由於我採用的是user方式,所以還要把用戶加進samba用戶中,可以採用pdbedit命令:

  1. [root@www private]# pdbedit -a -u liang 
  2. new password
  3. retype new password

pdbedit還有很多用處,具體用法可以自己查。

在這裏提醒一下,用戶要登錄samba服務器的某個共享文件要滿足3個條件:1.samba服務器有該用戶;2.該用戶已經加入samba用戶中;3必須屬於這個共享文件write list的用戶組。

現在可以開啓samba服務:

/etc/init.d/smb start

/etc/init.d/nmb start

這時還不能搞定收工,因爲還有selinux要設置,針對samba,selinux有幾個選項可以設置的,這要看各人需求而定了,這裏直接引用別人的講解:

//If you want to share files other than home directorie

chcon -t samba_share_t /directory

//If you want to share files with multiple domains

setsebool -P allow_smbd_anon_write=1

//If you are setting up this machine as a Samba server and wish to share the home directories

setsebool -P samba_enable_home_dirs 1

//If you want to use a remote Samba server for the home directories on this machine

setsebool -P use_samba_home_dirs 1

//You can disable SELinux protection for the samba daemon by executing
service smb restart

現在就能收工了。

小貼示:我在windows的網絡鄰居登錄samba時選了記住密碼,結果就不能用戶切換了,即使重啓也不能,後來經csdn論壇熱心人指導,可以:

1.windows執行“control userpasswords2”
2.在“詳細設置”裏面打開“密碼管理”
3.刪除你那個用戶鏈接
4.重啓,重新訪問samba


 

 

 

       

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