Chinaunix首页 | 论坛 | 博客
  • 博客访问: 799069
  • 博文数量: 770
  • 博客积分: 5000
  • 博客等级: 大校
  • 技术积分: 4950
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-09 17:49
文章分类

全部博文(770)

文章存档

2011年(1)

2008年(769)

我的朋友

分类:

2008-10-10 11:24:01

[center]声明此文是从网上下载的作者不详,那位网友知道此文的作者麻烦通知一声我会把作者名字补上[/center]


[center]E-mail服务器的建立[/center]

E-mail 以其快捷方便的特性成为人们使用最多的工具,安装设置M a i l服务器软件是一个必不可少的部分。本章详细介绍电子邮件服务器软件的安装设置及其使用中的一些技巧。常见的电子邮件服务器有三种: S e n d m a i l服务器、邮局协议( P O P )邮件服务器和U n i x - t o - U n i xCopy (UUCP) 服务器。S e n d m a i l服务器处理Internet 中来回传输的S T M P邮件。S T M P为简单邮件传输协议,它是从一个站点到另一个站点传输邮件的标准协议。P O P服务器如同邮局一样地保管信件。用户可以直接和P O P服务器连接,它将负责将邮件传送给他们。U U C P服务器的性质介于S T M P及P O P之间。

1.sendmail 服务器的设置:
S e n d m a i l对一般的系统管理者而言,往往是个难点,因为系统的使用者对E - m a i l的需求与依?*潭雀撸?荒苡蟹趾敛畲怼Sendmail 8.9.3.1是目前Sendmail 8.9.x系列的最高版本。系统安全方面,是目前评价最好的,目前已知的BUG 都已经改好了。因为本软件是一public domain ,可以在网路上各f t ps e r v e r上找到其source code。由于该软件的发展者把一些必要的设定步骤自动化了,所以,其实安装这个软件并不是非常的困难。笔者把S e n d m a i l的安装分成几个步骤:

1) 获取此软件:(通过f t p相关站点或直接从安装光盘上获取),至少要有
sendmail.8.9.3.1.base.tar.gz
sendmail.8.9.3.1.cf.tar.gz
sendmail.8.9.3.1.xdoc.tar.gz

这三个文件,其中,第一个文件是此软件的程序;第二个文件是此软件的设定,此二者是必要的文档;第三个是文本文件,如果不想看,可以不要。得到以上文件以后,解开文件。建议管理者读一读此软件的相关文件。
2) 全解压开后应该会在该目录下建立几个目录,其中程序是在“~ / s e n d m a i l / s r c”的目录下,设定文件在“~ / s e n d m a i l / c f”目录下。请1转换至“~ / s e n d m a i l / s r c” 的目录,用ls 命令可以看到许多名Makefile.xxx 的文件档案。请使用者找到一个适合自己系统的m a k e f i l e,如:假设是用IBM AIX 的系统,那就使用M a k e f i l e . A I X;用H P的系统,那就用M a k e f i l e . H P - U X;如果是Sun 系统,那就用M a k e f i l e . S u n O S . x . x,但如果是SunOS 4.1.3 ,就得要用M a k e f i l e . S u n O S这个m a k e f i l e文件,而如果是Solaris 2.3 ,则得要用M a k e f i l e . S u n O S . 5 . x。用v i或任何其他编辑器,调出刚挑出的m a k e f i l e文件,做一点点必要的修改。所要修改的地方不多,下面是可能要修改的地方:
• "CC ="如果原文件所用的c o m p i l e r并不是自己系统的,这才要改。
• 本系统是否有安装Berkerlay 的New database?如果有,跳过本点,到第3 点。如果没有(如:一般SunOS 都没有装),那么请修改这几行(下面以M a k e f i l e . S u n O S为例,但其他系统也类似):
a .在DBMDEF= -DNDBM -DNEWDB -DNIS 一行,请改成:DBMDEF= -DNDBM -DNIS(即去掉- D N E W D B )
b .把这两行R E M A R K起来:I N C D I R S = - I / u s r / s w w / i n c l u d e / d b--> # INCDIRS=-I/usr/sww/include/dbL I B D I R S = - L / u s r / s w w / l i b--> # LIBDIRS=-L/usr/sww/lib
c .修改LIBS= -ldb -ldbm -lresolv 这一行成:LIBS= -ldbm -lresolv(即去掉- d b )把n r o ff的“- m a n d o c”参数改成一般系统可以接受的“- m a n”(当然,这得依你的系统而定)。如果不改也并不会影响s e n d m a i l的安装,只是不能看到格式化后的s e n d m a i l相关文件罢了。

3) 输入make -f Makefile.xxx等待编译完毕。不过,笔者可以乘这个空文件把旧的s e n d m a i l相关文件案备份起来,以防万一有什么不测,还可以有所储备) 。要备份的文件是:/usr/lib/sendmail 和s e n d m a i l . c f (后者所在位置得依原系统而定,不过,一般都是在/ e t c下或/ e t c / m a i l下)。有一点要记住的是,原来的/usr/lib/sendmail 是个suid root的程序,备份的请记住执行chmod u-s xxxx,要不然,留着这样一个suid root 的程序,也是会让人有机可乘的!

4) 此一步骤也可以在compile 程序时进行,就是要产生系统设定文件,即sendmail.cf 。请切换至设定文件目录~ /sendmail/cf/cf 之下。找一个合适自己系统的x x x x . m c文件。笔者一般是使用tcpproto.mc 这一个不用u u c p的文件。如果是用tcpproto.mc 这个文件,笔者在solaris 2.3试了,在文件中要加上一行: OSTYPE(solaris2) ,如果不小心忘了加上O S T Y P E ( ),会有“unknow mailer” 的错误,然后信寄不出去。选定了某一个合意的.mc 文件,接下来可执行m 4产生.cf 文件。请用下面指令:
# m4 XXX.mc > YYY.cf如果是sun 4.1.3 ,可能系统会抱怨m 4的版本太旧了。请试用:
# /usr/5bin/m4 XXX.mc >YYY.cf若还是不行,那就去找新版的m 4回来c o m p i l e。产生出来的Y Y Y. c f一般得要改某个地方才能正常地收信。请寻找“ C w”,原来产生的. c f文件,C w应是:Cwlocalhost请在localhost 之后加上你那一台机器所有可能用来当收信地址的host name ,如:
Cwlocalhost tarn.ustc.edu.cn man.ustc.edu.cn
如果这个步骤忘了做,将会有从外面机器寄信来却收不到,机器会抱怨:"configure error ...."

5) 这个步骤是要把c o m p i l e好的东西install 到系统上去了。假设compile 的结果没有任何错误,产生.cf 文件过程也就没有什么值得注意的信息。所产生的.cf 文件也改好了。切换至目录~/sendmail/src ,下指令:
# make -f Makefile.XXX install
系统会把c o m p i l e出来的~/ s e n d m a i l / s r c / s e n d m a i l与man document拷贝到它们该有的目录。切换至目录~/sendmail/cf/cf ,把产生出来的Y Y Y. c f文件拷贝到本系统sendmail.cf 应该在的地方,如:/ e t c或/etc/mail 。把旧sendmail daemon 的process kill 掉。用ps -ax |grep sendmail |grep -v grep 找出旧d a e m o n的p r o c e s s (或cat /etc/sendmail.pid 或cat /etc/mail/sendmail.pid),然后用kill -9 processIDkill 掉它。启动新d a e m o n。例如下指令:
/usr/lib/sendmail -bd -q30m
当然,保守一点,看旧的d a e m o n怎么跑,照旧的来下参数应该没有问题。

6) 这个步骤主要用来测试:
a. local 的收、发信。
b. remote的收、发信。
c. 最好当然能试试不同的domain 或甚至net 的收发情况。

