Tải bản đầy đủ (.pdf) (29 trang)

Tài liệu Cài đặt Samba pdf

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (227.17 KB, 29 trang )

Tài liệu này mô tả cách dùng giao thức Server Message Block, còn gọi là giao thức
Session Message Block, NetBIOS hay giao thức LanManager, với Linux sử
dụng Samba.
MỤC LỤC
1. Giới thiệu
2. Cài đặt
3. Cách vận hành Daemons
4. Cấu hình tổng quát (/etc/smb.conf)
5. Chia xẻ Linux Drive với Windows Machines
6. Truy cập SMB Share với Linux Machines
7. Chia xẻ Linux Printer với Windows Machines
8. Chia xẻ Windows Printer với Linux Machines
9. Backing Up Windows Machines vào một máy chủ Linux
10. Sử dụng Samba Across Routed Networks
11. Tài liệu tham khảo
1. Giới thiệu:
Tài liệu này mô tả cách dùng giao thức Server Message Block, còn gọi là giao thức
Session Message Block, NetBIOS hay giao thức LanManager, với Linux sử dụng
Samba. mặc dù tài liệu có trọng tâm là Linux, nhưng Samba có thể chạy trong hầu
hết các hệ điều hành tương tự Unix
Samba chỉ làm việc trong mạng cục bộ Ethernet dùng giao thức TCP/IP
Samba có bốn chức năng căn bản như sau :
<!--[if !supportLists]-->1. <!--[endif]-->Chia xẻ drive Linux với Windows
machines.
<!--[if !supportLists]-->2. <!--[endif]-->Truy cập SMB share với Linux
machines.
<!--[if !supportLists]-->3. <!--[endif]-->Chia xẻ máy in Linux với Windows
machines.
<!--[if !supportLists]-->4. <!--[endif]-->Chia xẻ máy in Windows với Linux
machines.
2. Cài đặt:


Để cài đặt Windows 95/98 dùng TCP/IP, chọn Control Panel | Network, rồi add
and configure Microsoft TCP/IP.
Với Windows NT, chọn Control Panel | Network | Protocols.
Samba package đòi hỏi phải có hai daemons dưới đây. Chúng được cài đặt đầy đủ
trong /usr/sbin and run hoặc được boot từ systems startup scripts hay từ inetd.
smbd (The SMB daemon)
nmbd (Qui dinh NetBIOS của ten may chu hỗ trợ
cho clients)
Tiêu biểu, Samba binaries sau đây được cài trong /usr/bin
hay /usr/local/samba/bin, mặc dù vị trí tuỳ chọn.
smbclient ( SMB client cho UNIX machines)
smbprint ( script de in toi 1 may in trong
may chu SMB )
smbprint.sysv (SBN client cho SVR4 UNIX machines)
smbstatus (danh sach ket noi hien hanh SMB
cho local host)
smbrun (Mot 'glue' script tao thuan tien
cho viec chay cac ung dung tren may chu SMB)

.
Thêm vào đó, một script gọi là ‘print’, đáp ứng như một điểm đầu (front end) hữu
ích đến smpprint script.
Cài đặt tiếp theo, đặt daemons vào /usr/sbin và binaries vào /usr/bin. Cài đặt man
pages vào /usr/local/man.
Khi bạn thực hiện Samba package, nên chỉ định trong Makefile vị trí cho file cấu
hình, smb.conf. Thông thường file này ở /etc, nhưng bạn có thể để nó bất kỳ chỗ
nào tuỳ thích. Về phương diện này , chúng tôi cho rằng bạn chỉ định vị trí của file
cấu hình như /etc/smb.conf, vị trí log file là log file = /var/log/samba-log.%m và
thư mục khóa là lock directory = /var/lock/samba.
Cài đặt file cấu hình, smb.conf. Vào thư mục chứa Samba. Tìm thư mục con

