Linux下Web服务器架设笔录教学内容.doc
《Linux下Web服务器架设笔录教学内容.doc》由会员分享,可在线阅读,更多相关《Linux下Web服务器架设笔录教学内容.doc(133页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Good is good, but better carries it.精益求精,善益求善。Linux下Web服务器架设笔录-Linux下Web服务器架设笔录本文环境:CentOS5.4+ApacheApache的安装CentOS默认已安装Apache服务器软件,可使用rpm命令检查安装情况:dxlocalhost$rpm-qa|grephttpdhttpd-2.2.3-31.el5.centos若没有默认安装,可在安装光盘内找到rpm包并进行安装:dxlocalhost$rpmivhhttpd-2.2.3-31.e15.i386.rpm安装成功后,几个重要的文件分布如下:/etc/httpd
2、/conf/httpd.confApache的主配置文件/etc/httpd/logsApache的日志存放目录/etc/httpd/modulesApache的模块存放目录/usr/lib/httpd/modulesApache模块存放的另一目录/usr/sbin/apachectlApache控制脚本(非目录),用于启动、停止等操作Httpd进程运行时需要apache用户的支持,CentOS在安装时一般情况下已默认创建了这个用户,如果系统中没有这个用户,应该重新创建。运行ApacheApache安装完成之后,有一套默认的配置文件可以启动:rootlocalhostdx#/usr/sbin/
3、apachectlstart查看进程的启动状态:rootlocalhostdx#ps-eaf|grephttpdroot111961014:54?00:00:00/usr/sbin/httpd-kstartapache1119711196014:54?00:00:00/usr/sbin/httpd-kstartapache1119811196014:54?00:00:00/usr/sbin/httpd-kstartapache1119911196014:54?00:00:00/usr/sbin/httpd-kstartapache1120011196014:54?00:00:00/usr/sb
4、in/httpd-kstartapache1120111196014:54?00:00:00/usr/sbin/httpd-kstartapache1120211196014:54?00:00:00/usr/sbin/httpd-kstartapache1120311196014:54?00:00:00/usr/sbin/httpd-kstartapache1120411196014:54?00:00:00/usr/sbin/httpd-kstart可以看到,有9个Apache的进程,其中一个是由root用户身份运行,另外8个以apache用户身份运行,这8个进程是第1个进程的子进程。启动多个
5、进程的目的是为了更好地为客户端提供服务,初始子进程的个数可以在配置文件中指定。设置Apache随系统启动而启动:rootlocalhostdx#chkconfig-listhttpdhttpd0:关闭1:关闭2:关闭3:关闭4:关闭5:关闭6:关闭rootlocalhostdx#chkconfighttpdonrootlocalhostdx#chkconfig-listhttpdhttpd0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭检查端口监听状态:rootlocalhostdx#netstat-an|grep:80tcp00:80:*LISTEN确定端口状态后,只要防火墙有设置h
6、ttp为信任的协议,就可以在客户端访问Apache的测试页面了:http:/172.18.20.243/Apache服务器的全局配置Apache服务器的配置主要集中在主配置文件/etc/httpd/conf/httpd.conf中,本节先介绍Apache服务器的全局基本配置,之后再介绍目录访问控制,用户个人网站配置,虚拟主机配置等其他高级配置。Apache的例子配置文件包含了很多的配置选项,涵盖了Apache服务器的大部分的重要功能,里面的配置指令包括全局配置、主服务器配置和虚拟主机配置三大部分,这里首先解释一下例子配置文件中有关全局配置的指令,他们决定了Apache服务器的总体性能。root
7、localhostconf#more/etc/httpd/conf/httpd.conf#ThisisthemainApacheserverconfigurationfile.Itcontainsthe#configurationdirectivesthatgivetheserveritsinstructions.#Seefordetailedinformation.#Inparticular,see#foradiscussionofeachconfigurationdirective.#DoNOTsimplyreadtheinstructionsinherewithoutunderstand
8、ing#whattheydo.Theyrehereonlyashintsorreminders.Ifyouareunsure#consulttheonlinedocs.Youhavebeenwarned.#Theconfigurationdirectivesaregroupedintothreebasicsections:#1.DirectivesthatcontroltheoperationoftheApacheserverprocessasa#whole(theglobalenvironment).#2.Directivesthatdefinetheparametersofthemaino
9、rdefaultserver,#whichrespondstorequeststhatarenthandledbyavirtualhost.#Thesedirectivesalsoprovidedefaultvaluesforthesettings#ofallvirtualhosts.#3.Settingsforvirtualhosts,whichallowWebrequeststobesentto#differentIPaddressesorhostnamesandhavethemhandledbythe#sameApacheserverprocess.#Configurationandlo
10、gfilenames:Ifthefilenamesyouspecifyformany#oftheserverscontrolfilesbeginwith/(ordrive:/forWin32),the#serverwillusethatexplicitpath.Ifthefilenamesdo*not*begin#with/,thevalueofServerRootisprepended-sologs/foo.log#withServerRootsetto/etc/httpdwillbeinterpretedbythe#serveras/etc/httpd/logs/foo.log.#Sect
11、ion1:GlobalEnvironment#全局配置部分指令#ThedirectivesinthissectionaffecttheoveralloperationofApache,#suchasthenumberofconcurrentrequestsitcanhandleorwhereit#canfinditsconfigurationfiles.#Dontgiveawaytoomuchinformationaboutallthesubcomponents#wearerunning.Commentoutthislineifyoudontmindremotesites#findingout
12、whatmajoroptionalmodulesyouarerunningServerTokensOS#连接时显示Apache的版本和操作系统的名称#ServerRoot:Thetopofthedirectorytreeunderwhichtheservers#configuration,error,andlogfilesarekept.#NOTE!IfyouintendtoplacethisonanNFS(orotherwisenetwork)#mountedfilesystemthenpleasereadtheLockFiledocumentation#(availableat);#you
13、willsaveyourselfalotoftrouble.#DoNOTaddaslashattheendofthedirectorypath.#ServerRoot/etc/httpd#指定服务器的根目录,以后在配置文件中指定起始符号不是”/”的路径时,以该目录作为起始目录,如logs/error_log即表示/etc/httpd/logs/error_log#PidFile:Thefileinwhichtheservershouldrecorditsprocess#identificationnumberwhenitstarts.#PidFilerun/httpd.pid#Timeout:
14、Thenumberofsecondsbeforereceivesandsendstimeout.#Timeout120#客户端建立连接后如果连续120秒内没有响应,则切断连接#KeepAlive:Whetherornottoallowpersistentconnections(morethan#onerequestperconnection).SettoOfftodeactivate.#KeepAliveOff#“Off”表示不使用持久连接功能,即在一个TCP连接中只传送一个请求和一个应答消息。建议设置为on,可提高服务器性能。#MaxKeepAliveRequests:Themaximumn
15、umberofrequeststoallow#duringapersistentconnection.Setto0toallowanunlimitedamount.#Werecommendyouleavethisnumberhigh,formaximumperformance.#MaxKeepAliveRequests100#使用持久连接时,该连接允许发送的最大请求消息数。如果设为0,表示没有限制。#KeepAliveTimeout:Numberofsecondstowaitforthenextrequestfromthe#sameclientonthesameconnection.#Keep
16、AliveTimeout15#使用持久连接功能时,客户端的下一个请求消息超过15秒还未到达,就切断该连接。#Server-PoolSizeRegulation(MPMspecific)#设置使用preforkMPM运行方式的参数,CentOS中默认以此方式运行Apache服务器。#配置Apache运行时启动多少个进程来处理客户端的请求。#preforkMPM#StartServers:numberofserverprocessestostart#MinSpareServers:minimumnumberofserverprocesseswhicharekeptspare#MaxSpareSer
17、vers:maximumnumberofserverprocesseswhicharekeptspare#ServerLimit:maximumvalueforMaxClientsforthelifetimeoftheserver#MaxClients:maximumnumberofserverprocessesallowedtostart#MaxRequestsPerChild:maximumnumberofrequestsaserverprocessserves#模块定义开始StartServers8#初始的httpd子进程数为8个MinSpareServers5#最小的空闲httpd子进
18、程总数为5个MaxSpareServers20#最大的空闲httpd子进程总数为20个ServerLimit256#最大的httpd子进程数允许值为256个MaxClients256#最大客户端连接数为256MaxRequestsPerChild4000#每个httpd子进程处理了4000个请求后要关闭#模块定义结束#设置workerMPM方式的参数,与preforkMPM类似,但设置的是线程数。#workerMPM#StartServers:initialnumberofserverprocessestostart#MaxClients:maximumnumberofsimultaneous
19、clientconnections#MinSpareThreads:minimumnumberofworkerthreadswhicharekeptspare#MaxSpareThreads:maximumnumberofworkerthreadswhicharekeptspare#ThreadsPerChild:constantnumberofworkerthreadsineachserverprocess#MaxRequestsPerChild:maximumnumberofrequestsaserverprocessserves#模块定义开始StartServers2#主控制进程生成2个
20、httpd子进程MaxClients150#最大客户端连接数为150MinSpareThreads25#最小的空闲httpd线程总数为25个MaxSpareThreads75#最大的空闲httpd线程总数为75个ThreadsPerChild25#每个子进程可产生25个线程MaxRequestsPerChild0#每个子进程处理的最大请求数,0表示没有限制#模块定义结束#Listen:AllowsyoutobindApachetospecificIPaddressesand/or#ports,inadditiontothedefault.Seealsothe#directive.#Change
21、thistoListenonspecificIPaddressesasshownbelowto#preventApachefromglommingontoallboundIPaddresses(0.0.0.0)#Listen12.34.56.78:80Listen80#设置服务器的监听端口为80#DynamicSharedObject(DSO)Support#TobeabletousethefunctionalityofamodulewhichwasbuiltasaDSOyou#havetoplacecorrespondingLoadModulelinesatthislocationsothe
22、#directivescontainedinitareactuallyavailable_before_theyareused.#Staticallycompiledmodules(thoselistedbyhttpd-l)donotneed#tobeloadedhere.#Example:#LoadModulefoo_modulemodules/mod_foo.so#加载动态模块(DSO)LoadModuleauth_basic_modulemodules/mod_auth_basic.soLoadModuleauth_digest_modulemodules/mod_auth_digest
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Linux Web 服务器 架设 笔录 教学内容
限制150内