2.在Linux机器上设置pop3代理
在L i n u x服务器上, h t t p / h t t p s / f t p代理的应用非常广泛, s q u i d大家都很熟悉,但是有些特殊情况下,你可能需要让一台L i n u x机器也做为p o p 3代理服务器,代理客户端从互联网上接收邮件,并传送邮件给客户工作站。也许这种服务对于专线连到I S P的用户更适合,在有的公司的内部网中,需要从外部世界收信,可能你不能直接与外部世界通信,但能很容易地访问到你的防火墙机器。这时,在防火墙机器上安装p o p 3代理就起到了一种不可替代的作用。软硬件环境:R e d h a t 6 . 0,T I S通用防火墙代理服务程序plug-gw (下载),实现方法:
1) 安装p o p 3代理非常简单,仅需要下载上面提到的一个很小的程序p l u g - g w即可,下载后放入/ u s r / l o c a l / e t c目录下(需要执行权限)。
2) 这里假设你需要代理互联网上两个邮件服务器,一个是tarn.ustc.edu.cn , 另一个是pop3.263.net.
3) 在/ u s r / l o c a l / e t c目录下创建存取表文件n e t p e r m - t a b l e,像下面这样:
root@sh-proxy etc # more netperm-table
plug-gw: port 110 192.168.13.* -plug-to
public.sta.net.cn-port110
plug-gw: port 114 192.168.13.21 -plug-to pop3.163.net -port110
root@sh-proxy etc # ls -l
total 24
-rwxrwxr-x 1 root root 314 Sep 14 17:58 netperm-table
-r-xr-xr-x 1 root root 22489 Dec 31 1998 plug-gw
注意第一行允许1 9 2 . 1 6 8 . 1 3 . 0网段上任何机器使用该代理服务器接收p u b l i c . s t a . n e t . c n上的邮件。第二行仅允许一台机器1 9 2 . 1 6 8 . 1 3 . 2 1使用该代理服务器接收p o p 3 . 2 6 3 . n e t上的邮件。
4) 修改/ e t c / s e r v i c e s,加下面的一行:pop3proxy 114/tcp
5) 在命令行下运行两句程序,也可加入到/ e t c / r c . d / r c . l o c a l的最后,使得每次启动时装载:
# /usr/local/etc/plug-gw -daemon pop3 pop3 &
# /usr/local/etc/plug-gw -daemon pop3proxy pop3proxy &
注意请确信/ e t c / s e r v i c e s中存在一行pop3 110/tcp ,若前面的名字不是p o p 3,而是其他的如p o p - 3等,那么或者更新为pop3 11 0 / t c p,或者运行/usr/local/etc/plug-gw -daemon pop-3 pop-3 &
6) 若在Wi n d o w s客户端用outlook express收发邮件,若从p u b l i c . s t a . n e t . c n收信,仅需改p o p 3服务器为你的防火墙即可,若从p o p 3 . 2 6 3 . n e t收信,还得更改标准p o p 3端口号为11 4 ,而不是11 0。
[center] [/center]
[center]FTP服务器的建立[/center]

