
(背景原理待补,以下仅为搭建过程记录 )
---------------------------------------------------------------------------------------------------------
1.下载地址:
APR: wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz
Apr-util wget http://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz
pcre: wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.zip
wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.tar.gz
mod_jk.conf http://www.apache.org/dist/tomcat/tomcat-connectors/jk/ (进入这个页面下载安装包)
---------------------------------------------------------------------------------------------------------
2.安装依赖包
yum install gcc zlib-devel openssl-devel gcc+ gcc-c++ opensslperl lrzsz wget
3.分别解压 tar -zxvf xxxx,之后进入各自安装包文件夹内执行安装命令
4. 安装apr
./configure --prefix=/opt/apr
make && make install
5.安装apr-util
./configure --prefix=/opt/apr-util--with-apr=/opt/apr
make && make install
6.安装pcre
./configure--prefix=/opt/pcre --with-apr=/opt/apr --with-apr-util=/opt/apr-util
make && make install
7.安装httpd2.4
./configure --prefix=/opt/apache/ --with--mpm=worker --enable-so--enable-mods-shared=all --enable-forward=shared --enable-speling=shared--enable-rewrite=shared --enable-proxy=shared --enable-proxy-ajp=shared--enable-dav=shared --enable-mod_proxy_http=shared--enable-mod_proxy_ftp=shared --enable-mod_proxy_ajp=shared--enable-mod_proxy_balancer=shared --enable-mod_proxy_connect=shared --with-apr=/opt/apr --with-apr-util=/opt/apr-util--with-pcre=/opt/pcre
make && make install
8.关闭防火墙
关闭命令:Service iptables stop
永久关闭防火墙:chkconfig iptables off
两个命令同时运行,运行完成后查看防火墙关闭状态
Service iptables status
9.关闭 selinux
vi /etc/selinux/config
#SELINUX=enforcing (前加“#”,注释掉该行)
# SELINUX=targeted(前加“#”,注释掉该行)
SELINUX=disabled(增加)
:wq!
shutdown -r now (重启系统)
10.启动apache
/opt/apache/bin/apachectl start
报错
第一个:AH00557报错解决办法
vi /etc/hosts
第二个AH0058的错解决办法:
所以要解决这个问题可以设定httpd.conf文件中的ServerName,如下:
vi /opt/apache/conf/httpd.conf
把 #ServerName **example.com:80改成下图:
重新启动后:访问http://ip出现It works!就成功了

二、配置JDK环境变量
详见安装JDK文档
三、安装Tomcat
tomcat建议使用7.0
1.解压 tomcat
2.更改名称 :mv 成tomcat1并放到 opt
3. cp -r tomcat1 tomcat2
4.vi /etc/profile 后加入
exportTOMCAT_HOME=/opt/tomcat1
5.配置tomcat中的server.xml文件信息
tomcat1内容不变,修改tomcat2内容:
vi tomcat2/conf/server.xml
/server port =8005修改为9005
/connector port=8080修改为9090
/AJP=8009修改为9009
分别修改配xml文件:
<Enginename="Catalina" defaultHost="localhost"jvmRoute="tomacat1">
<Enginename="Catalina" defaultHost="localhost"jvmRoute="tomacat2">
6.启动tomcat
./tomcat2/bin/startup.sh
7.验证修改信息
http://ip:8080 和 http://ip:9090
四、安装mod_jk.conf
1. tar -zxvftomcart-connectors-1.240-src.tar.gz
2. mv tomcatxxxxx /usr/local
3.cd /usr/local/tomcatxxx/native
4. ./configure --with-java-home=/usr/java/jdk1.6.0 --with-apxs=/opt/apache/bin/apxs
make && makeinstall
5. cp apache-2.0/mod-jk.so /opt/apache/modules
五、配置mod_jk.conf
在/opt/apache/conf 建立mod_jk.conf
---------------------------------------------------------------------------------------------------------
#加载mod_jk Module
LoadModule jk_module/opt/apache/modules/mod_jk.so
#指定workers.properties文件路径
JkWorkersFile /opt/apache/conf/workers.properties
#加载workers的请求处理分配文件
JkMountFile /opt/apache/conf/uriworkermap.properties
#指定jk的日志输出文件
JkLogFile /opt/apache/logs/mod_jk.log
#指定日志的级别
#JkLogLevel info
#指定日志的格式
#JkLogStampFormat"[%a %b %d %H:%M:%S %Y]"
#指定那些请求交给tomcat处理,"controller"为在workers.propertise里指定的负载分配控制器名
JkMount /* controller
JkMount /*.jsp controller
JkMount /*.action controller
JkMount /*.do controller
---------------------------------------------------------------------------------------------------------
六、配置workers.properties文件
在/opt/apache/conf 建立workers.properties
---------------------------------------------------------------------------------------------------------
#server列表
worker.list=controller,tomcat1,tomcat2
#=============tomcat1==========
worker.tomcat1.port=8009
#ajp13端口号,server.xml配置
worker.tomcat1.host=localhost
#tomcat的主机地址
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor=1
#server的加权比重,值越高,分得请求越多
#==========tomcat2==============
worker.tomcat2.port=9009
#ajp13端口号,server.xml配置
worker.tomcat2.host=localhost
#tomcat的主机地址
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor=1
#server的加权比重,值越高,分得请求越多
#======controller==============
worker.controller.type=lb
worker.retries=3
#重复次数
worker.controller.balance_workers=tomcat1,tomcat2
#worker.controller.sticky_session=1
---------------------------------------------------------------------------------------------------------
七、配置uriworkermap.properties
在/opt/apache/conf 建立
---------------------------------------------------------------------------------------------------------
/*=controller
/jkstatus=status
!/*.gif=controller
!/*.jpg=controller
!/*.css=controller
!/*.js=controller
!/*.htm=controller
!/*.html=controller
---------------------------------------------------------------------------------------------------------
八、修改httpd.conf文件
在文件的最后插入:
Include /opt/apache/conf/mod_jk.conf
九、验证负载均衡是否成功:
1、在/opt/tomcat1/webapps/test新建test.jsp以下代码
<%@pagecontentType="text/html;charset=utf-8"%>
<html>
<head>
<title>Tomcat1 test1</title>
</head>
<body>
<font color ="red" size="20">
<%out.print("恭喜成功安装启动Tomcat1");%>
</font>
</body>
</html>
2、在/opt/tomcat1/webapps/test新建test.jsp以下代码
<%@pagecontentType="text/html;charset=utf-8"%>
<html>
<head>
<title>Tomcat1 test2</title>
</head>
<body>
<font color ="red" size="20">
<%out.print("恭喜成功安装启动Tomcat2");%>
</font>
</body>
</html>
3、访问http://192.168.0.98/test/test.jsp,多次强制,应该会访问到不同的tomcat
4.ok got it……O(∩_∩)O~