前提你已经安装tomcat和apache都能正常运行
第一步:首行下载
https://tomcat.apache.org/download-connectors.cgi
tomcat-connectors-1.2.48-src.tar.gz
tar -zxvf tomcat-connectors-1.2.48-src.tar.gz
cd tomcat-connectors-1.2.48-src/native/
./configure --with-apxs=/usr/local/apache2.4/bin/apxs
(此处apxs地址可能不一样,可用命令" whereis apxs "来查看)
如果没有的话,先安装apxs ,太好了我有。没了百度去。
make
make install
2、在Apacheconf下新建 workers.properties
worker.list = controller,tomcat1,tomcat2
#worker.list = controller
#列表========tomcat1========
worker.tomcat1.port=1009 #ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat1.host=localhost #tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat1.type=ajp13 #ajp12,ajp13
worker.tomcat1.lbfactor = 1 #server的加权比重,值越高,分得的请求越多
#========tomcat2========
worker.tomcat2.port=2009 #ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat2.host=localhost #tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat2.type=ajp13 #ajp12,ajp13
worker.tomcat2.lbfactor = 1 #server的加权比重,值越高,分得的请求越多
#========controller,负载均衡控制器========
worker.controller.type=lb
worker.retries=3 #断线重连次数
worker.controller.balance_workers=tomcat1,tomcat2 #指定分担请求的tomcat
worker.controller.sticky_session=true
worker.controller.sticky_session_force=false
3、在Apacheconf下新建 mod_jk.conf
#加载mod_jk.so
LoadModule jk_module modules/mod_jk.so
#加载workers.properties
JkWorkersFile conf/workers.properties
#需要拦截的类容 /* 表示所有
JkMount /* controller
(下面这个加入了打印输出日志,上面仅作为测试使用,来自网络:
JkWorkersFile /usr/local/web/apache/conf/workers.properties
# Where to put jk logs
JkLogFile /usr/local/web/apache/logs/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"
# 将所有servlet 和jsp请求通过ajp13的协议送给Tomcat,让Tomcat来处理
JkMount /tomcatTest/* worker1
JkMount /tomcatTest/*.jsp worker1
JkMount /*.jsp worker1
)
4、配置httpd:conf 在Apache启动时加载mod_jk.conf
在httpd最后一段加
include conf/mod_jk.conf
(这一段摘自网络:
LoadModule jk_module modules/mod_jk.so
Include /usr/local/apache2.4/conf/mod_jk.conf
道理都是相同的
)
最后需要注意,版本匹配。