examples/simple và đọc file README. Copy file Smb.conf đã tìm thấy ở thư mục
này vào to /etc.
Nếu bạn không muốn file cấu hình của bạn ở /etc, hãy đặt nó ở đâu cũng được, rồi
cho symlink vào /etc:
ln -s /path/to/smb.conf /etc/smb.conf
3. Cách vận hành Daemons:
Hai SMB daemons là /usr/sbin/smbd and /usr/sbin/nmbd. Dưới phần lớn sự phân
phối của Linux , các daemon này là started, stoped và restarted theo startup script
đặt trong /etc/rc.d/init.d/smb và symlinked tới một runlevel thích hợp.
Nếu không dùng startup script tiêu chuẩn, có thể chạy Samba daemon từ inetd hay
tiến trình stand-alone.Samba sẽ đáp ứng nhanh hơn một chút đối với Stand-alone
daemon hơn là inetd
Mặt khác, bạn nên kiểm tra file /etc/services for lines trông giống như:
netbios-ns 137/tcp nbns
netbios-ns 137/udp nbns
netbios-dgm 138/tcp nbdgm
netbios-dgm 138/udp nbdgm
netbios-ssn 139/tcp nbssn
Phải chắc rằng mọi file đều uncommented. Tuỳ thuộc vào sự phân phối của bạn,
bạn có lẽ còn phải thêm chúng vào. Samba sẽ không thể nối kết với cổng thích
hợp, trừ khi nó có các đầu vào này /etc/services .
Để chạy daemons từ inetd, hãy đặt những dòng theo sau vào inetd configuration
file, /etc/inetd.conf:
# SAMBA NetBIOS services (for PC file and print
sharing)
netbios-ssn stream tcp nowait root /usr/sbin/smbd
smbd
netbios-ns dgram udp wait root /usr/sbin/nmbd nmbd
Rồi restart inetd daemon bằng lịnh:
kill -HUP `cat /var/run/inetd.pid`

Để chạy daemons từ system startup scripts, hãy để các script sau vào
file /etc/rc.d/init.d/smb và symbolically link nó vào files specified bằng lịnh:
#!/bin/sh
#
# /etc/rc.d/init.d/smb - starts and stops SMB
services.
#
# The following files should be synbolic links to
this file:
# symlinks: /etc/rc.d/rc1.d/K35smb (Kills SMB
services on shutdown)
# /etc/rc.d/rc3.d/S91smb (Starts SMB
services in multiuser mode)
# /etc/rc.d/rc6.d/K35smb (Kills SMB
services on reboot)
#
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
# See how we were called.
case "$1" in
start)
echo -n "Starting SMB services: "
daemon smbd -D
daemon nmbd -D
echo
touch /var/lock/subsys/smb

