Axin 发表于 2005-8-22 09:00:50

快速架设各种服务器

快速架设apache/vsftpd/samba/sendmail服务器

daweicheng
[email protected]

1 序言
2 参考文档
3 动态域名实现
4 apache
5 vsftpd
6 samba
7 sendmail
8 附录
a) httpd.conf的详细设定
b) vsftpd.conf的详细设定
c) smb.conf的详细设定
d) sendmail.mc的详细设定
e) tcp端口对照表(0~1457)

1 序言

现在宽带网络越来越普及,这为个人架设服务器提供了良好的基础.
本文讲述了如何实现动态域名,并快速设置好apache/vsftpd/samba/sendmail服务器.本文参阅了不少优秀文档,并接合了自己的一些心得.在这里,感谢这些无私的作者和为linux做出贡献的人们.

环境:redhat linux 9

2 参考文档

Red Hat Linux 9.0服务器架设全程实录
http://www.douzhe.com/linuxtips/1701.html

简易www伺服器设定
http://linux.vbird.org/linux_server/0360apache.php

简易vsftpd伺服器设定
http://linux.vbird.org/linux_server/0410vsftpd.php

简易samba伺服器设定
http://linux.vbird.org/linux_server/0370samba.php

简易Mail Server架设 -- Sendmail设定
http://linux.vbird.org/linux_server/0380sendmail.php

RHCE_Linux_Study_Guide
此文档在许多linux站点都可以找到

3 动态域名实现

考虑虚拟拨号的用户ip地址是动态分配的,这里我们申请动态域名.假设我们拥有公网ip.
在http://www.comexe.cn/ddns/ddns_trying.php上申请一个二级域名,然后下载linux的动态域名客户端linux_i.tar.gz,放在/tmp下

cd /tmp
tar zxvf linux_i.tar.gz

解压后的文件pipclient我们放在/usr/local/comexe/下

mkdir /usr/local/comexe/
mv pipclient /usr/local/comexe/
cd /usr/local/comexe/

下面配置客户端,在以下网址有说明:
http://www.comexe.cn/ddns/ddns_assistant_use.php#a4

./pipclient
依此输入在科迈注册的用户名,密码,域名
在Input Offline URL or Offline IP(Enter for none):此处我们直接回车(离线域名对我们注册的二级域名无效)
Has another domain?(Y/N):多个域名按"Y"
配置完按Ctrl+C结束.
修改配置用-c参数:
./pipclient -c

运行:
pipclient要在系统启动时以后台进程运行。请修改系统启动脚本(/etc/rc.d/rc.local),加入如下命令:
nohup /usr/local/comexe/pipclient -w /usr/local/comexe &
其中“-w”参数指定工作目录

因为我个人更喜欢用ntsysv(setup->system service),所以没有在rc.local中加命令
于是自己写了个简陋的脚本,用chkconfig加入系统服务,以后可以用service comexe start和service comexe stop启用和停止动态域名:
cd /etc/init.d/
vi comexe
然后写入下面的内容:
#! /bin/sh
#chkconfig:2345 90 90
#description:comexe


. /etc/rc.d/init.d/functions

case "$1" in

start)
echo -n "start ddns: "
/usr/local/comexe/pipclient -w /usr/local/comexe > /dev/null &
echo
;;

stop)
echo -n "stop ddns: "
killproc pipclient
echo
;;

*)
exit 1
;;
esac

exit 0
好了,wq保存退出
chmod 755 comexe
chkconfig --add comexe
chkconfig --level 35 comexe on
这样,把comexe这个脚本加到了启动服务中,以后每次开机后自动加载(运行级3,5)
service comexe start和service comexe stop可手动加载和停止该服务.

4 apache

apache是被广泛应用的web服务器软件,有多个平台的版本.关于apache名称的由来,大家有兴趣可以看看参考文档中的解释:)
首先是安装工作.
我们需要安装如下的软件包(可以在redhat linux 9 光盘中找到)
httpd
httpd-devel
redhat-config-httpd
httpd-manual
autoconf
automake
libtool
mod_perl
mod_ssl
mod_python
用rpm -Uvh将这些软件包装好,然后:
/sbin/chkconfig --level 35 httpd on                将httpd服务在运行级3,5自动加载
/sbin/service httpd start                        启动httpd服务
在web浏览器中输入http://localhost,如果安装无误,你会看见apache的测试页面

