Windows下的集群参考:http://cuisuqiang.iteye.com/blog/2070357Linux上安装Apache与问题说明:http://cuisuqiang.iteye.com/blog/2070460因为已经有了使用ajp_proxy的示例,Apache自己集成,而且就是改参数的事情,所以这里集群时使用JK来做!下载jk:http://tomcat.apache.org/download-connectors.cgi下载文件:tomcat-connectors-1.2.40-src.tar.gz

解压安装等操作:

tar-zxvftomcat-connectors-1.2.40-src.tar.gz cdtomcat-connectors-1.2.40-src cdnative ./configure--with-apxs=/usr/local/apache2/bin/apxs--with-java-home=/usr/jdk1.6 make makeinstall cpapache-2.0/mod_jk.so/usr/local/apache2/modules/

/usr/local/apache2/conf/httpd.conf增加include /usr/local/apache2/conf/mod-jk.conf

新建mod-jk.conf配置文件

#加载mod_jk模块,注意名称与modules目录下的文件名保持一致. LoadModulejk_module/usr/local/apache2/modules/mod_jk.so #指定workers.properties文件目录. JkWorkersFile/usr/local/apache2/conf/workers.properties #指定哪些请求由tomcat处理,controller为workers.properties文件里指定的负载控制器. JkMount/*controller #JkMount/*.htmlcontroller #JkMount/*.jspcontroller #JkMount/*.docontroller #JkMount/servlet/*controller #JkUnMount/index.htmlcontroller

新建workers.properties配置文件

worker.list=controller#不指定报错Couldnotfindaworkerforworkername=controller #========tomcat1======== worker.tomcat1.port=8019 worker.tomcat1.host=localhost worker.tomcat1.type=ajp13 worker.tomcat1.lbfactor=1 #========tomcat2======== worker.tomcat2.port=8029 worker.tomcat2.host=localhost worker.tomcat2.type=ajp13 worker.tomcat2.lbfactor=1 #========tomcat3======== worker.tomcat3.port=8039 worker.tomcat3.host=localhost worker.tomcat3.type=ajp13 worker.tomcat3.lbfactor=3 #========tomcat4======== worker.tomcat4.port=8049#指定tomcat2服务器AJP的端口,默认为8009 worker.tomcat4.host=localhost#指定tomcat2服务器IP或域名 worker.tomcat4.type=ajp13#指定tomcat2与apacheAJP通讯协议 worker.tomcat4.lbfactor=3#指定负载平衡因数,只有启用了负载平衡才有用. #========controller负载平衡控制器======== worker.controller.type=lb#指定controller类型 worker.controller.balanced_workers=tomcat1,tomcat2,tomcat3,tomcat4#指定负载平衡的tomcat worker.controller.sticky_session=true#指定是否粘性session worker.controller.sticky_session_force=false worker.connection_pool_size=3000 worker.connection_pool_minsize=50 worker.connection_pool_timeout=50000 #session配置说明: #当sticky_session,sticky_session_force都为true时不复制session, #sticky_session_force=false指集群中某台服务器多次请求没有响应,则转发到其它服务器处理, #sticky_session=false不使用粘性session,同时配置不复制session时,注意转发请求后可能会找不到原来的session.

看到了我这里配置了四个集群,因为在Windows上已经使用,所以这里我直接指定他的AJP端口即可

启动Apache访问应用即可

声明:有的资源均来自网络转载,版权归原作者所有,如有侵犯到您的权益 请联系邮箱:our333@126.com我们将配合处理!

原文地址:Linux下apache+tomcat+jk集群发布于2021-11-25 16:31:01