;;
stop)
echo -n "Shutting down SMB services: "
killproc smbd
killproc nmbd
rm -f /var/lock/subsys/smb
echo ""
;;
*)
echo "Usage: smb {start|stop}"
exit 1
esac
Nếu khi khởi động Samba bạn nhận được báo lỗi rằng says something about the
daemon failing to bind to port 139, thì có thể bạn có một Samba process khác
đang chạy rồi mà chưa shut down. Kiểm tra process list (với 'ps auxww | grep
mbd') để xem lại.
4. Cấu hình tổng quát (/etc/smb.conf)
Cấu hình Samba trong một Linux được điều khiển bởi một file đơn, /etc/smb.conf.
File này xác định tài nguyên hệ thống mà bạn muốn chia xẻ với bên ngoài và giới
hạn nào mà bạn muốn đưa vào đó.
Phần [global] định nghĩa vài biến mà Samba dùng để vạch rõ việc chia xẻ mọi tài
nguyên.
Phần [homes] cho phép những user biệt lập truy cập thư mục home của họ trên
local (Linux machine). Nghĩa là, người dùng kết nối vào share này từ Windows
machines, sẽ được kết nối với thư mục cá nhân của họ bằng một tài khoản trên
Linux box.
File smb.conf mẫu dưới đây cho phép người dùng đơn lẻ vào home directories của
họ trong local machine và để viết vào một thư mục tạm. Đối với một Windows
user để thấy được những sự chia xẻ này, Linux box phải hiện hữu trong mạng
local. Rồi người dùng kết nối vào một network drive từ Windows File Manager

hay Windows Explorer.
; /etc/smb.conf
;
; Make sure and restart the server after making changes
to this file, ex:
; /etc/rc.d/init.d/smb stop
; /etc/rc.d/init.d/smb start
[global]
; Uncomment this if you want a guest account
; guest account = nobody
log file = /var/log/samba-log.%m
lock directory = /var/lock/samba
share modes = yes
[homes]
comment = Home Directories
browseable = no
read only = no
create mode = 0750
[tmp]
comment = Temporary file space
path = /tmp
read only = no
public = yes
Để kiểm tra sự chính xác của smb.conf file , dùng tiện ích 'testparm' .
Nếu Samba server của bạn có nhiều giao diện ethernet, bạn có thể thêm vào phần
[global] /etc/smb.conf: như duới đây, để sửa lỗi cho một Samba daemon nào đó.
interfaces = 192.168.1.1/24
5. Chia xẻ một Linux Drive với Windows Machines
Để chia xẻ một directory với public, tạo một dòng ở phần [tmp] nêu trên để thêm
vào smb.conf:

[public]
comment = Public Stuff
path = /home/public
public = yes
writable = yes
printable = no
Để directory trên có thể readable chung, nhưng chỉ writable đối với nhóm có thẩm
quyền, hãy sửa nhu sau:
[public]
comment = Public Stuff
path = /home/public
public = yes
writable = yes
printable = no
write list = @staff
Để sử dụng Samba cho sản phẩm của Microsoft thì hơi khó vì các Window hiên
hành dùng password được mã hoá một cách mặc định mà Samba thì không mà
hóa. Do đó bạn phải cấu hình Samba dùng password mã hoá hoặc ngược lại.
Làm cho Windows hiểu được encrypted SMB passwords hãy vào registry editor:
Windows 95/98 =============
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\VNETSU
P Add a new DWORD value: Value Name: EnablePlainTextPassword Data: 0x01.
Windows NT ==========
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Rdr\Parameters
Add a new DWORD value: Value Name: EnablePlainTextPassword Data: 0x01
Windows 2000 ============
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanWork
Station\Parameters Add a new DWORD value: Value Name:
EnablePlainTextPassword Data: 0x01
Để cấu hình Samba dùng encrypted passwords:

Trong phần [global] của /etc/smb.conf, thêm dòng:
encrypt passwords = yes
smb passwd file = /etc/smbpasswd
Nếu clients và server của bạn dùng encrypted passwords, bạn phải tạo kết nối ban
đầu bằng cách, điền tên phần chia vào Windows File Manager hay Explorer dialog
box, theo form '\\<hostname>\<sharename>'. rồi Logon.
Nếu bạn nghi ngờ NetBIOS name service không đúng cấu hình, hãy dùng địa chỉ
IP address của server: '\\<host ip address>\<sharename>'.
Để filenames thể hiện đúng trong Windows 95/98/NT, bạn còn phải thiết lập vài
tuỳ chọn trong phần share tương ứng:
; Mangle case = yes seems to give the correct
filenames
; for Win95/98/NT.
mangle case = yes
; If samba is case sensitive when looking for files
case sensitive = no
; Default case of files that are created
default case = lower
; Preserve case for all filenames
preserve case = yes
; Preserve case for dos (8.3) filenames
short preserve case = no

6. Truy cập một SMB Share với Linux Machines
Linux (UNIX) machines cũng có thể browse và mount SMB shares, bất kể server
là Windows machine hay Samba server!
Samba có trong chương trình SMB client của UNIX machines. Nó cung cấp một
giao diện ftp-like trong command line. Bạn có thể dùng tiện ích này để chuyển
files qua lại giữa Windows 'server' và một Linux client.
Phần lớn Linux distributions hiện nay cũng bao gồm smbfs package, cho phép

người ta mount và umount SMB shares.
Để thấy shares nào có hiệu lực trên host mà bạn muốn xem:
/usr/bin/smbclient -L host
Tùy theo server, có thể đòi password, và lịnh này xuất ra chẳng hạn như:
Server time is Sat Aug 10 15:58:27 1996
Timezone is UTC+10.0
Password:
Domain=[WORKGROUP] OS=[Windows NT 3.51] Server=[NT LAN
Manager 3.51]
Server=[ZIMMERMAN] User=[] Workgroup=[WORKGROUP]
Domain=[]
Sharename Type Comment
--------- ---- -------
ADMIN$ Disk Remote Admin
public Disk Public
C$ Disk Default share
IPC$ IPC Remote IPC
OReilly Printer OReilly
print$ Disk Printer Drivers
Machine này có browse list:
Server Comment
--------- -------
HOPPER Samba 1.9.15p8
KERNIGAN Samba 1.9.15p8
LOVELACE Samba 1.9.15p8
RITCHIE Samba 1.9.15p8
ZIMMERMAN
Danh sách trình duyệt chỉ ra những SMB servers khác có tài nguyên được chia xẻ
trên mạng.
Để sử dụng client, chạy:

/usr/bin/smbclient service <password>
Ở đây, 'service' là tên một machine và share. Thí dụ, bạn muốn tìm một thu mục được
share như 'public' trên máy zimmerman, hãy làm như sau:
/usr/bin/smbclient \\\\zimmerman\\public mypasswd
bạn sẽ nhận được:
Server time is Sat Aug 10 15:58:44 1996
Timezone is UTC+10.0
Domain=[WORKGROUP] OS=[Windows NT 3.51] Server=[NT LAN
Manager 3.51]
smb: \>
Đánh 'h' để gọi help của smbclient:
smb: \> h
ls dir lcd
cd pwd
get mget put
mput rename
more mask del
rm mkdir
md rmdir rd
prompt recurse
translate lowercase print
printmode queue
cancel stat quit
q exit
newer archive tar
blocksize tarmode
setmode help ?
!
smb: \>
smbclient chỉ dùng để kiểm tra, nếu bạn muốn làm việc thực sự thì phải dùng đến

package với hai tiện ích smbmount và smbumount. Với điều kiện smbfs có hỗ trợ
biên dịch vào kernel .
Sau đây là một kiểu mẫu sử dụng smbmount để mount 1 SMB share là
"customers" từ máy "samba1":
[root@postel]# smbmount "\\\\samba1\\customers" -U
rtg2t -c 'mount /customers -u 500 -g 100'
Added interface ip=192.168.35.84 bcast=192.168.255.255
nmask=255.255.0.0
Got a positive name query response from 192.168.168.158
( 192.168.168.158 )
Server time is Tue Oct 5 10:27:36 1999
Timezone is UTC-4.0
Password:
Domain=[IPM] OS=[Unix] Server=[Samba 2.0.3]
security=user
Phát ra một lịnh mount sẽ chỉ ra các share mounted:
[root@postel]#
mount

/dev/hda2 on / type ext2 (rw)
none on /proc type proc (rw)
none on /dev/pts type devpts (rw,mode=622)
//SAMBA1/CUSTOMERS on /customers type smbfs (0)
7. Chia xẻ một Linux Printer với Windows Machines
Thêm cấu hình printing vào smb.conf:
[global]
printing = bsd
printcap name = /etc/printcap
load printers = yes
log file = /var/log/samba-log.%m

lock directory = /var/lock/samba
[printers]
comment = All Printers
security = server
path = /var/spool/lpd/lp
browseable = no
printable = yes
public = yes
writable = no
create mode = 0700
[ljet]
security = server
path = /var/spool/lpd/lp
printer name = lp
writable = yes
public = yes
printable = yes

×