在apache 2中主配置文件是/etc/httpd/conf/httpd.conf
该文件的修改可以手动编辑或用redhat-config-httpd这样的图形化程式来完成
下面简单介绍一下该配置文件的主要配置参数:

KeepAlive On
是否允许持续性连线,即一个连线有多个请求

MaxKeepAliveRequests 100
在持续性连线中,最大允许的连接数目,设定为0,表示没有限制

MinSpareServers与MaxSpareServers是设定httpd进程数量的范围
StartServers可以设定在这两者之间(用ps -guax|grep httpd可以看到httpd进程数)

MaxClients 150
同一时间的连接数目.如果设得太大会很耗资源,设得太小则无法让很多人连上来

MaxRequestsPerChild
一个服务进程允许的最大请求数,设为0表示无限制

Listen 80
设定监听端口,默认80,表示监听所有ip的80端口,可以根据情况设成其他端口
也可以设为监听某一ip的端口,如xxx.xxx.xxx.xxx:80
这要在系统启动时激活网络(仅限固定ip),否则httpd服务启动失败

DocumentRoot "/var/www/html"
DocumentRoot设定apache的根目录

<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>
设定apache根目录的属性,Options后面的值表示:
ExecCGI                        使该目录下CGI可执行
FollowSymLinks                允许链接至其他目录
Includes                        允许使用SSI
Indexes                        如果该目录下找不到index.html,则显示该目录下文件名称
MultiViews                根据特定条件自动选择并返回一个合适的文件(很少用到)
All                        使用上面所有参数,除了MultiViews

AddDefaultCharset ISO-8859-1
apache缺省的显示语言编码,将ISO-8859-1改为GB2312,以显示简体中文

NameVirtualHost *
虚拟主机设定.所谓虚拟机指一个主机有多个域名对应,
该设定可以让不同的域名对应不同的页面,就好像存在多个主机一样
apache有两种方式的虚拟机:基于ip的虚拟机和基于名字的机
基于IP的虚拟主机要求使用不同的IP地址来区别不同的虚拟主机
基于名字的虚拟主机使用相同的IP地址来配置不同的虚拟主机
*可以用ip地址或internet上的主机名称来替代

<VirtualHost www.myvirtualhost.com>
        ServerName    www.myvirtualhost.com
        DocumentRoot/var/www/html/myvirtualhost
        ServerAdmin    [email protected]
        ErrorLog logs/www.myvirtualhost.com-error_log
        CustomLog logs/www.myvirtualhost.com-access_log common
</VirtualHost>
上面是一个虚拟机的例子,即www.myvirtualhost.com
ServerAdmin        管理员电邮地址
ErrorLog                错误日志
CustomLog        访问日志
设定一个虚拟机至少需要ServerName和DocumentRoot两项,即服务器名和虚拟机网页的根目录.
可根据情况设定多个虚拟主机

设置无误后,用httpd -t测试有无语法错误
service httpd reload装载修改过的设定

现在可以用浏览器测试一下

最后,开放iptables中的80端口(取决于httpd.conf中的端口设定)
vi /etc/sysconfig/iptables
由于iptables是至上而下读取配置文件规则的,所以在
-A RH-Lokkit-0-50-INPUT -p tcp -m tcp --dport 0:1023 --syn -j REJECT
这一行之上加入允许的规则就可以了.加入:
#httpd(apache)
-A RH-Lokkit-0-50-INPUT -p tcp -m tcp --dport 80 --syn -j ACCEPT
然后service iptables restart
重启iptables服务
这样,可以从internet上访问这台主机的www服务了.

5 vsftpd

vsftpd是linux上常用的几种ftp服务器软件之一,vsftpd是very secure FTP daemon的缩写.

首先,将redhat linux 9 cd #3上的vsftpd-1.1.3-8.i386.rpm装好

chkconfig --level 35 vsftpd on
运行级3,5下,vsftpd服务开机自动加载

