Linux下安装与配置tomcat集群+负载均衡

一、Apache HTTP Server 的安装与简单配置

1、到官网下载 Apache HTTP Server,我下载的是 httpd-2.2.26.tar.gz

2、创建安装目录:mkdir /usr/local/apache2/

3、解压下载的压缩包,解压后为 httpd-2.2.26:tar -xvf httpd-2.2.26.tar.gz

4、切换到源码目录:cd httpd-2.2.26

5、配置安装路径等:

   ./configure --prefix=/usr/local/apache2/ --enable-shared=max/ --enable-module=rewrite/ --enable-module=so

6、编译源文件:make

7、安装:make install

8、至此Apache HTTP Server 的安装已经完成,可以通过/usr/local/apache2/bin/apachectl start 启动Apache服务,然后在浏览器中访问 http://ip地址 进行测试,如果出现“It works!”或Apache图标的漂亮界面,说明Apache安装成功!

9、制作Apache启动项:

a、复制Apache启动脚本:cp /bin/apachectl /etc/rc.d/init.d/apache

b、编辑Apache启动脚本:vi /etc/rc.d/init.d/apache ,在开头#!/bin/sh下添加一下内容:#chkconfig:2345 85 15

c、保存退出后添加apache服务:chkconfig --add apache

d、查看linux 80 端口是否关闭:netstat -an | grep :80 ,如果未关闭则将其关闭或重启linux。

e、查看是否存在linux自带httpd服务:ps -aux | grep httpd ,存在的话将其关闭,否则导致新添加的apache服务启动失败。

f、关闭上述第8步启动的apache服务(如果已启动),通过 service apache start(stop、restart)来启动(关闭、重启)apache服务。启动后,通过浏览器访问 http://linuxIP地址,如果出现“It works!”或Apache图标的漂亮界面,说明Apache启动项制作成功!

二、编译生成mod_jk.so

mod_jk是Tomcat集群时三种负载均衡中的一种,该种方式apache会自动检测到停止的tomcat,然后不再发请求过去。缺点是,当停止掉的tomcat服务器再次启动的时候,如果apache检测不到,仍然不会转发请求过去。

1、到官网下载对应版本的tomcat-connectors,我这里下载的是tomcat-connectors-1.2.37-src.tar.gz。

2、解压tomcat-connectors-1.2.37-src.tar.gz:tar -xvf tomcat-connectors-1.2.37-src.tar.gz

3、切换到native目录:cd tomcat-connectors-1.2.37-src/native/

4、配置源文件:./configure --with-apxs=/usr/local/apache2/bin/apxs

5、编译源文件:make

6、生成mod_jk.so文件:make install

生成过程结果后,cd /usr/local/apache2/modules/ 是不是mod_jk.so文件已经在这了!

三、Tomcat负载均衡+集群配置






原文地址:https://www.cnblogs.com/yjtx/p/4429615.html