2009年4月7日 星期二

FreeBSD 7.01 release 安裝記錄3(安裝samba網芳)

安裝參考Samba@FreeBSD 架設程序
twbsd.org-第二十章 SAMBA 網路芳鄰
由 ports 安裝 Samba:

# cd /usr/ports/net/samba3
# make install

安裝選項:

Options for samba 3.0.24,1
[X] LDAP With LDAP support
[X] ADS With Active Directory support
[ ] CUPS With CUPS printing support
[ ] WINBIND With WinBIND support
[X] ACL_SUPPORT With ACL support
[ ] FAM_SUPPORT With File Alteration Monitor
[X] SYSLOG With Syslog support
[ ] QUOTAS With Disk quota support
[X] UTMP With UTMP accounting support
[ ] MSDFS With MSDFS support
[ ] PAM_SMBPASS With PAM authentication vs passdb backends
[ ] CLUSTER With experimental cluster support
[ ] EXP_MODULES With experimental modules
[X] POPT With system-wide POPT library
[ ] MAX_DEBUG With maximum debuging

編輯 Samba CONF 檔案:

# vi /usr/local/etc/smb.conf
# cp /usr/local/etc/smb.conf.sample /usr/local/etc/smb.conf //若無smb.conf 則複製

全域設定 (Global Settings):
smb.conf內參數: 'workgroup'
範例:

workgroup = WORKGROUP

smb.conf內參數: 'server string'
範例:

server string = %h Samba Server
'%h' 代表主機名稱變數。

smb.conf內參數: 'security'
要使用哪一種安全模式。如果設定為 share,就是任何人都可以存取,無需使用帳號密碼;
而設為 user 則是要輸入使用者名稱及密碼。如果我們設為 user,必須要再設定使用者
使用者及密碼。
範例:

security = user // share

smb.conf內參數: 'log file'
範例:

log file = /var/log/samba/%m.log

smb.conf內參數: 'dos charset'
Windows 用戶端的編碼,繁體中文 Windows 使用的是 big5 編碼,這個編碼在 Samba 內的格式被稱為『 cp950 』喔!
範例:

dos charset = cp950

smb.conf內參數: 'create mask' 'directory mask'
設定新建檔案時的權限為何。Samba 的權限除了看資料夾的權限設定外,還會看 UNIX 的
權限。我們將新建檔案的權限設為 0666,新建目錄設為 0777,以讓不同使用者所建立的
可以讓有權存取該共享資料夾的使用者存取。
範例:

create mask = 0666
directory mask = 0777

smb.conf內參數: 'sendfile'
在下載檔案時,我們使用 FreeBSD 的系統呼叫 sendfile() 以提高下載速度。使用
sendfile() 可以提高效能近一倍喔!

use sendfile = yes

使用者權限 (Share Definitions):
設定使用者家目錄,原始設定為:

[homes]
comment = Homes Directories
browseable = no
writable = yes

更改為:

[homes]
comment = Home directory for %u on %h
browseable = no
writable = yes
path = /usr/home/%u/
valid users = %S

設定共享資料夾,所有使用者都可以讀寫檔案:

# A publicly accessible directory, read/write to all users.
[public]
comment = %h Shared Public Directory
path = /usr/home/samba/public
force directory mode = 0777
force create mode = 0777
force group = nobody
force user = nobody
public = yes
writeable = yes
read only = no

測試 Samba CONF 檔案有無語法錯誤:

# /usr/local/bin/testparm | more

建立共享資料夾:

# cd /usr; mkdir home ; cd home ; mkdir samba ; cd samba ; mkdir public
# chmod 777 public

使用者帳號設定:
使用者必須同時設定兩種帳號: OS database (FreeBSD 的使用者帳號)、Samba user database (Samba 的使用者帳號) 才能正常登入 Samba 伺服器。

建立 OS database (FreeBSD 的使用者帳號):(假設帳號名稱為 winuser)

# adduser

adduser 用法,請參閱 FreeBSD Man Pages、 FreeBSD 使用者管理。
建立 Samba user database (Samba 的使用者帳號):

# smbpasswd -a winuser

顯示:
New SMB password:
鍵入 Windows 密碼,顯示:
Retype new SMB password:
再鍵入 Windows 寫碼確認。

啟動 Samba:
設定開機時,自動啟動 Samba,在 /etc/rc.conf 加入這一行設定:

samba_enable="YES"

有了 /usr/local/etc/rc.d/samba 我們只要在後面再加上 start 或 stop 就可以啟動或停止 samba 的服務
啟動samba

# /usr/local/etc/rc.d/samba start

==============================
我的設定檔,留著備用
==============================

[global]
workgroup = WORKGROUP
security = share
encrypt passwords = no
hosts allow = 192.168.1.
load printers = no
printing = bsd
dos charset = cp950
#[Customize]
use sendfile=yes
create mask=0666
directory mask=0777
smb ports=139
#============================ Share Definitions ==============================
[homes]
comment = Home Directories for %u on %h
path = /
browseable = yes
writable = yes
read only = no
public = no
force directory mode = 0777
force create mode = 0777
force group = nobody
force user = nobody
底下目錄全註解

==============================
解決Samba Server Unable to connect to CUPS server localhost:631 - 連線被拒絕問題
==============================
修改/usr/local/etc/smb.conf

# vi /usr/local/etc/smb.conf
load printers = no
printing = bsd
printcap name = /dev/null
disable spoolss = yes
# /usr/local/etc/rc.d/samba restart //smb.conf儲存後重啟samba

==============================
解決smbd[xxxx]: getpeername failed;lib/util_sock.c:get_peer_addr 錯誤==============================
修改/usr/local/etc/smb.conf

# vi /usr/local/etc/smb.conf
smb ports=139 //只監聽port 139 適用XP系統
# iptables -I INPUT 1 -p tcp --dport 445 -j DROP //阻擋445port的連線
# /usr/local/etc/rc.d/samba restart //smb.conf儲存後重啟samba

沒有留言:

張貼留言