service vsftpd start
启动vsftpd服务
参数restart,stop可重启/停止服务

配置文件:
/etc/vsftpd/vsftpd.conf
是vsftpd的主要设定文件

/etc/vsftpd.ftpusers
不能访问ftp服务器的用户列表,默认root不可访问vsftpd服务器

/etc/vsftpd.user_list
这个文件中也是一些用户的列表
在/etc/vsftpd/vsftpd.conf中:
1)当userlist_enable=YES(默认)时,启用配置文件/etc/vsftpd.user_list
a)此时若没有userlist_deny=NO,则/etc/vsftpd.user_list中的用户也不可访问vsftpd服务器
b)此时若存在userlist_deny=NO,则仅接受/etc/vsftpd.user_list中存在的用户的登录请求(同时这些用户不存在于/etc/vsftpd.ftpusers中)
2)当userlist_enable=NO时,则不会启用配置文件/etc/vsftpd.user_list

下面简单说明一下/etc/vsftpd/vsftpd.conf的参数设定:

anonymous_enable=YES
允许匿名用户登录

local_enable=YES
允许本地用户登录(linux系统下实在的帐户)

write_enable=YES
允许上传

local_umask=022
本地用户上传文件的umask设为022

xferlog_enable=YES
启用记录上传/下载活动日志

connect_from_port_20=YES
tcp端口20作为ftp-data传送端口(一般21为ftp-control端口)

userlist_enable=YES
(请参看上面/etc/vsftpd.user_list配置文件的简单说明)

listen=YES
使用standalone模式

local_root=/var/ftp
本地用户登录后的目录为/var/ftp
如果没有这项设定,本地用户登录后的目录为自己的家目录

chroot_list_enable=YES
让下面配置文件中的本地用户不能到达家目录之外的地方
chroot_list_file=/etc/vsftpd.chroot_list

pasv_enable=YES
启用被动模式
#port_enable=YES
启用主动模式
注意,这两个参数只能出现一个,另一个必需用#注释掉(设为NO也不可以)

以上是vsftpd.conf的一些基本设定,更详悉的设定,请参看附录

修改好配置文件,重启一下服务service vsftpd restart

下面开放tcp 20,21端口
在/etc/sysconfig/iptables中加入:

#vsftpd(vsftp)
-A RH-Lokkit-0-50-INPUT -p tcp -m multiport --dport 20,21 --syn -j ACCEPT

(加入的位置在REJECT规则之前)
然后service iptables restart
重启iptables服务

这样,vsftpd服务器就架好了,可以用客户端测试一下

6 samba

samba的作用是提供Unix/Linux与Windows之间的通讯,并使她们之间实现文件/打印机/设备共享.在Windows网络中,设置好samba的Linux机器可以做服务器也可以做客户端.

安装以下几个rpm包:
samba
samba-common
samba-client
samba-swat
redhat-config-samba
其中samba-swat是以web页面方式配置samba的前端,redhat-config-samba是Xwindow下的图形化配置程式,她们的作用都是设定/etc/samba/smb.conf这个配置文件,此文件也可以手动编辑.

chkconfig --level 35 smb on
运行级3,5下,samba服务开机自动加载

service smb start
开启samba服务.参数包括start/restart/stop/reload等

samba的一些重要组成文件:
/usr/sbin/smbd                SMB服务守护程式
/usr/sbin/nmbd                NetBIOS服务守护程式
/etc/samba/smb.conf        samba主配置文件
/usr/bin/smbclient                连接到SMB共享的客户端程式
/usr/bin/testparm                检验smb.conf有效性的脚本
/usr/bin/smbprint                此脚本可以将打印任务送至SMB主机的打印机
/usr/bin/smbstatus                列出本地主机的SMB连接
smbfs                        smbfs文件系统,可以将共享文件夹用mount命令挂载至本地

samba主配置文件/etc/samba/smb.conf中的主要参数设定:
该文件中#为信息注释符 ;为参数注释符

#======================= Global Settings =====================================


workgroup = MYGROUP
工作组名称

server string = Samba Server
主机说明

netbios name = SMBServer
在网络中的netbios名称,如果没有设定,预设值为HOSTNAME

