您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 销售管理 > Apache与tomcat的整合、负载均衡和加入启动和系统服务
Apache与tomcat的整合及负载均衡系统环境:WindowsServer2008R2SP1虚拟机软件:Hyper-V管理器6.1.7601.17514虚拟机环境:RedHatEnterpriseLinuxServerrelease5.4(Tikanga)X64安装软件版本:JDK:1.6.0_19Tomcat:6.0.20Apache:2.2.19JK:1.2.10实施步骤:一、安装软件。。。1tar-xzvfjdk1.6.0_19.tar.gz2tarxvfztomcat.tar.gz3tarzxvfhttpd-2.2.19.tar.gz4cdhttpd-2.2.195./configure--prefix=/usr/local/apache2--enable-so--enable-mods-shared=most--with-mpm=worker6make7makeinstall8tarzxvfjakarta-tomcat-connectors-1.2.10-src.tar.gz9cdjakarta-tomcat-connectors-1.2.10-src/jk/native/10./buildconf.sh11./configure--with-apxs=/usr/local/apache2/bin/apxs12make13makeinstall二、配置整合及负载均衡1cp/usr/local/jakarta-tomcat-connectors-1.2.10-src/jk/native/apache-2.0/mod_jk.so/usr/local/apache2/modules2配置环境变量vi/etc/profile在文本末尾加入以下内容JAVA_HOME=JDK安装路径CATALINA_HOME=tomcat安装路径CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$CATALINA_HOME/lib/servlet-api.jarPATH=$JAVA_HOME/bin:$PATHexportJAVA_HOMECATALINA_HOMECLASSPATHPATH3应用初始的环境变量source/etc/profile4修改apache的httpd.confvi/usr/local/apache2/conf/httpd.conf修改以下几处并且在末尾加上:Include/usr/local/apache2/conf/mod_jk.conf5添加及设置mod_jk.confvi/usr/local/apache2/mod_jk.conf增加以下内容#加载mod_jkModuleLoadModulejk_modulemodules/mod_jk.so#指定workers.properties文件路径JkWorkersFileconf/workers.propertiesJkLogFilelogs/mod_jk.logJkLogLevelinfo#指定那些请求交给tomcat处理,controller为在workers.propertise里指定的负载分配控制制器JkMount/*lb6添加及设置workers.propertiesvi/usr/local/apache2/conf/workers.properties添加以下内容worker.list=lb,tomcat1,tomcat2#server列表#========tomcat1========worker.tomcat1.port=8009#ajp13端口号,在tomcat下server.xml配置,默认8009worker.tomcat1.host=10.1.1.2#tomcat的主机地址,如不为本机,请填写ip地址worker.tomcat1.type=ajp13worker.tomcat1.lbfactor=1#server的加权比重,值越高,分得的请求越多#========tomcat2========worker.tomcat2.port=8009#ajp13端口号,在tomcat下server.xml配置,默认8009worker.tomcat2.host=10.1.1.3#tomcat的主机地址,如不为本机,请填写ip地址worker.tomcat2.type=ajp13worker.tomcat2.lbfactor=1#server的加权比重,值越高,分得的请求越多#========controller,负载均衡控制器========worker.lb.type=lbworker.lb.balanced_workers=tomcat1,tomcat2#指定分担请求的tomcatworker.lb.sticky_session=17、将JSP文件放入/usr/local/tomcat/webapps/ROOT8启动apache和tomcat8打开浏览器输入就是这么简单。三、将apache和tomcat加入启动和系统服务选项1Apache加入启动项里面:echo'/usr/local/apache2/bin/apachectlstart'/etc/rc.local2Apache加入到系统服务里面:cp/安装目录下/apache/bin/apachectl/etc/rc.d/init.d/httpd修改httpd在文件头部加入如下内容:####CommentstosupportchkconfigonRedHatLinux#chkconfig:23459090#description:httpserver###保存在打入chkconfig--addhttpdchkconfig--level345httpdon3tomcat加入启动和系统服务选项安装jsvc#cd/usr/local/tomcat/bin#tarxvfzjsvc.tar.gz#cdjsvc-src#shsupport/buildconf.sh#chmod755configure#./configure--with-java=/usr/local/java(改成你的JDK的位置)#make注:我在執行./configure--with-java=/usr/local/java的過程中,產生configure:error:noacceptableCcompilerfoundin$PATH這樣的錯誤提示,發現是沒有安裝C編譯器,于是執行“yuminstallgcc”安裝了gcc,之后重新執行./configure--with-java=/usr/local/java就Ok了修改启动文件#vi./native/Tomcat5.sh改成如下内容:#!/bin/sh#chkconfig:3458713#description:TomcatDaemon#processname:jsvc#pidfile:/var/run/jsvc.pid#config:#Sourcefunctionlibrary.#./etc/rc.d/init.d/functions#prog=tomcat#Smallshellscripttoshowhowtostart/stopTomcatusingjsvc#IfyouwanttohaveTomcatrunningonport80pleasemodifytheserver.xml#file:#port=80minProcessors=5maxProcessors=75#enableLookups=trueredirectPort=8443#acceptCount=10debug=0connectionTimeout=60000/#YouneedadevelopementversionofTomcat(ApacheTomcat/4.1-dev)#Adaptthefollowinglinestoyourconfiguration################################################################################Copyright2004TheApacheSoftwareFoundation.##LicensedundertheApacheLicense,Version2.0(theLicense);#youmaynotusethisfileexceptincompliancewiththeLicense.#YoumayobtainacopyoftheLicenseat##:##!--Defineanon-SSLHTTP/1.1Connectoronport80--#ConnectorclassName=org.apache.catalina.connector.http.HttpConnector#port=80minProcessors=5maxProcessors=75#enableLookups=trueredirectPort=8443#acceptCount=10debug=0connectionTimeout=60000/##ThatisforTomcat-5.0.x(ApacheTomcat/5.0)##AdaptthefollowinglinestoyourconfigurationJAVA_HOME=/usr/local/jdkCATALINA_HOME=/usr/local/tomcatDAEMON_HOME=/usr/local/tomcat/binTOMCAT_USER=root#formultiinstancesadaptthoselines.TMP_DIR=/var/tmpPID_FILE=/var/run/jsvc.pidCATALINA_BASE=/usr/local/tomcatCATALINA_OPTS=CLASSPATH=\$JAVA_HOME/lib/tools.jar:\$CATALINA_HOME/bin/commons-daemon.jar:\$CATALINA_HOME/bin/bootstrap.jarcase$1instart)##StartTomcat#$DAEMON_HOME/jsvc-src/jsvc\-user$TOMCAT_USER\-home$JAVA_HOME\-Dcatalina.home=$CATALINA_HOME\-Dcatalina.base=$CATALINA_BASE\-Djava.io.tmpdir=$TMP_DIR\-wait10\-pidfile$PID_F
本文标题:Apache与tomcat的整合、负载均衡和加入启动和系统服务
链接地址:https://www.777doc.com/doc-1577825 .html