目前很多企业单位正在构架自己的I n t r a n e t,F T P服务器是其中的一个服务支持,有很多单位还配置了基于U N I X平台的计算机,为了在网上能够提供F T P服务支持,专门购置基于U N I X平台的FTP Server软件,其实在基于U N I X平台的计算机系统中,采取一定的技术方法,就可以建立自己的F T P S e r v e r,实现网上文件上下载服务,无须再购置专门的软件,何乐而不为之呢?下面就其建立过程阐述如下:
1) 确定FTP Server的共享目录。为FTP Server建立一个F T P工作目录,在此设定为/ h o m e / f t p
2) 编写FTP Server初始设置的S h e l l程序( s e t u p )。用编辑工具(如v i )编写一个S h e l l程序,用于对系统进行设置。
# ! / b i n / s h
case $# in
0) ftphome="`grep '^ftp:' /etc/passwd | cut -d: -f6`"
;;
1) if [ "$1" = "start" ]; then
ftphome="`grep '^ftp:' /etc/passwd | cut -d: -f6`"
e l s e
f t p h o m e = $ 1
f i
; ;
*) echo "Usage: $0 [anon-ftp-root]"
exit 1
; ;
e s a c
if [ -z "${ftphome}" ]; then
echo "$0: ftphome must be non-null"
exit 2
f i
if [ "${ftphome}" = "/" -o "${ftphome}" = "/usr" ]; then
echo "$0: ftphome must not be / or /usr"
exit 2
f i
if [ ! -d ${ftphome} ]; then
mkdir ${ftphome}
f i
if [ ! -d ${ftphome}/usr/bin ]; then
if [ ! -d ${ftphome}/usr/bin ]; then
mkdir -p ${ftphome}/usr/bin
f i
cp /usr/bin/ls ${ftphome}/usr/bin
chmod 111 ${ftphome}/usr/bin/ls
chown root ${ftphome}/usr/bin
chmod 555 ${ftphome}/usr/bin
if [ -r ${ftphome}/bin ]; then
mv -f ${ftphome}/bin ${ftphome}/Obin
f i
ln -s usr/bin ${ftphome}
if [ ! -d ${ftphome}/usr/lib ]; then
mkdir -p ${ftphome}/usr/lib
f i
if [ ! -d ${ftphome}/etc ]; then
mkdir -p ${ftphome}/etc
f i
cp /usr/lib/ld.so /usr/lib/ld.so.1 ${ftphome}/usr/lib
for lib in libc libdl libintl libw libnsl libsocket \
nss_nis nss_nisplus nss_dns nss_files
d o
cp /usr/lib/${lib}.so.1 ${ftphome}/usr/lib
rm -f ${ftphome}/usr/lib/${lib}.so
ln -s ./${lib}.so.1 ${ftphome}/usr/lib/${lib}.so
d o n e
cp /usr/lib/straddr.so.2 ${ftphome}/usr/lib
rm -f ${ftphome}/usr/lib/straddr.so
ln -s ./straddr.so.2 ${ftphome}/usr/lib/straddr.so
cp /etc/passwd /etc/group /etc/netconfig ${ftphome}/etc
chmod 555 ${ftphome}/usr/lib/*
chmod 444 ${ftphome}/etc/*
chown root ${ftphome}/usr/lib ${ftphome}/etc
chmod 555 ${ftphome}/usr/lib ${ftphome}/etc
if [ ! -d ${ftphome}/dev ]; then
mkdir -p ${ftphome}/dev
f i
p r e f i x = " / d e v i c e s / p s e u d o / m m @ 0 : "
for device in zero
d o
line=`ls -l ${prefix}${device} | sed -e 's/,//'`
major=`echo $line | awk '{print $5}'`
minor=`echo $line | awk '{print $6}'`
rm -f ${ftphome}/dev/${device}
mknod ${ftphome}/dev/${device} c ${major} ${minor}
done
p r e f i x = " / d e v i c e s / p s e u d o / c l o n e @ 0 : "
for device in tcp udp ticotsord
d o
line=`ls -l ${prefix}${device} | sed -e 's/,//'`
major=`echo $line | awk '{print $5}'`
minor=`echo $line | awk '{print $6}'`
rm -f ${ftphome}/dev/${device}
mknod ${ftphome}/dev/${device} c ${major} ${minor}
d o n e
chmod 666 ${ftphome}/dev/*
chown root ${ftphome}/dev
chmod 555 ${ftphome}/dev
#建立一个匿名F T P服务目录,并设立可读可写属性
if [ ! -d ${ftphome}/pub ]; then
mkdir -p ${ftphome}/pub
f i
chown ftp ${ftphome}/pub
chmod 777 ${ftphome}/pub
3) 编辑/ e t c / p a s s w d和/ e t c / s h a d o w文件。设置匿名F T P帐号,按下面方法分别对/ e t c / p a s s w d和/ e t c / s h a d o w两个文件中增加如下数据:在/ e t c / p a s s w d文件中增加
ftp:x:30000:30000:Anonymous FTP:/home/ftp:/nosuchshell
在/ e t c / s h a d o w文件中增加
f t p : N P : 6 4 4 5 : : : : : :
4) 运行s e t u p程序。
在运行s e t u p程序之前,将该文件设置成执行文件。
#chmod +x setup
运行s e t u p程序#setup /home/ftp
以上步骤就完成了F T P服务器的建立,即可使用F T P 服务器,可以用如e x p l o r e r、n e t s c a p e。n a v i g a t o r等浏览器对F T P服务器进行访问,进行下载和上载文件操作,使用非常方便。      
--------------------next---------------------
[center]建立S a m b a服务器[/center]

不管现在身在何处,只要身边有电脑的话,几乎都可以看到Wi n d o w s 9 5 / N T的踪影,因为Wi n d o w s 9 5 / N T的G U I界面漂亮、直观、简单易用,不能不让人想使用它,但L i n u x的爱好者欢L i n u x系统的开放和每天有挖掘不完的新东西,自己可以把L i n u x弄的千变万化,完全适用于自己的电脑与本身的喜好。两种操作系统的优良特性如果能互相配合,那不是挺好的吗?但是L i n u x与Wi n d o w s 9 5 / N T之间的连线只能靠T C P / I P,从Windows95/NT telnet到L i n u x或是用f t p做文件传输而己! L i n u x虽然有N F S可以有效和Wi n d o w s 9 5 / N T相连,然而Wi n d o w s 9 5 / N T目前似乎没有一套免费、易用的N F S软件可以和L i n u x沟通。两种操作系统之间似乎毫无关系!但自从“S a m b a”出现后,从此为L i n u x和Wi n d o w s 9 5 / N T搭起友谊的桥梁了。
1 Samba是什么
基本上,S a m b a可以想成是一个局域网络上的File/Printer Server,可以提供文件系统、打印机或是其他的信息并与Samba Server在同一个子网域( s u b n e t )的Samba client(如Wi n d o w s 9 5、Wi n d o w s N T、Wa r p S e r v e r、s m b f s等)共享。因为它的基本工作原理是让N e t b i o s ( Wi n d o w s 9 5网络邻居的通信协议)与SMA(Server Message Block)这两种协议运行在T C P / I P的通信协议上,且使用Netbios nameserver 让你的L i n u x机器可以在网络邻居上被看到,所以L i n u x就可以和Wi n d o w s 9 5 / N T在网络邻居上沟通,互相浏览分享文件了。也就是说, Smaba Server可以让你的L i n u x变成如Novell Server一般,可以让Wi n d o w s 9 5的使用者用网络邻居分享L i n u x的文件和打印机了。
2 安装Samba
S a m b a这套免费的软件里面包含了Samba Server和Samba Client,所以装好S a m b a后,不只是可以提供资源给别人,同样也可以用Samba Client 去分享其他Samba Server 或是Wi n d o w s 9 5 / N T网络邻居上的机器共享出来的资源。基本上, S a m b a是为U N I X系统所发展的,但目前也有N e t Wa r e、Windows NT、O S / 2和V M S版的S a m b a了,如果想尝试使用别的操作系统的S a m b a也是非常容易的一件事!而在使用Red Hat Linux安装S a m b a之前,建议k e r n e l最好是用2 . 2 . 1 0版的,因为它针对S a m b a的b u g做了些修正,在使用Samba client打印文件名时会稳定一些。在Red Hat Linux下安装S a m b a是最简单不过的了,只要几个步骤就可以解决了。目前最新版的S a m b a版本为2 . 0 . 3 p 8,表示2 . 0 . 3版p a t c h第8次。在Red Hat Linux发行版所附光盘中,即捆绑有S a m b a - 2 . 0 . 3 - 8 . i 3 8 6 . r p m软件,你可以直接从光盘上安装。当然了,你也可以从其他渠道(比如I n t e r n e t上S a m b a的主页: h t t p:/ / w w w. a p a c h e . o rg上下载A p a c h e的最新版本)获得S a m b a软件,如果是S a m b a的源程序代码压缩文件,你首先得将它进行解压缩,然后进行编译才可以使用。以S a m b a - 1 . 9 . 1 7 p 2 . t a r. g z文件为例,讲一下编译的基本步骤: (如果使用Red Hat Linux 4.1光盘中捆绑的S a m b a - 2 . 0 . 3 - 8 . i 3 8 6 . r p m软件,因为它是R P M类型文件,无须编译,可直接跳过这一步骤)。我们现在就开始安装S a m b a。请依照下列步骤完成:
1) 解压缩文件。
取得s a m b a - 1.9.1 7 p 2 . t a r. g z文件,然后随便找个目录将它解压缩,包文件解压缩后,直接会产生目录s a m b a - 1.9.1 7 p 2 /:
# tar zxvf samba-1 .9.1 7 p 2 . t a r . g z
阅读安装说明文件,获取帮助,先看看R E A D M E,再到d o c s /下看看其他文件和执行:
# nroff -man smbd.8|less
# nroff -man nmbd.8|less
相信会得到非常多的帮助。
2) 进入s o u r c e /,编辑M a k e f i l e文件。先看一下R E A D M E、I N S TA L L之类的文件,对于安装软件会有很大的帮助。因为S a m b a可适用于多种U N I X操作系统,所以M a k e f i l e里面定义了非常多的U N I X系统,我们只要找出定义L i n u x的部份,然后将#删除就可以了。而这一版S a m b a的M a k e f i l e里面对L i n u x有五种定义情况,请选择一种。基于安全性考虑,建议用第三种方式包含有shadow passward与q u o t a来编译S a m b a:Use this for Linux with shadow passwords先从M a k e f i l e中找到上面这一段字。假如系统有安装shadow password,就将M a k e f i l e里面这一段的
# FLAGSM = -DLINUX -DSHADOW_PWD -DFAST_SHARE_MODES
# LIBSM = -lshadow
这两行的#号删除,然后储存M a k e f i l e进行第3步骤。
Use this for Linux without shadow passwords
假如你的系统没有安装shadow password,就将M a k e f i l e里面这一段的
# FLAGSM = -DLINUX -DAXPROC -DFAST_SHARE_MODES
# FLAGSM = -DLINUX -DFAST_SHARE_MODES
# LIBSM =
这三行的#号删除,然后储存M a k e f i l e进行第3步骤。
Use this for Linux with shadow passwords and quota
假如系统有安装shadow password和q u o t a的话,就将M a k e f i l e里面这一段
# FLAGSM = -O3 -m486 - DLINUX-DSHADOW_PWD - DQUOTAS -DFAST_ SHARE_MODES
# LIBSM = -lshadow
这两行的#号删除,将M a k e f i l e储存起来后,并直接在s o u r c e /这个目录执行:
ln -s /usr/include/linux/quota.h /usr/include/sys/quota.h
或者
ln -sf /usr/src/quota-1.51 quota
如果/ u s r / s r c /目录下没有q u o t a - 1 . 5 1,可以到光盘的q u o t a /目录下取得q u o t a - 1 . 5 1 . t a r. g z,然
后将它解开再l i n k即可。多做这两个步骤的原因是因为要包含q u o t a,所以编译时需要用到
q u o t a的s o u r c e。
Use this for Linux with quota and glibc2
g l i b c 2是G N U新开发出的C Library,所以若有使用g l i b c 2与q u o t a,请将下面选项的#号删除:
# FLAGSM = -DLINUX -DQUOTAS -DNO_ASMSIGNALH -DGLIBC2 -DFAST_SHARE_MODES
# LIBSM = -L/lib/libc5-compat-lcrypt
Use this for Linux with glibc2(1ibc6)
只有使用g l i b c 2的人,请将下面选项的#删除:
# F L A G S M = - D L I N U X - D N E T G R O U P - D S H A D O W _ P W D - D A L L O W _ C H A N G E _ P A S S W O R D
-DFAST_SHARE_MODES = 1 -DNO_ASMSIGNALH_DGLIBC2
# LIBSM = -lnsl -lcrypt
3) 在s o u r c e /执行“m a k e”
m a k e成功后会得到好几个可执行文件,但我们执行Samba Server 或c l i e n t最需要的应是“s m b d”、“n m b d”这两个S a m b a的守护进程和“s m b c l i e n t”这个S a m b a的客户进程的执行文件并生成。接着执行“ make install”,会将S a m b a的所有东西安装到/ u s r / l o c a l / s a m b a /这个目录,就完成安装s a m b a了。若以前装过S a m b a,可以执行“ make revert”将旧的版本删除并安装新版本的S a m b a。
# make
# make install(or make revert)
做完此3个步骤就完成编译h t t p d了。
以上只是编译S a m b a源代码的一般步骤,在RedhatLinux 中,根本不必如此麻烦,可以直接使用RedhatLinux 光盘中捆绑的S a m b a - 2 . 0 . 3 - 8 . i 3 8 6 . r p m软件,因为它是R P M类型文件,无须编译即可直接安装。首先将光盘放入C D R O M中,可以执行
$ mount
$ cd /mnt/cdrom/
确认C D R O M已经M o u n t上,这时可以从光盘的/ R e d h a t L i n u x / R P M S /下取得S a m b a - 2 . 0 . 3 -8 . i 3 8 6 . r p m这个r p m软件,然后用R P M将它解压缩进行安装, R P M这个安装软件可以将新软件的source code重新整理包装成另外一种s o u r c e或b i n a r y的文件型式( . r p m ),这样一来可以免去安装软件时编译发生错误所产生的不良后果。执行命令如下:
$ rpm -ivh Samba-2.0.3-8.i386.rpm
S a m b a # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
可以看出S a m b a的软件名称以及它的安装过程,等到#字符跑完,就是软件安装完成了。
安装完成后会自动在/ e t c / 这个目录下放置有产生S a m b a 的s a m b a . c o n f 配置文件,在/ v a r / l o g / s a m b a /下面放置l o g . n m b文件,下面我们将详细谈如何进行设置。
3 设置Samba的配置文件
S a m b a的配置文件s m b . c o n f关系着Samba Server开放的权限、目录、打印机和机器所属的组,所以它对Samba Server非常重要。在使用RedhatLinux 光盘自带的s m a b a压缩文件s a m b a -2 . 0 . 3 - 8 . i 3 8 6 . r p m进行解压后,在e x a m p l e / s i m p l e /目录下就有一个s m b . c o n f的范例,请将它复制到/ u s r / l o c a l / s a m b a / 1 i b /这个S a m b a预设读取s m b.c o n f的目录,另外/ e t c /下有一个s m b . c o n f.d e f a u l t,这是完整的s m b.c o n f说明使用文件,也一并把它复制到/ u s r / l o c a l / s a m b a / 1 i b /。接着我们开始修改s m b.c o n f。为安全起见,我们首先还是把/etc / smb.c o n f文件复制成s m b.c o n f o l d,s m b.c o n f文件,
s m b . c o n f范例说明:
打开s m b.c o n f文件,首先是如下一段说明文字,建议你在明白设置的含义后进行修改。这是S a m b a S e r v e r- - - s m b d的设置文件;请特别注意, s m b.c o n f文件把用分号“;” m a r k起来的叙述当作注解。
# This is the main Samba configuration file. You should read the
# smb.conf(5) manual page in order to understand the options listed
# here. Samba has a huge number of configurable options (perhaps too
# many!) most of which are not shown in this example
#
# Any line which starts with a ; (semi-colon) or a # (hash)
# is a comment and is ignored. In this example we will use a #
# for commentry and a ; for parts of the config file that you
# may wish to enable
#
下面的w o r k g r o u p这一行用来指定你的机器在网络邻居上所属的组名称。笔者定义为q c。如果不指定,则内置的组名称为:“M Y G R O U P”
workgroup = qc
下面的h o s t s a l l o w这一行是设置哪一些领域的机器可以访问你的Samba Server;若没有设置,则内置任何机器都可以访问你的S a m b a;这里是设置192.168.1. 192.168.2. 127.领域的机器才可以访问S a m b a S e r v e r。
hosts allow = 202.204.89. 202.204.89. 120.
下面的h o s t s a l l o w这一行是定义如果你想使用自动调用的打印机而不是当需要时自己设置。
printcap name = /etc/printcap
load printers = yes
下面的config file 这一行是设置,只要加上下面这一行,不用重新开机,就可让修改s m b . c o n f后马上生效。不过对Wo r k g r o u p的定义无效。
config file = /etc/smb.conf
下面是S a m a b S e r v e r的一般化设置,设置打印机(须配合; / e t c / p r i n t c a p设置),使用者帐号
为g u e s t,将log file文件(记录文件)设置放在/ v a r / l o g / s a m b a / l o g . % m目录下;share modes = yes
指定允许任何人( g u e s t )使用定义在/ e t c / p r i n t c a p下的打印机。
[ g l o b a l ]
; printing = bsd
; guest account = pcguest
log file = /var/log/samba/log.%m
max log size = 50
share modes = yes
下面定义使用S a m a b S e r v e r的用户名的目录。
; username map = /etc/smbusers
下面是关于l i n u x的p r i n t e r的使用设置,设置打印机在Wi n d o w s 9 5网络邻居上的名称为[激
光打印机],且这台打印机可以在网络邻居上看到(browseable = yes),可以执行打印( p r i n t a b l e
= yes);但无权限者,如g u e s t不可以使用(public = no),且这台打印机的权限设置为0 7 5 0,也
就是只有拥有者( r o o t )才能使用。
[ p r i n t e r s ]
comment = All Printers
path = /var/spool/samba
browseable = no
# Set public = yes to allow user 'guest account ' to print
guest ok = no
writable = no
printable = yes
printable = no
create mask = 0750
下面设置所有使用者的Home Directories:
[ h o m e s ]
comment = Home Directories
browseable = yes
path = /home
writable = yes
下面设置d a v i d这位l i n u x上的使用者的Home directory。这种设置也是安装s a m a b的好处之
一,d a v i d这位使用者可以直接经由Wi n d o w s 9 5的网络邻居存取它在l i n u x上的Home directory,
对使用者来讲非常方便。
[ d a v i d ]
comment = david’s Home
path = /usr/david
valid users = david
public = no
writable = yes
下面的语句设置一个暂存的目录,可以让任何人共享(public = yes):
[ t m p ]
comment = Temporary file space
path = /
read only = yes
public = yes
上面只举了几个范例,如果想知道更多的范例,请参考S a m b a内附的s m b . c o n f.d e f a u l t。
设置好s m b . c o n f后,紧接着就要启动Samba Server了。
4 启动Samba
启动Samba Server有两种方法,一种是以s t a n d - a l o n e的形式,另一种则是以I n e t d的形式。
这两种方式各有利弊,以s t a n d - a l o n e的方式运行, D a e m o n会随时占住系统资源,但反应速度
较快,所以若没有电脑资源分配的问题,笔者建议采取这种方式。而以I n e t d的方式运行则比
较省电脑资源,相对的执行速度会比较慢。选择哪种方式,完全根据自己机器的设置而定。
要特别注意的是,不管采用哪一种方式启动S a m b a都可以,但切记不要让两种方式同时执
行,否则Samba Server将无法正常运行!然而,安装S a m b a时,S a m b a已经“预设使用I n e t d的
形式”启动S a m b a,所以此时只要重新开机后, Samba Server就会启动了。如果要使用D a e m o n
启动S a m b a,则必须先删除I n e t d形式启动的设置,所以我们先来了解如何用I n e t d启动S a m a b吧!
1. 使用Inetd启动Samab
(1) 在“/ e t c / s e r v i c e s”文件中加入下面六行
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
netbios-ssn 139/udp nbssn
因为安装S a m b a时已经自动帮加了,所以不用自己动手,如果你准备用s t a n d - a l o n e的形式
启动,就在这六行的前面加上#,将他们注释起来吧!
(2) 在“/ e t c / i n e t d . c o n f”文件中加入下面两行
netbios-ssn stream tcp nowait root /usr/sbin/smbd smbd
netbios-ns dgram udp wait root /usr/sbin/nmbd nmbd
并请将在/ u s r / l o c a l / s a m b a / b i n /下的s m b d、n m b d这两个Samab daemon文件复制到/ u s r / s b i n /以方
便使用。
2. 以stand-alone的方式启动Samba
以s t a n d - a l o n e的方式启动S a m b a在RedhatLinux 下最简单不过了,只要将下面三行加入
“/ e t c / r c . d / r c . l o c a l”这个文件中就可以了:
第一行是用e c h o显示信息用的,不加也没关系,接着是执行s m b d和n m b d。而参数- D就是表示要以D a e m o n形式运行, - d 1就是设置除错的级别为第一级,总共有0~5共六级。至于n m b d后面的-n samba就是指定这一台机器在Windows 95网络邻居上看到的名称为“ s a m b a”,你可以自己改成自己喜欢的名称,再配合s m b.conf 文件中定义的workgroup=Samba House,也就是说在网络邻居的S a m b a.H o u s e里面会有一台机器名称叫做s a m b a。如果说S a m b a启动都完全没问题, L i n u x和Windows 95之间的网络也都通畅的话,则可以在网络邻居上看到在整个网络上S a m b a _ H o u s e这个组名称。这个组名称里面有一台叫S a m b a的机器,不知道的人,在Windows 95的网络邻居看到你,还以为你的电脑也是安装Windows 95呢?假如出现S a m b a无法启动情况,请检查/ v s r / l o g / s a m b a /目录下的l o g . n m b ( n m b d启动记录)与l o g . s m b ( s m b d启动记录),以修正问题。
5 Samba常用的重要指令
当你的S a m b a运行正常时,请也看看这一小节,因为会介绍许多S a m b a常用的重要指令。
如果你的Samba Server不能正常工作,请依照下列步骤完成测试工作:
首先至少要有两台电脑可以使用,一台是你的L i n u x,一台则是Windows 95的机器,这样
才能进行测试工作。另外可以将/ u s r / l o c a l / s a m b a / b i n /这个路径加入. p r o f i l e或. c s h r c中(假如使用
b a s h或t c s h的话),以方便使用S m a b a的执行程序。
1. Testl
使用S a m b a提供的测试程序“t e s t p a r m”,测试s m b . c o n f的设置是否正确。
# testparm
2. Test2
使用p i n g,分别从L i n u x和Windows 95互相p i n g对方, 如果双方都有反应的话,表示网络
是顺畅的。
3. Test3
在L i n u x上执行“smbclient -L hostname”,测试能不能列出Samba Server共享出来的资源。
如笔者的机器h o s t n a m e为d a v i d,所以执行:
# smbclient -L david
会列出类似下面的信息
Added interface ip=140.115.210.158 bcast=140.115.255.255 nmask=255.255.0.0
Server time is Sun Oct 06 20 :1 6:30 1999
Timezone is UTC+8 .0
Domain=[SAMBA_HOUSE] OS=[Unix] Server=[Samba l.9.16p10]
Server=[david] User=[root] Workgroup=[SAMB_HOUSE] Domain=[SAMB_HOUSE]
S h a r e n a m e T y p e C o m m e n t
HomesDiskHome Directories
IPC$IPCIPC Service (Samba l.9.16p10)
RootDiskHome Directories
w z y a n g D i s k w z y a n g’s H o m e
激光打印机Printer All Printers
暂存区Disk Temporary file space
如果可以列出类似这样的信息, Samba Server应该没什么问题了!而这里要特别介绍的就
是s m b c l i e n t这个程序,s m b c l i e n t是S a m b a提供的c l i e n t程序,使用它可以存取网络上任何一台
Samab Server(Windows 95/NT网络邻居上的任何一台P C也算在内)开放出来的文件。而我们在
这测试中加- L就是列出Samab Server提供出来的资源清单。
4. Test 4
在L i n u x上执行“ nmblookup -B hostname_SAMB”,应该会得到S a m b a S e r v e r回传你的机
器的IP Address。例如:
# nmblookup -B david_SAMBA_
假如没有回传的话,而且是用i n e t d启动S a m b a的话,则请检查i n e t d.c o n f中关于n m b d的
设置是否正确。如果使用s t a n d a l o n e启动的话,可能是在s m b d或n m b d的地方加错参数了。
5. Test 5
在L i n u x上执行“ nmblookup -B IP_Address'*'”,其中的I P _ A d d r e s s是你使用的Wi n d o w s
9 5机器的网址,假如我使用的Windows 95其I P为1 4 0 . 11 5 . 2 1 9 . 1 4 5,则执行:
# nmblookup -B 140.115.219.145 '*'
则Windows 95那一台机器应该要回传它的I P回来。如果没有的话,应该是IP address不正确,
或是Windows 95没开机,不然就是Windows 95关于网络的设置没有安装好。
6. Test 6
在L i n u x上执行“nmblookup -d 2'*'”,会回传和Samba Server在同一个子网域( s u b n e t )的所
有的Windows 95机器网址。类似Got a positive name query response from l40.11 5 . 2 1 0 . 9 7这样的
信息。通常Test 5没问题的话,这里应该也没问题。
7. Test 7
在L i n u x上执行“ smbclient [url="file:///hostnameSharename"]\\hostname\Sharename[/url]”,登录自己的Samba Server。h o s t n a m e
就是表示你的机器名称, S h a r e n a m e则依据前面smbclient -L david的清单,我们得知可以登录
暂存区这个目录( Ty p e为D i s k都表示目录),于是执行:
# smbclient ‘\ \ d a v i d \暂存区’
登录d a v i d这台机器共享出来的暂存区( / t m p )目录。
Added interface ip=140.115.210.158 bcast=140.115.255.255 nmask=255.255.0.0
Server time is Sun Oct 06 21 :0 3:57 1999
Timezone is UTC+8.0
P a s s w o r d:(登入Samba Server会要求你输入将要存取目录的使用者密码,例如/ t m p属于
r o o t,所以要输入r o o t密码。若没有设密码,直接按E n t e r就可以进去了。成功后会出现S a m b a
S e r v e r的提示符号:s m b:\ > )
Domain=[SAMBA_HOUSE] OS=[UNIX] Server=[Samba 1.9.16p10]
s m b:\>help 执行h e l p看看指令列表。
ls dir lcdcd pwd
get mget putmput rename
moremask delrm mkdir
md rmdia rd prompt recurse
translate lowercase print printmode queue
qinfocancel stat quit q
exit newer archive tar blocksize
tarmode setmodehelp ? !
可以看出来, s m b c l i e n t几乎就是f t p的变相,你可以使用d i r看文件、g e t读取文件、p u t上
传文件⋯⋯,跟f t p没什么两样。
8. Test 8
在L i n u x上执行
# smbclient ‘ \ \ h o s t n a m e \ s h a r e n a m e’ -I xxx.xxx.xxx.xxx
分享Wi n d o w s 9 5网络邻居上的机器开放出来的文件。但必须先知道Wi n d o w s 9 5这台机器的
h o s t n a m e和它开放出来的目录,以及它的IP Address,才能存取这台机器上的文件。例如:
# smbclient ‘\ \ c h r i s \ d o o m’ -I 140.115.211.183
会连到网络邻居上主机名称为c h r i s的机器, 而连上后,用d i r查看到的文件就是d o o m这个目录
下的文件。
9. Test 9
在Wi n d o w s 9 5的机器上执行“ net view [url="file:///samba_name"]\\samba_name[/url]”,其中s a m b a _ n a m e就是你的L i n u x
机器的h o s t n a m e,如果能看到d a v i d这台机器的话,就表示你的S a m b a没问题了,如果发生错
误的话,如“ network name not found”,则必须查看n m b d有没有错误,或在Wi n d o w s 9 5网络
设置的T C P / I P协议中的“ wins server”加上的机器名称,或在Wi n d o w s 9 5这台机器的“ C:
/ e t c / l m h o s t”文件里面加上Wi n d o w s 9 5的机器网址,格式如下:
# C:/ e t c / l m h o s t
ip address hostname
t e s t e r
10. Test 10
查看能不能在Wi n d o w s 9 5的网络邻居上看到你的Samber Server,其实这是最直观的方法,
只要在网络邻居上可以看到你的S e r v e r,并且可以进入你共享出来的目录,就完全没有问题了。
如果遇到不能解决的问题,无法启动Samber Server,建议你看看S a m b e r压缩文件解压后
的d o c s /目录里面的文件。      
--------------------next---------------------
[center]WWW服务器的建立[/center]

Internet 下最热的服务便是W W W服务,W W W服务在当今的信息社会是必不可少的一种方式。无论在哪个领域,动态的h t m l页面都是一种宣传和获取信息的介质。为什么不运行你的W W W服务器呢?在这一节里,笔者以最普遍使用的阿帕奇( A p a c h e )服务器为例,详细讲解阿帕奇的安装、编译,以及所有实现不同功能的指令。你将学会如何配置一个功能强大的We b服务器,并启动和测试这个服务器。配置Web服务器在此过程中确保你的服务器配置得适合你的系统需要,一旦完成这一过程,便没有什么可担心的了。假如决定提供不同的特性集或改变系统,则需要修改配置。
1. 一般的httpd配置文件的规则
一共需要建立三个配置文件,所有的文件都遵循以下规则:
• 在文件中与大小写有关的只是文件路径和文件名。
• 使用#号注释掉一行。
• 当使用directive 命令时,每行只能放置一个指令。
• 为了使指令及接下来的数据一目了然,可以留下一些空白行, We b服务器将忽略它们。
2. 建立服务器配置文件
在安装L i n u x的过程中,通过R P M包,你将很轻松地装载阿帕奇服务器软件。进入你的安装目录,服务器的配置文件需要我们根据具体的需求来设置。要建立的第一个配置文件就是为We b服务器所建立的,先使用阿帕奇的h t t p . c o n f作为模板,对配置中遇到的参数做一定的说明(可根据自己的需求做改动,此配置仅供参考)。
# ServerType is either inetd, or standalone.
ServerType standalone
# If you are running from inetd, go to "ServerAdmin".
# Port: The port the standalone listens to.
Port 80
# HostnameLookups: Log the names of clients or just their IP numbers
# e.g. [url="][/url] (on) or 204.62.129.132 (off)
HostnameLookups off
# NOTE that some kernels refuse to setgid(Group) or semctl(IPC_SET)
# when the value of (unsigned)Group is above 60000;
# don't use Group nobody on these systems!
User nobody
Group nobody
# ServerAdmin: Your address, where problems with the server should be
# e-mailed.
ServerAdmin root@localhost
# ServerRoot: The directory the server’s config, error, and log files
# are kept in.
ServerRoot /etc/httpd
# BindAddress: You can support virtual hosts with this option. This option
# is used to tell the server which IP address to listen to. It can either
# contain "*", an IP address, or a fully qualified Internet domain name.
# See also the VirtualHost directive.
BindAddress *
# ErrorLog: The location of the error log file. If this does not start
# with /, ServerRoot is prepended to it.
ErrorLog logs/error_log
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
# The location of the access logfile (Common Logfile Format).
# If this does not start with /, ServerRoot is prepended to it.
CustomLog logs/access_log common
# PidFile: The file the server should log its pid to
PidFile /var/run/httpd.pid
ScoreBoardFile /var/run/httpd.scoreboard
#LockFile /var/lock/httpd.lock
# Apache needs to construct a self-referencing URL (a url that refers back
# to the server the response is coming from) it will use ServerName and
# Port to form a "canonical" name. With this setting off, Apache will
# use the hostname:port that the client supplied, when possible. This
# also affects SERVER_NAME and SERVER_PORT in CGIs.
UseCanonicalName on
# Timeout: The number of seconds before receives and sends time out
# Timeout: The number of seconds before receives and sends time out
Timeout 300
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
KeepAlive On
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We reccomend you leave this number high, for maximum performance.
MaxKeepAliveRequests 100
# KeepAliveTimeout: Number of seconds to wait for the next request
KeepAliveTimeout 15
# It does this by periodically checking how many servers are waiting
# for a request. If there are fewer than MinSpareServers, it creates
# a new spare. If there are more than MaxSpareServers, some of the
# spares die off. These values are probably OK for most sites ---
MinSpareServers 8
MaxSpareServers 20
# Number of servers to start --- should be a reasonable ballpark figure.
StartServers 10
MaxClients 150
# MaxRequestsPerChild: the number of requests each child process is
MaxRequestsPerChild 100
# Proxy Server directives. Uncomment the following line to
# enable the proxy server:
#ProxyRequests On
# To enable the cache as well, edit and uncomment the following lines:
#CacheRoot /var/cache/httpd
#CacheSize 5
#CacheGcInterval 4
建立你自己的文件h t t p d / c o n f / h t t p d . c o n f ,按照上面的内容及文件中的说明,修改你自己的配置,现在对其中的一些选项说明如下。
1) #SeverTy p e可以选择i n e t d或s t a n d a l o n e
因为运行的是I n t e r n e t下的站点,很容易选到i n e t d,然而,要想要h t t p d可以自我处理以占用较少的C P U资源,则可选择s t a n d a l o n e,因此我的h t t p d . c o n f文件的这个选项行为:
SeverType standalone
2) #Port: The port the standalone listens to
标准的h t t p d端口是8 0。一般情况下,应该与标准端口相连,这样可以使人们很容易进入你提供的服务。于是这一行应为:Port 80
3) # HostnameLookups这个选项的缺省为HostnameLookups off , 这样的缺省对所有的用户都有好处,当然也可以设置为on ,如: w w w.apache.com on 210.45.76. 6 off
4) #User nobody
#Group nobody
如果希望你的h t t p d对不同的用户和群组有不同的操作(通常不需要这么做),那么开启这个开关,若无此要求,则设置为:
User nobody
Group nobody
5) # ServerAdmin: Your address, where problems with the server should be e-mailed.当有人向你写信提及有关提供的服务时,不必紧张。能听到正面的评论是很好的,但当有人提出建设性的意见批评时,说明你的站点所提供的服务还需要进一步完善。因此,此处含有负责维护We b服务的E - m a i l地址。笔者所看到的是:
ServerAdmin root@localhost
6) # ServerRoot: The directory the server’s config, error, and log files are kept in.这里告诉你的系统在何处可以找到h t t p d文件。当然,将它们放在何处完全是个人爱好问题。ServerRoot /etc/httpd
7) 现在告诉系统在何处可以找到h t t p d日志文件。假如你的路径不是以/ 开头,意味着开始目录由S e r v e r R o o t分配。日志文件如下:• E r r o r l o g跟踪超时客户,不产生输出的脚本,试图覆盖不允许覆盖的内容,严重的服务器错误(产生段错误或总线错误)以及用户权限有关的问题。• Tr a n s f e r L o g跟踪以下信息:客户主机,提供的i d e n t d信息,用户权限,进入的日期和时间,H T T P请求的第一行,服务器状态码,以及发送的字节总数。
• AgentLog 跟踪使用的客户代理软件,它大多数情况用于收集统计数字或跟踪导致服务器错误的客户。• RefererLog跟踪指导用户与你连接的那些文档。
• 与这个日志文件相关的一个变量为R e f e r L g n o r e ,它忽略与特定用户的连接。例如,当不想对用户每次翻阅你的页面时都做记录, 就可以使用它。因为笔者建立了w w w. r e n a i s s o f t . c o m,所以选择忽略那个主机。
• PidFile 跟踪你的服务器进程I D号。
• 可以选择在某类中央记录区保存你的记录,若决定将我的记录与其他的h t t p d内容保存在一起,配置文件中的其他项将为:
ErrorLog logs/error_log
CustomLog logs/access_log common
PidFile /var/run/httpd.pid
ScoreBoardFile /var/run/httpd.scoreboard
8) #StartServers: The number of server to launch at startup
尽管对处理服务器数目有一编译缺省值,最好自己设置以了解你所要使用的数目。假如你接受这一缺省值,则很难知道现在可用的服务器,除非你查原代码。笔者选择的与例子相同的服务器数目( 1 0 ),这样我的系统就可以同时处理1 0个H T T P请求,而不需要额外的资源来启动多出的h t t p d进程。同时,1 0个空闲的d a e m o n只可能占用少量的资源。因此,这一行为:
S t a r t S e v e r 1 0
9) #MaxSpareServer:
# M i n S p a r e S e r v e r :
同样,有一编译缺省值,但建议在你的配置文件中设定一下。上例中数目为2 0和1 0,即
最大和最小空闲服务器进程数目。系统将周期性检测等待中的服务进程数目,如果数目小于
最小空闲服务器进程数目,系统将会产生一个新的进程;若数目大于最大服务器进程,将是
一种资源的浪费,系统将会关闭一个进程。笔者将其设置为:
MinSpareServers 8
MaxSpareServers 20
10) # MaxKeepAliveRequests
这个参数表明在当前的连接中系统能够处理的请求的最大数值,为了保证你的服务器正
常服务,这个参数应该设置得较大。笔者在模板文件中的参数设置为:
MaxKeepAliveRequests 100
11) MaxClients 150
这个参数值表示服务器允许的最大客户请求数,即最多允许访问用户的数目。
12) # MaxRequestsPerChild
MaxRequestsPerChild 这个指令设定一个独立的子服务程序将能处理的请求数量。在处理
M a x R e q u e s t s P e r C h i l d这个请求之后,子程序将会被终止。如果MaxRequestsPerChild 为0的话,
那么该程序永远不会被终止。MaxRequestsPerChild 设为非0的值做为限制有两个好处:
• 由记忆体使用量限制程序使用的记忆体数量;
• 由赋予程序有限的存留时间,可以在服务器负载降低时协助减少程序的数目。
3. 建立资源配置文件
建立这个文件用于通知We b服务器从哪里可以找到文档、脚本和别名。下面是一个名为
e t c / h t t p d / c o n f / s r m . c o n f的文件,作为模板。供大家参考。
# DocumentRoot: The directory out of which you will serve your
# documents.
DocumentRoot /home/httpd/html
# UserDir: The name of the directory which is appended onto a user’s home
# directory if a ~user request is recieved.
UserDir public_html
# DirectoryIndex: Name of the file or files to use as a pre-written HTML
# directory index. Separate multiple entries with spaces.
DirectoryIndex index.html index.shtml index.cgi index.htm
# FancyIndexing is whether you want fancy directory indexing or standard
FancyIndexing on
# AddIcon tells the server which icon to show for different files or filename
# extensions
AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip
AddIconByType (TXT,/icons/text.gif) text/*
AddIconByType (IMG,/icons/image2.gif) image/*
AddIconByType (SND,/icons/sound2.gif) audio/*
AddIconByType (VID,/icons/movie.gif) video/*
AddIcon /icons/binary.gif .bin .exe
AddIcon /icons/binhex.gif .hqx
AddIcon /icons/tar.gif .tar
AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv
AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip
AddIcon /icons/a.gif .ps .ai .eps
AddIcon /icons/layout.gif .html .shtml .htm .pdf
AddIcon /icons/text.gif .txt
AddIcon /icons/c.gif .c
AddIcon /icons/p.gif .pl .py
AddIcon /icons/f.gif .for
AddIcon /icons/dvi.gif .dvi
AddIcon /icons/uuencoded.gif .uu
AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl
AddIcon /icons/tex.gif .tex
AddIcon /icons/bomb.gif core
AddIcon /icons/back.gif ..
AddIcon /icons/hand.right.gif README
AddIcon /icons/folder.gif ^^DIRECTORY^^
AddIcon /icons/blank.gif ^^BLANKICON^^
# DefaultIcon is which icon to show for files which do not have an icon
# explicitly set.
DefaultIcon /icons/unknown.gif
# HeaderName is the name of a file which should be prepended to
# directory indexes.
ReadmeName README
HeaderName HEADER
# IndexIgnore is a set of filenames which directory indexing should ignore
# Format: IndexIgnore name1 name2...
IndexIgnore .??* *~ *# HEADER* README* RCS
# AccessFileName: The name of the file to look for in each directory
# for access control information.
AccessFileName .htaccess
# TypesConfig describes where the mime.types file (or equivalent) is
# to be found.
TypesConfig /etc/mime.types
# DefaultType is the default MIME type for documents which the server
# cannot find the type of from filename extensions.
DefaultType text/plain
# AddEncoding allows you to have certain browsers (Mosaic/X 2.1+) uncompress
# information on the fly. Note: Not all browsers support this.
AddEncoding x-compress Z
AddEncoding x-gzip gz
# Just list the languages in decreasing order of preference.
LanguagePriority en fr de
# Redirect allows you to tell clients about documents which used to exist in
# your server's namespace, but do not anymore. This allows you to tell the
# clients where to look for the relocated document.
# example.
Alias /icons/ /home/httpd/icons/
# ScriptAlias: This controls which directories contain server scripts.
# Format: ScriptAlias fakename realname
ScriptAlias /cgi-bin/ /home/httpd/cgi-bin/
# If you want to use server side includes, or CGI outside
# ScriptAliased directories, uncomment the following lines.
# AddType allows you to tweak mime.types without actually editing it, or to
# make certain files to be certain types.
# Format: AddType type/subtype ext1
Addtype application/x-httpd-cgi .pl .cgi
#AddType application/x-httpd-php3 .php3
#AddType application/x-httpd-php3-source .phps
# The following is for PHP/FI (PHP2):
#AddType application/x-httpd-php .phtml
# AddHandler allows you to map certain file extensions to "handlers",
# actions unrelated to filetype. These can be either built into the server
# or added with the Action command (see below)
# Format: AddHandler action-name ext1
# To use CGI scripts:
AddHandler cgi-script .cgi
# To use server-parsed HTML files
AddType text/html .shtml
AddHandler server-parsed .shtml
# Uncomment the following line to enable Apache's send-asis HTTP file
# feature
BrowserMatch "RealPlayer 4\.0" force-response-1.0
BrowserMatch "Java/1\.0" force-response-1.0
BrowserMatch "JDK/1\.0" force-response-1.0
1) # DocumentRoot: The directory out of which you will serve your
# documents.
使用这一变量,可以规定你的服务器将显示文件的主目录。通常,笔者使用标准方法(如果你想将所有的记录文件放在一个集中的地方,可以改变它,以适应你的需要),这样,此文件的开头为:
DocumentRoot /home/httpd/html
2) # UserDir: The name of the directory which is appended onto a user’s home
# directory if a ~ user request is recieved.
这个指令用于分配一个目录,此目录将存在于用户保存他们的H T M L文件的目录中,标准是目录:public_html: 任何时候如果某人跟踪某个链接,例如h t t p : / / w w w. s e v e r. c o m / ~ u s e r,他实际进入的目录应该是: h t t p : / / w w w. s e v e r.com/~user/public_html, 这是一种保持整洁及适当安全的措施,这样其他人员便不能进入用户目录。笔者的配置文件的下一行为(使用了缺省值)UserDir public_html
3) # DirectoryIndex: Name of the file or files to use as a pre-written HTML
# directory index.
使用这一指令,当外面的用户连接到某人的主目录时,可以设置一个假想的文件名。在上例中,并没有列出文件名,只是因为已设置了缺省的文件名,于是服务器首先查看此文件名(一般为i n d e x . h t m l或i n d e x . h t m )。笔者将其设置为DirectoryIndex index.html index.shtml index.cgi index.htm
4) # FancyIndexing is whether you want fancy directory indexing or standard
F a n c y I n d e x i n g指显示目录、文件及图标和文件大小。假如你想以此方式显示你的文件和目录,将这一选项打开;否则,将其关闭。笔者的下一行设置为O n,形式如下:FancyIndexing on      
--------------------next---------------------
5) # AddIcon tells the server which icon to show for different files or filename
# extensions
可以使用这个指令定义We b服务器将使用什么图标显示目录中的文件类型。这是一种改进目录显示方法的简单方法。这个指令没有缺省值,因此如果你没有定义内容,就没有图标可用。欲使用图标的路径蕴含在D o c u m e n R o o t变量的值中,而D o c u m e n t R o o t变量在这个配置文件的一开始就已定义了,因此,第一个变量指出了保存图标的目录,这个目录将在你的D o c u m e n t R o o t目录内。笔者的配置如下:
AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip
AddIconByType (TXT,/icons/text.gif) text/*
AddIconByType (IMG,/icons/image2.gif) image/*
AddIconByType (SND,/icons/sound2.gif) audio/*
AddIconByType (VID,/icons/movie.gif) video/*
AddIcon /icons/binary.gif .bin .exe
AddIcon /icons/binhex.gif .hqx
AddIcon /icons/tar.gif .tar
AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv
AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip
AddIcon /icons/a.gif .ps .ai .eps
AddIcon /icons/layout.gif .html .shtml .htm .pdf
AddIcon /icons/text.gif .txt
AddIcon /icons/c.gif .c
AddIcon /icons/p.gif .pl .py
AddIcon /icons/f.gif .for
AddIcon /icons/dvi.gif .dvi
AddIcon /icons/uuencoded.gif .uu
AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl
AddIcon /icons/tex.gif .tex
AddIcon /icons/bomb.gif core
AddIcon /icons/back.gif ..
AddIcon /icons/hand.right.gif README
AddIcon /icons/folder.gif ^^DIRECTORY^^
AddIcon /icons/blank.gif ^^BLANKICON^^
6) # DefaultIcon is which icon to show for files which do not have an icon
# explicitly set.这里,告诉服务器用哪个图标表示未曾定义的文件类型。一般为u n k n o w n图标。笔者使用缺省配置,其文件的下一行为:DefaultIcon /icons/unknown.gif
7) #ReadmeName is the name of the README file the server will look for by
# default.
使用此指令定义H T M L文件,它包含一个当前目录下的文件描述列表。尽管文件名与描述分别储存在不同的文件中,但这些文件描述在目录列表的文件旁边显示。以后你将需要创建包含描述的H T M L文件。为了简单起见,起名为r e a d m e . h t m l ,这样源配置文件的下行为:
ReadmeName README
8) # HeaderName is the name of a file which should be prepended to
# directory indexes.
使用此指令定义包含一个当前目录自定义标题的H T M L文件,这个标题在目录列表的上部显示。今后你将有必要创建包含最新标题的H T M L文件。为了简单起见,我将它定义为h e a d e r. h t m l ,于是配置文件的此行为:
HeaderName HEADER
9) # IndexIgnore is a set of filenames which directory indexing should ignore
# Format: IndexIgnore name1 name2...假如不想让某些文件出现在目录列表中,使用I n d e x I g n o r e。例如,假如你想忽视r e a d m e . h t m l及h e a d e r. h t m l文件(它们由服务器本身使用,用户无需亲自使用它们),笔者将使用下一行:
IndexIgnore .??* *~ *# HEADER* README* RCS
10)# AccessFileName: The name of the file to look for in each directory
# for access control information.
这条指令告诉服务器在何处去寻找访问控制文件,你将对这种文件进行配置,确立哪些
目录是高于一般客户的人才能进入的。AccessFileName .htaccess
11) # DefaultType is the default MIME type for documents which the server
# cannot find the type of from filename extensions.当服务器不能决定实际文件类型时,使用这一指令可以分配一个缺省的文件类型。我使用的缺省设置:DefaultType text/plain这里,t e x t指文件类型(标准文件类型),p l a i n指子类型( M I M E调用这种文件类型)。
12)# AddEncoding allows you to have certain browsers (Mosaic/X 2.1+) uncompress
# information on the fly. Note: Not all browsers support this.
假如想使你的服务器在发送文件的同时对其解压缩(这样存储该文件的所需的的磁盘空间较少),可使用这个指令。例如,若想让服务器能够还原U n i x压缩( . z )文件及g z i p压缩( . g z )文件(正如源配置文件列表中的例子所示),将输出下述内容:
AddEncoding x-compress Z
AddEncoding x-gzip gz
13) # AddLanguage allows you to specify the language of a document. You can
# then use content negotiation to give a browser a file in a language
# it can understand.
此项允许你指定文档所使用的语言,可以使用缺省值。其文件如下:
AddLanguage en .en
AddLanguage fr .fr
AddLanguage de .de
AddLanguage it .it
其中e n表示英语,f r为法语, d e为德语, i t则为意大利语。随后的配置L a n g u a g e P r i o r i t y与此项类似,这里从略。
14) # Aliases: Add here as many aliases as you need (with no limit). The format is
# Alias fakename realname
假如想为你的H T M L 文件路径起一个别名, 可以使用这个指令。例如, 将/ h o m e / h t t p d / i c o n s /起别名为/ i c o n s ,可以用如下的指令:
Alias /icons/ /home/httpd/icons/
15) # AddType allows you to tweak mime.types without actually editing it, or to
# make certain files to be certain types.
如果希望你的服务器能够支持C G I (大多数的We b服务器都这样做了),利用此选项,把它加入你的配置文件,笔者的下一行为:
Addtype application/x-httpd-cgi .pl .cgi
同样,如果希望你的服务器同样支持p h p ,也可以以同样的方法将其相加,如:
AddType application/x-httpd-php .phtml
16) # AddHandler allows you to map certain file extensions to "handlers",
# actions unrelated to filetype.
4. 建立访问配置文件
这是要设置的最后一个配置文件,它告诉We b服务器哪些客户可以进入哪些目录,以及在其他目录哪些服务是可用的。下面的文件为e t c / h t t p d / c o n f / a c c e s s . c o n f,可作为大家配置此文件的模板。
## access.conf -- Apache HTTP server configuration file
# access.conf: Global access configuration

Options None
AllowOverride None
< / D i r e c t o r y >
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something ’s not working as
# you might expect, make sure that you have specifically enabled it
# below.
# This should be changed to whatever you set DocumentRoot to.

# This may also be "None", "All", or any combination of "Indexes",
# "Includes", "FollowSymLinks", "ExecCGI", or "MultiViews".
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
Options Indexes Includes FollowSymLinks
# This controls which options the .htaccess files in directories can
# override. Can also be "All", or any combination of "Options", "FileInfo",
# "AuthConfig", and "Limit"
AllowOverride None
# Controls who can get stuff from this server.
order allow,deny
allow from all
< / D i r e c t o r y >
# /home/httpd/cgi-bin should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.

AllowOverride None
Options ExecCGI
< / D i r e c t o r y >

Options ExecCGI
< / D i r e c t o r y >

Options ExecCGI
< / D i r e c t o r y >

Options ExecCGI
< / D i r e c t o r y >
# Allow server status reports, with the URL of [url="][/url]
# Change the ".your_domain.com" to match your domain to enable.
#
#SetHandler server-status
#order deny,allow
#deny from all
#allow from, your_domain.com
# < / L o c a t i o n >
# Allow access to local system documentation from localhost
Alias /doc /usr/doc

order deny,allow
deny from all
allow from localhost, 127.0.0.1
Options Indexes FollowSymLinks
< / D i r e c t o r y >
# There have been reports of people trying to abuse an old bug from pre-1.1
# days. This bug involved a CGI script distributed as a part of Apache.
# By uncommenting these lines you can redirect these attacks to a logging
# script on phf.apache.org. Or, you can record them yourself, using the
s c r i p t
# support/phf_abuse_log.cgi.
#
#deny from all
#ErrorDocument 403 [url="][/url]
# < / L o c a t i o n >
# You may place any other directories or locations you wish to have
# access information for after this one.
要建立你自己的配置文件e t c / h t t p d / c o n f / a c c e s s . c o n f,可照上例中同样的顺序填写内容。从某种意义上讲,这是最重要的一个配置文件,因为它控制对你的系统的存取,所以要多花些时间学习,下面是我的服务器配置文件的一些选择。
1) # This file defines server settings which affect which types of services
# are allowed, and in what circumstances.

Options None
AllowOverride None
< / D i r e c t o r y >
# This may also be "None", "All", or any combination of "Indexes",
# "Includes", "FollowSymLinks", "ExecCGI", or "MultiViews".
从上面可以看出,服务器在此目录下的选项如下:
• None 表示在此目录下没有特性,这是最安全的,因为使用你服务器的用户完全不能在此目录下做任何事情。
• All 表明此目录下的所有特性可用。不要轻易使用这个特性,除非你真的想让用户进入特定的目录看到其中的任何东西(包括用户的主目录)。实际上,假如从一个用户的主目录到你的某个目录建立了s i m l i n k s ,而这个目录你并不想让其他人进入。如果使用A l l选项,其他的用户就可以利用这个链进入该目录。
• Follow SymLinkszz 使得服务器从这个目录跟踪s i m l i n k s。选择此项一定要小心,因为如果s i m l i n k s是从用户的主目录到不允许其他人访问的目录,将会产生一种链接,使得外部的We b用户也可以进入你并不想让他进入的目录。
• SymLinksIfOwnerMatch 使得服务器从这个目录跟踪s i m l i n k s,条件是链所指的文件拥有者同时是链的创建者。此选项部分地解决了上面所述的问题,外部用户一般不能跟踪链,除非该用户也拥有此链所连接的文件。
• Indexs 表明服务器可以让人们要求当前目录的索引,并让部分用户得到他们所在目录
的H T M L索引。如果不用此选项,外部用户将不会得到H T M L索引,但在此目录中可以
加载任何要索引的文件。如果想提供H T M L文件索引及描述,使用此选项。
• Include 表明服务器可以让用户提供信息,例如一个文件最后被修改的日期。在这里,出于安全起见,先将所有的目录都定义为N o n e,以免出现安全漏洞。由于此选项是可以覆盖的,需要其他要求的选项可以在后面一一定义。
2) # This should be changed to whatever you set DocumentRoot to.

Options All
AllowOverride All
order allow,deny
allow from all

这个D i r e c t o r y指令同样也是一个完整的语句。和以前一样的模式,但这一次指的是S e v e r R o o t的目录(我使用的是h o m e / h t t p d / h t m l ),此部分的第一行为:此时,我作为根目录又完全控制了该目录,但想要让人们能够获得这里所有的文件,可以使用以下选项。
Options All
现在已可以通过输入来控制哪个. h t a c c e s s选项是服务器可以覆盖的。尽管有多种选择,我建议最好用下面的:
AllowOverride All
除非你确实想拒绝一些主机存取,一般情况下需要做的仅仅是添加为以下部分:
allow from all
3) # /home/httpd/cgi-bin should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.

AllowOverride None
Options ExecCGI
< / D i r e c t o r y >
以上为S e v e r R o o t的设置,笔者采用了缺省值,其选项如上所示。
4) 现在设置u s r目录下的文件特性,笔者选择如下:
#Allow access to local system documentation from localhost
Alias /doc /usr/doc

order deny,allow
deny from all
allow from localhost, 127.0.0.1
Options Indexes FollowSymLinks
< / D i r e c t o r y >
其中,笔者只允许内部I P 1 2 7 . 0 . 0 . 1的主机查看这个目录,因此做了以下的设置:
deny from all
allow from localhost, 127.0.0.1
到此为止,你已经完成了配置We b服务器的工作!
5. 启动Web服务器
这是最后一步,真正地启动We b服务器。设置一些内容,以便每次引导系统时服务器都
将自己启动。需要做以下的工作:
1) 编辑文件/ e t c / s e r v i c e。
2) 增加以下行:
http 80/tcp
你不必使用端口8 0,但它是标准的h t t p端口,若不使用这个端口,人们将不得不在U R L中使用端口编号才能与你连接。
3) 存盘退出/ e t c / s e r v i c e s。
4) 编辑文件/ e t c / i n e t d . c o n f。
增加行:
http stream tcp nowait ftp /etc/httpd/httpd httpd
5) 存盘退出。
6) 作为r o o t登录。
7) 输入ps aux.。
8) 为i n e t d找到进程号。
9) 输入kill - HUP
从现在开始,当你引导系统时,自动启动的一个进程便是h t t p d。      
--------------------next---------------------

阅读(2772) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~