hosts allow = 192.168.1. 192.168.2. 127.
设定哪些ip地址可访问主机

security = user
samba的安全级别,从低到高有四级:share/user/server/domain
share:        任何用户都可以访问服务器上的资源,无须帐号
user:        需要用户名和密码进行验证
server:        帐号验证交给另外一个服务器,如交给另一台NT服务器.
        如果递交失败,就退到user安全级.
domain:        这个安全级别要求网络上存在一台Windows的主域控制器,samba将帐号递交
        给该服务器验证.
    user/server/domain要求用户在本地linux机器上也有系统帐户,否则不能访问.
这里只简单介绍一下share/user的用法,详悉设定请参看附录

encrypt passwords = yes
使用加密密码

smb passwd file = /etc/samba/smbpasswd
存放samba帐户密码的文件

local master = yes
samba服务器可以成为本地主浏览器

os level = 33
samba服务器的管理等级

domain master = yes
该服务器成为域浏览器

preferred master = yes
该服务器成为工作组中的首要主浏览器

#============================ Share Definitions ==============================

   comment = Home Directories
   browseable = no
   writable = yes
   valid users = %S
   create mode = 0664
   directory mode = 0775
上面是用户家

Axin 发表于 2005-8-22 09:01:34

187=Application Communication Interface
188=Plus Five's MUMPS
189=Queued File Transport
189=Queued File Transport
190=Gateway Access Control Protocol
190=Gateway Access Control Protocol
191=Prospero Directory Service
191=Prospero Directory Service
192=OSU Network Monitoring System
193=srmp, Spider Remote Monitoring Protocol
194=irc, Internet Relay Chat Protocl
195=DNSIX Network Level Module Audit
196=DNSIX Session Mgt Module Audit Redir
197=Directory Location Service
198=Directory Location Service Monitor
199=SMUX
200=IBM System Resource Controller
201=at-rtmp AppleTalk Routing Maintenance
202=at-nbp AppleTalk Name Binding
203=at-3 AppleTalk Unused
204=AppleTalk Echo
205=AppleTalk Unused
206=AppleTalk Zone Information
207=AppleTalk Unused
208=AppleTalk Unused
209=Trivial Authenticated Mail Protocol
210=ANSI Z39.50z39.50
211=Texas Instruments 914C/G Terminal
212=ATEXSSTRanet
213=IPX
214=VM PWSCSvmpwscs
215=Insignia Solutions
216=Access Technology License Server
217=dBASE Unix
218=Netix Message Posting Protocol
219=Unisys ARPsuarps
220=Interactive Mail Access Protocol v3
221=Berkeley rlogind with SPX auth
222=Berkeley rshd with SPX auth
223=Certificate Distribution Center
224=Reserved (224-241)
241=Reserved (224-241)
242=Unassigned#
243=Survey Measurement
244=Unassigned#
245=LINKlink
246=Display Systems Protocol
247-255 Reserved
256-343 Unassigned
344=Prospero Data Access Protocol
345=Perf Analysis Workbench
346=Zebra serverzserv
347=Fatmen Serverfatserv
348=Cabletron Management Protocol
349-370 Unassigned
371=Clearcaseclearcase
372=Unix Listservulistserv
373=Legent Corporation
374=Legent Corporation
375=Hasslehassle
376=Amiga Envoy Network Inquiry Proto
377=NEC Corporation
378=NEC Corporation
379=TIA/EIA/IS-99 modem client
380=TIA/EIA/IS-99 modem server
381=hp performance data collector
382=hp performance data managed node
383=hp performance data alarm manager
384=A Remote Network Server System
385=IBM Application
386=ASA Message Router Object Def.
387=Appletalk Update-Based Routing Pro.
388=Unidata LDM Version 4
389=Lightweight Directory Access Protocol
390=UISuis
391=SynOptics SNMP Relay Port
392=SynOptics Port Broker Port
393=Data Interpretation System
394=EMBL Nucleic Data Transfer
395=NETscout Control Protocol
396=Novell Netware over IP
397=Multi Protocol Trans. Net.
398=Kryptolankryptolan
399=Unassigned#
400=Workstation Solutions
401=Uninterruptible Power Supply
402=Genie Protocol
403=decapdecap
404=ncednced
405=ncldncld
406=Interactive Mail Support Protocol
407=Timbuktutimbuktu
408=Prospero Resource Manager Sys. Man.
409=Prospero Resource Manager Node Man.
410=DECLadebug Remote Debug Protocol
411=Remote MT Protocol
412=Trap Convention Port
413=SMSPsmsp
414=InfoSeekinfoseek
415=BNetbnet
416=Silverplattersilverplatter
417=Onmuxonmux
418=Hyper-Ghyper-g
419=Arielariel1
420=SMPTEsmpte
421=Arielariel2
422=Arielariel3
423=IBM Operations Planning and Control Start
424=IBM Operations Planning and Control Track
425=ICADicad-el
426=smartsdpsmartsdp
427=Server Location
429=OCS_AMU
430=UTMPSDutmpsd
431=UTMPCDutmpcd
432=IASDiasd
433=NNSPnnsp
434=MobileIP-Agent
435=MobilIP-MN
436=DNA-CMLdna-cml
437=comscmcomscm
439=dasp, Thomas Obermair
440=sgcpsgcp
441=decvms-sysmgtdecvms-sysmgt
442=cvc_hostdcvc_hostd
443=https
444=Simple Network Paging Protocol
445=Microsoft-DS
446=DDM-RDBddm-rdb
447=DDM-RFMddm-dfm
448=DDM-BYTEddm-byte
449=AS Server Mapper
450=TServertserver
512=exec, Remote process execution
513=login, remote login
514=cmd, exec with auto auth.
514=syslog
515=Printer spooler
516=Unassigned
517=talk
519=unixtime
520=extended file name server
521=Unassigned
522=Unassigned
523=Unassigned
524=Unassigned
526=newdate
530=rpc courier
531=chatconference
532=readnewsnetnews
533=for emergency broadcasts
539=Apertus Technologies Load Determination
540=uucp
541=uucp-rlogin
542=Unassigned
543=klogin
544=kshell
545=Unassigned
546=Unassigned
547=Unassigned
548=Unassigned
549=Unassigned
550=new-who
551=Unassigned
552=Unassigned
553=Unassigned
554=Unassigned
555=dsf
556=remotefs
557-559=rmonitor
560=rmonitord
561=dmonitor
562=chcmd
563=Unassigned
564=plan 9 file service
565=whoami
566-569 Unassigned
570=demonmeter
571=udemonmeter
572-599 Unassigned ipc server
600=Sun IPC server
607=nqs
606=Cray Unified Resource Manager
608=Sender-Initiated/Unsolicited File Transfer
609=npmp-trapnpmp-trap
610=npmp-localnpmp-local
611=npmp-guinpmp-gui
634=ginadginad
666=Doom Id Software
704=errlog copy/server daemon
709=EntrustManager
729=IBM NetView DM/6000 Server/Client
730=IBM NetView DM/6000 send/tcp
731=IBM NetView DM/6000 receive/tcp
741=netGWnetgw
742=Network based Rev. Cont. Sys.
744=Flexible License Manager
747=Fujitsu Device Control
748=Russell Info Sci Calendar Manager
749=kerberos administration
751=pump
752=qrh
754=send
758=nlogin
759=con
760=ns
762=quotad
763=cycleserv
765=webster
767=phonephonebook
769=vid
771=rtip
772=cycleserv2
774=acmaint_dbd
775=acmaint_transd
780=wpgs
786=Concertconcert
800=mdbs_daemon
996=Central Point Software
997=maitrd
999=puprouter
1023=Reserved
1024=Reserved
1025=network blackjack
1030=BBN IAD
1031=BBN IAD
1032=BBN IAD
1067=Installation Bootstrap Proto. Serv.
1068=Installation Bootstrap Proto. Cli.
1080=SOCKS
1083=Anasoft License Manager
1084=Anasoft License Manager
1155=Network File Access
1222=SNI R&D network
1248=hermes
1346=Alta Analytics License Manager
1347=multi media conferencing
1347=multi media conferencing
1348=multi media conferencing
1349=Registration Network Protocol
1350=Registration Network Protocol
1351=Digital Tool Works (MIT)
1352=/Lotus Notelotusnote
1353=Relief Consulting
1354=RightBrain Software
1355=Intuitive Edge
1356=CuillaMartin Company
1357=Electronic PegBoard
1358=CONNLCLIconnlcli
1359=FTSRVftsrv
1360=MIMERmimer
1361=LinX
1362=TimeFliestimeflies
1363=Network DataMover Requester
1364=Network DataMover Server
1365=Network Software Associates
1366=Novell NetWare Comm Service Platform
1367=DCSdcs
1368=ScreenCastscreencast
1369=GlobalView to Unix Shell
1370=Unix Shell to GlobalView
1371=Fujitsu Config Protocol
1372=Fujitsu Config Protocol
1373=Chromagrafxchromagrafx
1374=EPI Software Systems
1375=Bytexbytex
1376=IBM Person to Person Software
1377=Cichlid License Manager
1378=Elan License Manager
1379=Integrity Solutions
1380=Telesis Network License Manager
1381=Apple Network License Manager
1382=udt_os
1383=GW Hannaway Network License Manager
1384=Objective Solutions License Manager
1385=Atex Publishing License Manager
1386=CheckSum License Manager
1387=Computer Aided Design Software Inc LM
1388=Objective Solutions DataBase Cache
1389=Document Manager
1390=Storage Controller
1391=Storage Access Server
1392=Print Managericlpv-pm
1393=Network Log Server
1394=Network Log Client
1395=PC Workstation Manager software
1396=DVL Active Mail
1397=Audio Active Mail
1398=Video Active Mail
1399=Cadkey License Manager
1400=Cadkey Tablet Daemon
1401=Goldleaf License Manager
1402=Prospero Resource Manager
1403=Prospero Resource Manager
1404=Infinite Graphics License Manager
1405=IBM Remote Execution Starter
1406=NetLabs License Manager
1407=DBSA License Manager
1408=Sophia License Manager
1409=Here License Manager
1410=HiQ License Manager
1411=AudioFileaf
1412=InnoSysinnosys
1413=Innosys-ACLinnosys-acl
1414=IBM MQSeriesibm-mqseries
1415=DBStardbstar
1416=Novell LU6.2novell-lu6.2
1417=Timbuktu Service 1 Port
1417=Timbuktu Service 1 Port
1418=Timbuktu Service 2 Port
1419=Timbuktu Service 3 Port
1420=Timbuktu Service 4 Port
1421=Gandalf License Manager
1422=Autodesk License Manager
1423=Essbase Arbor Software
1424=Hybrid Encryption Protocol
1425=Zion Software License Manager
1426=Satellite-data Acquisition System 1
1427=mloadd monitoring tool
1428=Informatik License Manager
1429=Hypercom NMSnms
1430=Hypercom TPDUtpdu
1431=Reverse Gosip Transport
1432=Blueberry Software License Manager
1433=Microsoft-SQL-Server
1434=Microsoft-SQL-Monitor
1435=IBM CISCibm-cics
1436=Satellite-data Acquisition System 2
1437=Tabulatabula
1438=Eicon Security Agent/Server
1439=Eicon X25/SNA Gateway
1440=Eicon Service Location Protocol
1441=Cadis License Management
1442=Cadis License Management
1443=Integrated Engineering Software
1444=Marcam License Management
1445=Proxima License Manager
1446=Optical Research Associates License Manager
1447=Applied Parallel Research LM
1448=OpenConnect License Manager
1449=PEportpeport
1450=Tandem Distributed Workbench Facility
1451=IBM Information Management
1452=GTE Government Systems License Man
1453=Genie License Manager
1454=interHDL License Manager
1454=interHDL License Manager
1455=ESL License Manager
1456=DCAdca
1457=Valisys

lincoln_834100 发表于 2006-11-5 11:30:21

这帖怎么没人顶啊?

npcomet 发表于 2006-11-5 16:29:16

:-D:-D:-D

慕容醉 发表于 2006-11-5 21:00:01

好东西哦

zzp1004 发表于 2006-11-20 11:05:04

好东西!
页: [1]
查看完整版本: 快速架设各种服务器