CentOS下Apache + Tomcat集群
1.以下几个包是需要下载的
Tomcat http://apache.etoak.com/tomcat/tomcat-7/v7.0.27/bin/apache-tomcat-7.0.27.tar.gz
Apr http://labs.renren.com/apache-mirror//apr/apr-1.4.6.tar.gz
Apr Util http://apache.etoak.com//apr/apr-util-1.4.1.tar.gz
Apache Http Server http://labs.renren.com/apache-mirror//httpd/httpd-2.2.22.tar.gz
Connector http://www.apache.org/dist/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.35-src.tar.gz
2.安装APR
[root@localhost app]#tar -zxvf apr-1.4.6.tar.gz
[root@localhost app]#cd apr-1.4.6
[root@localhost apr-1.4.6]#./buildconfbuildconf: checking installation...buildconf: python version 2.6.5 (ok)buildconf: autoconf not found. You need autoconf version 2.59 or newer installed to build APR from SVN.[root@localhost apr-1.4.6]#yum install autoconf[root@localhost apr-1.4.6]#./buildconfbuildconf: libtool not found. You need libtool version 1.4 or newer installed to build APR from SVN.[root@localhost apr-1.4.6]#yum install libtool[root@localhost apr-1.4.6]#./configure[root@localhost apr-1.4.6]# make-bash: make: command not found[root@localhost apr-1.4.6]#yum install make[root@localhost apr-1.4.6]# make[root@localhost apr-1.4.6]# make install
[root@localhost app]# tar -zxvf apr-util-1.4.1.tar.gz[root@localhost app]# cd apr-util-1.4.1[root@localhost apr-util-1.4.1]#./buildconf --with-apr=/app/apr-1.4.6[root@localhost apr-util-1.4.1]# ./configure --with-apr=/app/apr-1.4.6[root@localhost apr-util-1.4.1]#make[root@localhost apr-util-1.4.1]#make install
[root@localhost app]# tar -zxvf httpd-2.2.22.tar.gz[root@localhost app]# cd httpd-2.2.22[root@localhost httpd-2.2.22]# ./buildconf[root@localhost httpd-2.2.22]# ./configure[root@localhost httpd-2.2.22]# make[root@localhost httpd-2.2.22]# make install
[root@localhost app]tar -zxvf tomcat-connectors-1.2.35-src.tar.gz[root@localhost app]cd tomcat-connectors-1.2.35-src/native[root@localhost native]# ./configure --with-apxs=/usr/local/apache2/bin/apxs[root@localhost native]#make[root@localhost native]#make install
Include conf/mod_jk.conf
#加载mod_jk ModuleLoadModule jk_module modules/mod_jk.so#指定 workers.properties文件路径JkWorkersFile conf/workers.properties#指定那些请求交给tomcat处理,"controller"为在workers.propertise里指定的负载分配控制器JkMount /*.jsp controller
worker.list = controller,tomcat1,tomcat2 #server 列表#========tomcat1========worker.tomcat1.port=8009 #ajp13 端口号,在tomcat下server.xml配置,默认8009worker.tomcat1.host=localhost #tomcat的主机地址,如不为本机,请填写ip地址worker.tomcat1.type=ajp13worker.tomcat1.lbfactor = 1 #server的加权比重,值越高,分得的请求越多#========tomcat2========worker.tomcat2.port=9009 #ajp13 端口号,在tomcat下server.xml配置,默认8009worker.tomcat2.host=localhost #tomcat的主机地址,如不为本机,请填写ip地址worker.tomcat2.type=ajp13worker.tomcat2.lbfactor = 1 #server的加权比重,值越高,分得的请求越多#========controller,负载均衡控制器========worker.controller.type=lbworker.controller.balanced_workers=tomcat1,tomcat2 #指定分担请求的tomcatworker.controller.sticky_session=1
[root@localhost app]# tar -zxvf apache-tomcat-7.0.27.tar.gz[root@localhost app]# mv apache-tomcat-7.0.27 tomcat1[root@localhost app]# cp -R tomcat1/ tomcat2
<Server port="9005" shutdown="SHUTDOWN">
<Connector port="9080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
<Connector port="9009" protocol="AJP/1.3" redirectPort="8443" />
<!-- You should set jvmRoute to support load-balancing via AJP ie :<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">--><Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2"><!--tomcat2将与tomcat1黏贴session 在这里指定黏贴对象-->
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="6"> <Manager className="org.apache.catalina.ha.session.DeltaManager" expireSessionsOnShutdown="false" notifyListenersOnReplication="true"/> <!-- <Manager className="org.apache.catalina.ha.session.BackupManager" expireSessionsOnShutdown="false" notifyListenersOnReplication="true" mapSendOptions="6"/> --> <Channel className="org.apache.catalina.tribes.group.GroupChannel"> <Membership className="org.apache.catalina.tribes.membership.McastService" address="228.0.0.5" port="45564" frequency="500" dropTime="3000"/> <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" address="auto" port="4000" <!--tomcat1将与tomcat2的端口不同--> selectorTimeout="100" maxThreads="6"/> <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter"> <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/> </Sender> <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/> <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/> </Channel> <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter=".*/.gif;.*/.js;.*/.jpg;.*/.png;.*/.htm;.*/.html;.*/.css;.*/.txt;"/> <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/> <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/> </Cluster>
chcon -t httpd_modules_t /usr/local/apache2/modules/mod_jk.so