Apache添加JK模块实现tomcat负载均衡

栏目: Java · 发布时间: 5年前

内容简介:二.搭建介绍单机系统:Centos7解压拷贝到/usr/local/tomcat/

一.搭建原理介绍

1.web访问tomcat两种方式

Apache添加JK模块实现tomcat负载均衡

2.JK模块介绍

Apache添加JK模块实现tomcat负载均衡

3.AJP原理介绍,比较http方式区别

Apache添加JK模块实现tomcat负载均衡

二.搭建介绍

单机系统:Centos7

1.安装 java 环境

Apache添加JK模块实现tomcat负载均衡

rpm包安装即可rpm -ivh jdk-8u121-linux-x64.rpm

Apache添加JK模块实现tomcat负载均衡

2.安装tomcat

本文为搭建tomcat负载均衡,所以启动两个tomcat实例

Apache添加JK模块实现tomcat负载均衡

解压拷贝到/usr/local/tomcat/

tar zxf apache-tomcat-8.5.35.tar.gz

cp apache-tomcat-8.5.35 /usr/local/tomcat

cp -r apache-tomcat-8.5.35 /usr/local/tomcat

cd /usr/local/tomcat/

创建tomcat集群 mkdir /usr/local/cluster,拷贝tomcat到系群里,命名实例1

Apache添加JK模块实现tomcat负载均衡

配置实例1:7080

修改tomcat配置文件

Apache添加JK模块实现tomcat负载均衡 Apache添加JK模块实现tomcat负载均衡 Apache添加JK模块实现tomcat负载均衡 Apache添加JK模块实现tomcat负载均衡

添加测试页面:index.jsp

Apache添加JK模块实现tomcat负载均衡 Apache添加JK模块实现tomcat负载均衡

注:

将默认的WEB-INF和index.jsp拷到新建的testcluster下

修改WEB-INF下的web.xml,在最下面加上<distributable/>,实现se'ssion共享,所有节点通过广播共享session

Apache添加JK模块实现tomcat负载均衡

启动tomcat实例1并测试

Apache添加JK模块实现tomcat负载均衡

用同样的方法设置实例2,将端口改为8080

Apache添加JK模块实现tomcat负载均衡 Apache添加JK模块实现tomcat负载均衡

![]

Apache添加JK模块实现tomcat负载均衡 Apache添加JK模块实现tomcat负载均衡 Apache添加JK模块实现tomcat负载均衡

启动tomcat实例2并测试

Apache添加JK模块实现tomcat负载均衡 Apache添加JK模块实现tomcat负载均衡

3.安装apache

××× http://httpd.apache.org/ httpd-2.4.37.tar.gz

下载组件http://apr.apache.org/ apr-1.6.5.tar.gz apr-util-1.6.1.tar.gz

Apache添加JK模块实现tomcat负载均衡

yum install -y gcc

yum install -y pcre-devel lua-devel libxml2-devel

tar apr-1.6.5.tar.gz

cd apr-1.6.5/

./configure --prefix=/usr/local/apr

make

make install

yum install expat-devel -y

tar zxf apr-util-1.6.1.tar.gz

cd apr-util-1.6.1/

./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

make

make install

组件安装完成后,安装apache

cd httpd-2.4.37/

./configure --prefix=/usr/apache24 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util

make

make install

启动apache

/usr/apache24/bin/apachectl start

/usr/apache24/bin/apachectl stop

/usr/apache24/bin/apachectl start

浏览器输入190.168.0.250

显示 it works! 正常

4.安装JK模块

官网下载 Apache添加JK模块实现tomcat负载均衡 Apache添加JK模块实现tomcat负载均衡

make

make install

Apache添加JK模块实现tomcat负载均衡 Apache添加JK模块实现tomcat负载均衡

mod_jk.so模块安装完成

Apache添加JK模块实现tomcat负载均衡

拷贝到/usr/apache24/modules下

cp mod_jk.so /usr/apache24/modules/

Apache添加JK模块实现tomcat负载均衡

三.创建负载均衡,测试结果

Apache添加JK模块实现tomcat负载均衡

1.创建控制文件

vim workers.properties

Apache添加JK模块实现tomcat负载均衡

worker.list=controller,tomcat1,tomcat2

#tomcat1实例配置 这里要和tomcat配置文件Service.xml的jvmRoute保持一致

worker.tomcat1.host=127.0.0.1

worker.tomcat1.port=7009

worker.tomcat1.type=ajp13

#分发权重 值越大负载越大

worker.tomcat1.lbfactor=1

#tomcat2实例配置

worker.tomcat2.host=127.0.0.1

worker.tomcat2.port=8009

worker.tomcat2.type=ajp13

#分发权重 值越大负载越大

worker.tomcat2.lbfactor=1

#负载均衡分发控制器

worker.controller.type=lb

worker.controller.balance_workers=tomcat1,tomcat2

worker.controller.sticky_session=false

2.创建JK配置文件

vim mod_jk.conf

Apache添加JK模块实现tomcat负载均衡

LoadModule jk_module modules/mod_jk.so

JkWorkersFile conf/workers.properties

JkMount /* controller

3.修改httpd.conf配置文件

最后一行加入引入JK配置文件

Apache添加JK模块实现tomcat负载均衡

4.启动apache服务

Apache添加JK模块实现tomcat负载均衡

5.测试

实现用apache最分发tomcat负载均衡

Apache添加JK模块实现tomcat负载均衡 Apache添加JK模块实现tomcat负载均衡

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

3D打印

3D打印

[美]胡迪•利普森,梅尔芭•库曼 / 赛迪研究院专家组 / 中信出版社 / 2013-4 / 49.00元

《3D打印:从想象到现实》内容简介:你需要一把功能强大的锤子?你需要一双精致无比的鞋子?你需要给孩子准备奇异的玩具?你需要一顿精美的晚餐?只管打印出来就行了。《3D打印:从想象到现实》带你走进3D打印的世界,认识一下当下这个最酷的东西——它将从想象变成现实,并带来一场深刻的社会革命。 书中讲述了3D打印技术的突破性发展,以及3D打印技术将如何应用在学校、厨房、医院等场所的。《3D打印:从想象......一起来看看 《3D打印》 这本书的介绍吧!

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具