家庭和办公室中的 Samba
Linux 用户不断尝试,发现 Linux 的用途远远超出了五年前的想象,那时 Linux 本身还只是一项实验。对于许多用户来说,Linux 不仅仅是另一个 Unix 克隆;人们想要更多。Linux 自带内置网络功能,包括连接到互联网所需的所有工具,这使得选择 Linux 变得容易。这个决定不是基于 Linux 的纯粹成本(可以忽略不计),而是基于 Linux 使您能够用 PC 做大量事情。
只需少量投资(或者可能只是重新安排硬件),您就可以拥有一个完整的家庭网络,拥有两台计算机,即使只有其中一台计算机运行 Linux。Linux 也是办公室的良好网络服务器,设置家庭网络可以让您获得设置办公室网络所需的经验。
我甚至不知道 Samba 的存在,直到一位朋友在他的 WFWG 3.11 文件管理器上向我展示了他的 Linux 驱动器。他向我展示了他可以像 Linux 驱动器是本地驱动器一样来回复制文件。他构建的是一个由 2 台计算机组成的小型家庭局域网。他希望在他的主 Linux 服务器上安装 Samba,以便他的孩子们可以在服务器上运行大型程序,而无需占用他们机器上有限的硬盘空间。
家庭局域网安装非常容易。源代码“开箱即用”地编译,并且使用了安装的默认设置
/usr/local/samba/bin 用于二进制文件 /usr/local/samba/lib 用于配置文件 /usr/local/samba/locks 用于 samba 锁 /usr/local/samba/man 用于 samba 手册页 /usr/local/samba/var 用于 samba 日志
一些 Linux 发行版附带了 Samba,在这种情况下,/usr/bin/、/var/samba/ 和 /usr/man 更可能是文件的位置,并且配置文件通常保存在 /etc/smb.conf 中。
一个基本的配置文件(默认为 /usr/local/samba/lib/smb.conf)将包含一些基本条目,如 [global]、[printers] 和 [homes]。这些指定了描述环境的全局配置详细信息、客户端可用的打印机以及用户特定的主目录。您还可以为您希望导出到其他机器的其他目录创建自己的部分;请参阅 [dos] 条目。
配置文件的总体结构类似于 Windows .INI 文件,包含语句部分,以及以 ; 字符开头的独立行上的注释。
;----------------------------------------------
; Service(s): [globals] [homes] [printers]
;----------------------------------------------
[globals]
status=yes
printing = bsd
guest account = dos
browseable = yes
lock directory = /usr/local/samba/locks
domain master = yes
os level=33
[homes]
comment = Home Directories
guest ok = no
read only = no
browseable = yes
[printers]
comment = All Printers
path = /usr/spool/public
printcap name = /etc/printcap
printable = yes
public = yes
writable = no
create mode = 0700
browseable = yes
load printers = yes
[dos]
comment = Dos public directory
path = /g/dos
public = yes
writable = yes
printable = no
guest ok = yes
此配置文件允许 Samba 为网络客户端提供打印机、共享目录和主目录服务。/etc/passwd 文件中必须有一个名为“dos”的用户,没有密码或已知密码(并且最好是 /bin/false 作为 shell,至少在没有密码的情况下),以便拥有一个“世界共享”目录,如 [dos] 部分所示。确保目录(在本例中为 /g/dos/)归此用户“dos”所有。
如果您想要更多关于此文件的解释,请使用 man smb.conf。
在启动时,/usr/local/samba/lib/rc.samba 启动 smbd 和 nmbd 守护进程,并让它们等待客户端连接。我将它们作为守护进程运行,因为当我从 Samba 发出请求时,我想要获得额外的速度。
一个正常的 /usr/local/samba/lib/rc.samba 文件看起来像这样
#!/bin/sh PATH=/usr/local/samba/bin:$PATH smbd -D -d1 nmbd -D -d1 -G MY_WORKGROUP \ -n THIS_MACHINE_NAME
对于 smbd(文件和打印机服务器守护进程)和 nmbd(名称服务器守护进程),-D 选项表示充当守护进程,在后台工作。-d1 表示调试消息比平常更详细一些;一旦您的网络稳定,您可能想要删除它。-G 选项指定计算机应属于的 netbios 组(或 lanmanager 域),-n 选项可用于指定网络上服务器的名称;如果省略,则使用服务器的正常主机名代替。
有些人不同意将 Samba 守护进程作为始终在后台运行的守护进程运行,而更喜欢从 inetd 运行它们。这会降低网络响应速度,但如果需求量不大,则可以减少服务器上的负载。大多数发行版附带的 /etc/inetd.conf 文件中的基本条目是
netbios-ssn stream tcp nowait root /usr/sbin/smbd smbd netbios-ns dgram udp wait root /usr/sbin/nmbd nmbd
您显然必须提供二进制文件的正确路径,才能通过 inetd 调用它们。
在客户端,无论是运行 WFWG 3.11 还是 Win95,TCP/IP 都应该是默认协议。每个具有服务的机器都应显示在浏览列表中。要连接到 Samba 服务器上的 dos 共享服务,您可以只使用基本的 net 命令。
c:\> net use d: \\MACHINE_NAME\dos password : XXXXXX
这对于需要共享几个主目录和一个打印机的小型局域网来说已经足够了。确保有一个有效的 /etc/printcap 文件,其中包含您的打印机的正确条目;设置标准的 Linux 打印超出了本文的范围。您可以执行 man printcap 以获取有关此文件所需语法的更多信息,或者阅读 Linux Printing HOWTO,其中提供了有关打印设置的更详细信息。
我在办公室中使用 Samba 处理大约 20 台计算机的局域网,这更加复杂,但设置起来并不困难,并且非常稳定。如果您只打算设置家庭网络,则可以跳到本文末尾。如果您已经管理 Windows 95 网络,那么此处介绍的特定于 Windows 的信息可能对您来说并不新鲜。
Samba 服务器运行在 Linux 1.2.13 (elf) 上,samba-1.9.15p8 运行在 100MHZ Pentium 上,配备 16M 内存、4G SCSI 磁盘和一个 4G DAT。
Samba 客户端在各种 i486 上运行 WFWG 3.11 和 Win95,配备 8-16M 内存。
1. 通过新的 Win95 注册表的策略: 注册表是一种新格式,用于存储用户和系统特定设置的所有设置。有一个注册表编辑器,用于修改注册表中保存的设置。
策略是用户可以在系统上做什么和不能做什么,以及他们可以在网络上做什么和不能做什么。还有一个策略编辑器,用于编辑用户和计算机策略。
2. 远程登录身份验证: 其中所有 Win95 客户端机器都将 所有 登录到网络和客户端机器的身份验证都通过 Linux 帐户进行。
这是您将 Samba 设置为域控制器的地方。
1. 如果在 smb.conf 文件中您有 user = security 并且您将 Win95 注册表设置为“在访问 windows 之前需要域身份验证”,则使用域密码登录到 Win95 工作站。
2. Samba 具有读取 /etc/passwd 的功能,查找 uid 并验证用户输入的密码是否正确。
3. 如果密码正确,则会将“访问已授予”的结果代码发送到 Win95 机器。
4. 如果 smb.conf 文件中存在 [netlogon] 条目,则会检查此目录中是否存在 config.pol 文件,Win95 机器希望读取该文件以获取机器和用户的策略。这必须在 Win95 设置中,在注册表的“网络设置”中使用“远程更新”和“自动路径”进行设置。
5. 如果您在 smb.conf 文件中具有 logon script = %U.bat,则将为每个用户在客户端上执行指定的批处理文件。(%U 替换为用户名,因此 %U.bat 变为 username.bat—您可以为每个用户设置单独的批处理文件)。确保登录脚本(将保存在 [netlogon] 部分中指定的目录中)使用 DOS 样式行尾;确保这一点的最好方法是在 DOS 系统上使用 DOS 编辑器创建文件。
如果您使用登录脚本,它们会很有用。只需要简单的 DOS 命令
net time /set /yes
会将服务器上的时间与工作站上的时间匹配起来。只需在一个系统上维护时间是很方便的。将策略存储在服务器上是另一个好主意。您可以从另一个工作站更新策略文件,并且下次用户登录时,策略文件将被读取,并且客户端注册表将自动更新!
所有关于这些 Win95 细节的必要信息都可以在 Windows 95 Resource Kit 中找到。有关这些主题的其他讨论可以在以下网址找到
comp.os.ms-windows.networking.tcp-ip 用于 Windows 和 TCP/IP 网络。
comp.os.ms-windows.setup.win95 用于 Win95 中的设置、硬件和驱动程序问题。
comp.os.ms-windows.networking.win95 用于 Win95 到 Novell、TCP/IP、其他网络。
对于较大的局域网,smb.conf 文件如下所示
; ---------------------------------------------
; Service(s): [globals] [homes] [printers]
; ---------------------------------------------
;
[globals]
status = yes
; This enables or disables logging of
; connections to a status file that
; smbstatus can read. Yes by default.
printing = bsd
; See manpage for your system. This
; one is Linux and requires BSD
; printing entries.
guest account = dos
; for printing to work
invalid users = root, @wheel
; don't let super-users access from
; the network
browseable = yes
; By default, everything is browsable
; unless specified elsewhere in
; services sections
hosts allow = 10.10.1.
; you can specify who is allowed in
; 10.10.1. is a class C network that
; never sees the internet
lock directory = /var/lock/samba/locks
; Locks for sessions
log file = /var/log/samba/log.%m
; Individual logfile for each client
; machine
syslog = 2
; Anything level 2 and below will also
; be sent to syslogd
message command = /bin/mail -s \
'message from %f on %m' \
pkelly < %s; rm %s
; If someone sends a "win-popup"
; message - mail it to sys admin
socket options = TCP_NODELAY
dead time = 30
; Close any unused sessions after
; 30 minutes - good for big network.
read prediction = yes
; Speeds up reads from disk
share modes = yes
; For a 'dos share' type of use
max xmit = 8192
; This option controls the maximum
; packet size that will be negotiated
; by Samba.
os level = 33
; This integer value controls what level
; Samba advertises itself as for browse
; elections. See BROWSING.txt for details.
security = user
; For /etc/passwd to be used
; for Domain Logons to work
domain master = yes
; Master browser
domain logons = yes
; For network authentication
logon script = scripts/login.bat
; Single batch file to be executed
; when users logon to the network
; These are simple dos Batch files
; logon script = scripts/%U.bat
; individual batch files - where %U
; is the person's logon name
[netlogon]
comment = Network Logon Services
path = /u/netlogon
; This is the default setting for
; the Win95 machines to look for
; the config.pol file and and .bat
; scripts to run for the client.
writable = yes
; I make this writable so I can add
; or delete items in the config.pol
; file and update the .bat scripts
guest ok = no
; guests not allowed on our network
[homes]
comment = Secure Home Directory for : %u
path = /u/users/%u
; This will match up the user's name
; to their home directory.
guest ok = no
; guests not allowed on our network
read only = no
; Let people write to their own
; home directory.
create mode = 640
; This is handy! I can set this for
; each service differently. So users
; can create files people can't
; delete in their home dir.
writable = yes
; The above "read only = no" does
; this, but I like to be safe :)
browseable = no
; Don't let people know who's home
; directories are there.
[printers]
comment = HP4L in BSC Office
path = /usr/spool/public
printcap name = /etc/printcap
; "man printcap" for details on the
; syntax for your printer.
printable = yes
public = yes
; Everyone connected can print!
writable = no
; Default
create mode = 0700
; Default
browseable = no
; Default
load printers = yes
;-------------------------------------------
; fcp Services
;-------------------------------------------
[programs]
comment = Shared Programs
path = /u/programs
; This is where I store the shared programs
; and have only read access for people.
public = yes
; Public - but not writable for all.
writable = yes
; Writable for the sys admin to install
; new programs.
create mode = 644
; What the ownerships are to be
[data]
comment = Data Directories
path = /u/data
public = no
; You have to be a member of this group
; who owns these files to be able to
; work on the files
create mode = 770
; This is for all the database files that
; need to be shared and group writable.
; The 770 is needed because dir-'s are
; sometimes created and need to be
; executable in order to work right.
writeable = yes
; Allow people to write and delete files
volume = "Data on Fileserver"
我完全用 Win95 和 Windows for Workgroups 作为客户端,Linux Samba 服务器作为服务器替换了 LANtastic 网络,使用了该配置。TCP/IP 是唯一使用的协议,并且人们过去使用 LANtastic 的对等网络仍然可以通过客户端网络软件使用。
我完全消除了从 Angus Systems Group Ltd. 编写的多用户 C-Tree 数据库中获得的所有与网络相关的错误。来自 Samba 服务器的所有磁盘访问都减少到过去所需时间的一半左右,并且整个系统的性能比以前的 MS-DOS 文件服务器好得多。MS-DOS .EXE 在网络上的加载速度快了三倍。
Peter Kelly (pkelly@ets.net) 是 JDP Computer Systems 和 Systems Software 的网络管理员。他还为 O & Y Properties Inc. 的 First Canadian Place 1 号楼执行数据库和网络功能。有时他会离开他的 Linux X-Workstation 出去吃饭或参加多伦多大学计算机科学学院的兼职课程。
