Professional Documents
Culture Documents
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
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
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.
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.
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.
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
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ư:
Để chạy daemons từ inetd, hãy đặt những dòng theo sau vào inetd configuration
file, /etc/inetd.conf:
Để 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)
#
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.
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
Để 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:
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
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanWork
Station\Parameters Add a new DWORD value: Value Name:
EnablePlainTextPassword Data: 0x01
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
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 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.
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]#
mount
[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
print command = lpr -r -h -P %p %s
Cổng vào /etc/printcap dưới đây của máy in HP 5MP trên máy chủ Windows NT :
cm - comment
lp - device name to open for output
sd - the printer's spool directory (on the
local machine)
af - the accounting file
mx - the maximum file size (zero is unlimited)
if - name of the input filter (script)
# /etc/printcap
#
# //zimmerman/oreilly via smbprint
#
lp:\
:cm=HP 5MP Postscript OReilly on zimmerman:\
:lp=/dev/lp1:\
:sd=/var/spool/lpd/lp:\
:af=/var/spool/lpd/lp/acct:\
:mx#0:\
:if=/usr/bin/smbprint:
Phải chắc rằng thư mục spool và accounting hiện hữu và writable; 'if' line có
đường dẫn phù hợp với smbprint script; và chỉ đến một thiết bị thích hợp.
#!/bin/sh -x
#
# Script further altered by hamiltom@ecnz.co.nz
(Michael Hamilton)
# so that the server, service, and password can be read
from
# a /usr/var/spool/lpd/PRINTNAME/.config file.
#
# In order for this to work the /etc/printcap entry
must include an
# accounting file (af=...):
#
# cdcolour:\
# :cm=CD IBM Colorjet on 6th:\
# :sd=/var/spool/lpd/cdcolour:\
# :af=/var/spool/lpd/cdcolour/acct:\
# :if=/usr/local/etc/smbprint:\
# :mx=0:\
# :lp=/dev/null:
#
# The /usr/var/spool/lpd/PRINTNAME/.config file should
contain:
# server=PC_SERVER
# service=PR_SHARENAME
# password="password"
#
# E.g.
# server=PAULS_PC
# service=CJET_371
# password=""
#
# Debugging log file, change to /dev/null if you like.
#
logfile=/tmp/smb-print.log
# logfile=/dev/null
#
# The last parameter to the filter is the accounting
file name.
#
spool_dir=/var/spool/lpd/lp
config_file=$spool_dir/.config
#
# Some debugging help, change the >> to > if you want
to same space.
#
echo "server $server, service $service" >> $logfile
(
# NOTE You may wish to add the line `echo translate' if
you want automatic
# CR/LF translation when printing.
echo translate
echo "print -"
cat
) | /usr/bin/smbclient "\\\\$server\\$service"
$password -U $user -N -P >> $logfile
Hầu hết các Linux distributions dùng nenscript để chuyển đổi từ văn bản ASCII
sang Postscript. Perl script makes sau đây cung cấp một giao diện đơn giản công
việc in của Linux qua smbprint.
Dùng smbprint để in ASCII files nhằm rút ngắn những hàng dài. Script này ngắt
dòng bằng khoảng trắng.
Việc định dạng source code được thực hiện bởi nenscript. Nó lấy một file ASCII
và foramts file này thành 2 cột có gán tiêu đề (date, filename, etc), nó cũng đánh
số trang.
Những văn bản viết bằng Postscript thì luôn luôn được dịnh dang hoàn chỉnh, nên
không cần phải làm gì cả.
#!/usr/bin/perl
# Script: print
# Authors: Brad Marshall, David Wood
# Plugged In Communications
# Date: 960808
#
# Script de in toi mot may in Postscript theo Samba.
# Purpose: Takes files of various types as arguments
and
# processes them appropriately for piping to a Samba
print script.
#
# Currently supported file types:
#
# ASCII - ensures that lines longer than
$line_length characters wrap on
# whitespace.
# Postscript - Takes no action.
# Code - Formats in Postscript (using nenscript)
to display
# properly (landscape, font, etc).
#
unless ( -f $print_prog ) {
die "Can't find $print_prog!";
}
unless ( -f $nenscript ) {
die "Can't find $nenscript!";
}
&ParseCmdLine(@ARGV);
# DBG
print "filetype is $filetype\n";
if ($filetype eq "ASCII") {
&wrap($line_length);
} elsif ($filetype eq "code") {
&codeformat;
} elsif ($filetype eq "ps") {
&createarray;
} else {
print "Sorry..no known file type.\n";
exit 0;
}
# Pipe the array to smbprint
open(PRINTER, "|$print_prog") || die "Can't open
$print_prog: $!\n";
foreach $line (@newlines) {
print PRINTER $line;
}
# Send an extra linefeed in case a file has an
incomplete last line.
print PRINTER "\n";
close(PRINTER);
print "Completed\n";
exit 0;
# --------------------------------------------------- #
# Dưới đây là một subroutine
# ---------------------------------------------------
sub ParseCmdLine {
# Parses the command line, finding out what
file type the file is
$arg = shift(@_);
if ($arg =~ /\-./) {
$cmd = $arg;
# DBG
# print "\$cmd found.\n";
$file = shift(@_);
} else {
$file = $arg;
}
if ($file =~ /\.ps$/) {
$filetype = "ps";
} elsif ($file =~ /\.java$|\.c$|\.h$|
\.pl$|\.sh$|\.csh$|\.m4$|\.inc$|\.html$|\.htm$/) {
$filetype = "code";
} else {
$filetype = "ASCII";
}
sub usage {
print "
Usage: print [-a|c|p] <filename>
-a prints <filename> as ASCII
-c prints <filename> formatted as source code
-p prints <filename> as Postscript
If no switch is given, print attempts to
guess the file type and print appropriately.\n
";
exit(0);
}
sub wrap {
# Create an array of file lines, where each
line is < the
# number of characters specified, and wrapped
only on whitespace
# DBG
#print "Entering subroutine wrap\n";
#print "The line length limit is $limit\n";
# DBG
#print "The line is:\n$line\n";
# DBG
#print "Wrapping...";
# DBG
#print "The partial line
is:\n$part\n";
# DBG
#print "The last character
was a space\n";
substr($line,0,$limit + 1)
= "";
substr($part,-1,1) = "";
push(@newlines,"$part\n");
} else {
# If it is not, find the
last space in the
# sub-line and print up to
there.
# DBG
#print "The last character
was not a space\n";
push(@newlines,substr($part,0,$limit-$index)
. "\n");
} else {
# There was no space in
the line, so
# print it up to $limit.
substr($line,0,$limit) =
"";
push(@newlines,substr($part,0,$limit)
. "\n");
}
}
}
push(@newlines,$line);
}
close(FILE);
}
sub codeformat {
# Call subroutine wrap then filter through
nenscript
&wrap($line_length);
sub createarray {
# Create the array for postscript
open(FILE, "<$file") || die "Can't open $file:
$!\n";
while(<FILE>) {
push(@newlines,$_);
}
close(FILE);
}
3) Viết bộ lọc /usr/local/bin/main-filter giống như bạn đề nghị dùng bộ lọc ljet4l-
filter thay vì dùng cat.
Here's mine.
P.S. : đây là đọan trích từ Print2Win mini-Howto về việc locking và tạo máy in ảo.
lpr làm một 'exclusive' mở trên file mà bạn chỉ định như lp=. Nó làm điều này để
ngăn chặn nhiều quá trình in tới máy in chính trong cùng một lúc.
tác động thứ yếu của việc này là , eng và colour không thể in cùng lúc, ngược lại
mọi tiến trình ghi khác vào /dev/null sẽ bị ngắt!
Đối với hệ thống đơn người dùng đây có lẽ không phải là vấn đề lớn, nhưng với hệ
thống chừng 50 may in, nó sẽ trở thành vấn đề
Để giải quyết, ta dùng máy in gỉa cho mỗi máy như: touch /dev/eng.
Sửa đầu vào của lp trong printcap file ở trên như sau:
---Kết thúc
Script sau đây dùng tiện ích smbclient để backup Windows 3.x và NT machines
vào Linux based DAT SCSI Drive do Adam Neat
Chuỗi 'agnea1' là username trên Linux machine thực hiện việc backups.
#!/bin/bash
clear
echo Initialising ...
checkdate=`date | awk '{print $1}'`
if [ -f "~agnea1/backup-dir/backup-data" ]; then
if [ -d "~agnea1/backup-dir/temp" ]; then
#########################################################
# Main Section
#
#########################################################
cd ~agnea1/backup-dir/temp
rm -r ~agnea1/backup-dir/temp/*
cd ~agnea1/backup-dir/
case "$checkdate"
in
Mon)
echo "Backuping for Monday"
cat backup-data |
/usr/local/samba/bin/smbclient
\\\\$1\\$2 -I$3 -N echo "Complete"
if [ -d "~agnea1/backup-dir/Monday"
]; then
echo "Directory Monday Not
found ...
making" mkdir
~agnea1/backup-dir/Monday
fi
Tue)
echo "Backuping for Tuesday"
cat backup-data |
/usr/local/samba/bin/smbclient
\\\\$1\\$2 -I$3 -N echo "Complete"
if [ -d "~agnea1/backup-
dir/Tuesday" ]; then
echo "Directory Tuesday Not
found ...
making" mkdir
~agnea1/backup-dir/Tuesday
fi
echo "Archiving ..."
cd ~agnea1/backup-dir/temp
tar -cf tuesday.tar *
echo "done ..."
rm ~agnea1/backup-dir/Tuesday/tuesday.tar
mv tuesday.tar ~agnea1/backup-dir/Tuesday
;;
Wed)
echo "Backuping for Wednesday"
cat backup-data |
/usr/local/samba/bin/smbclient
\\\\$1\\$2 -I$3 -N echo "Complete"
if [ -d "~agnea1/backup-
dir/Wednesday" ]; then
echo "Directory Wednesday
Not found
... making" mkdir
~agnea1/backup-dir/Wednesday
fi
echo "Archiving ..."
cd ~agnea1/backup-dir/temp
tar -cf wednesday.tar *
echo "done ..."
rm ~agnea1/backup-dir/Wednesday/wednesday.tar
mv wednesday.tar ~agnea1/backup-
dir/Wednesday
;;
Thu)
echo "Backuping for Thrusday"
cat backup-data |
/usr/local/samba/bin/smbclient
\\\\$1\\$2 -I$3 -N echo "Complete"
if [ -d "~agnea1/backup-
dir/Thursday" ]; then
echo "Directory Thrusday
Not found ...
making" mkdir
~agnea1/backup-dir/Thursday
fi
echo "Archiving ..."
cd ~agnea1/backup-dir/temp
tar -cf thursday.tar *
echo "done ..."
rm ~agnea1/backup-dir/Thursday/thursday.tar
mv thursday.tar ~agnea1/backup-dir/Thursday
;;
Fri)
echo "Backuping for Friday"
cat backup-data |
/usr/local/samba/bin/smbclient
\\\\$1\\$2 -I$3 -N echo "Complete"
if [ -d "~agnea1/backup-dir/Friday"
]; then
echo "Directory Friday Not
found ...
making" mkdir
~agnea1/backup-dir/Friday
fi
echo "Archiving ..."
cd ~agnea1/backup-dir/temp
tar -cf friday.tar *
echo "done ..."
rm ~agnea1/backup-dir/Friday/friday.tar
mv friday.tar ~agnea1/backup-dir/Friday
;;
*)
echo "FATAL ERROR: Unknown variable passed
for day"
exit 1;;
esac
#!/bin/bash
BACKDIR=3D/backup
WINCMD=3D/usr/bin/smbclient
function CopyWinHost(){
echo $1,$2,$3
REMOTE=3D$1
SHARE=3D$2
DEST=3D$3
function CopyUnixHost(){
REMOTE=3D$1
SRC=3D$2
DEST=3D$3
1) Mọi computers mà bạn có thể xem được phải được cài đặt chung một WINS
server (Samba hay NT )
2) Bộ duyệt chính cho mỗi subnet phải là NT hay Samba. (không phải là Win9X)
3) Phải sử dụng cùng một tên workgroup cho mọi subnets. Điều này không thực
sự cần thiết nhưng là cách đơn giản nhất để bảo đảm thành công. Nếu bạn không
thể sắp đặt như vậy thì bạn phải tổ chức cách thức thông tin cho trình duyệt để
propogate giữa các subnets. (Nó không propogate qua WINS). Nó propogates qua
hai cơ cấu:
i) mỗi một bộ duyệt chính nhận biết các thông báo của workgroup từ các bộ
duyệt chính khác trên một broadcast domain giống nhau
ii ) mỗi browse master giao tiếp với global DMB cho workgroup (tiêu biểu
domain controller hay một Samba box được đánh dấu như là domain master) và
trao đổi đầy đủ thông tin tình duyệt một cách định kỳ
Cũng như vậy, Rakesh Bharania chỉ ra rằng Cisco routers có thể được cấu hình để
chuyển tiếp SMB traffic bằng cách cho phép trình duyệt. Đề nghị của ông ta là cấu
hình giao diện đường truyền hosts SMB clients bằng lịnh:
ip helper-address x.x.x.x