系统环境:Windows Server 2008 R2 SP1
虚拟机软件:Hyper-V管理器 6.1.7601.17514
虚拟机环境:Red Hat Enterprise Linux Server release 5.4 (Tikanga) X64
安装软件版本:JDK:1.6.0_19 Tomcat:6.0.20 Apache:2.2.19 JK: 1.2.10
实施步骤:
一、安装软件。。。
1 tar -xzvf jdk1.6.0_19.tar.gz
2 tar xvfz tomcat.tar.gz
3 tar zxvf httpd-2.2.19.tar.gz
4 cd httpd-2.2.19
5 ./configure --prefix=/usr/local/apache2 --enable-so --enable-mods-shared=most --with-mpm=worker
6 make
7 make install
8 tar zxvf jakarta-tomcat-connectors-1.2.10-src.tar.gz
9 cd jakarta-tomcat-connectors-1.2.10-src/jk/native/
10 ./buildconf.sh
11 ./configure --with-apxs=/usr/local/apache2/bin/apxs
12 make
13 make install
二、配置整合及负载均衡
1 cp /usr/local/jakarta-tomcat-connectors-1.2.10-src/jk/native/apache-2.0/mod_jk.so /usr/local/apache2/modules
2 配置环境变量
vi /etc/profile
在文本末尾加入以下内容
JAVA_HOME=JDK安装路径
CATALINA_HOME=tomcat安装路径
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$CATALINA_HOME/lib/servlet-api.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CATALINA_HOME CLASSPATH PATH
3 应用初始的环境变量
source /etc/profile
4 修改apache的httpd.conf
vi /usr/local/apache2/conf/httpd.conf
修改以下几处
并且在末尾加上:Include /usr/local/apache2/conf/mod_jk.conf
5 添加及设置mod_jk.conf
vi /usr/local/apache2/mod_jk.conf
增加以下内容
#加载mod_jk Module
LoadModule jk_module modules/mod_jk.so
#指定 workers.properties文件路径
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel info
#指定那些请求交给tomcat处理,"controller"为在workers.propertise里指定的负载分配控制制器
JkMount /* lb
6 添加及设置workers.properties
vi /usr/local/apache2/conf/workers.properties
添加以下内容
worker.list = lb,tomcat1,tomcat2
#server 列表
#========tomcat1========
worker.tomcat1.port=8009
#ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat1.host=10.1.1.2
#tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor = 1
#server的加权比重,值越高,分得的请求越多
#========tomcat2========
worker.tomcat2.port=8009
#ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat2.host=10.1.1.3
#tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor = 1
#server的加权比重,值越高,分得的请求越多
#========controller,负载均衡控制器========
worker.lb.type=lb
worker.lb.balanced_workers=tomcat1,tomcat2
#指定分担请求的tomcat
worker.lb.sticky_session=1
7、将JSP文件放入/usr/local/tomcat/webapps/ROOT
8 启动apache和tomcat
8 打开浏览器输入 http://apache服务器的地址或者localhost/index.jsp
就是这么简单。
三、将apache和tomcat加入启动和系统服务选项
1 Apache加入启动项里面:
echo /usr/local/apache2/bin/apachectl start >> /etc/rc.local
2 Apache加入到系统服务里面:
cp /安装目录下/apache/bin/apachectl /etc/rc.d/init.d/httpd
修改httpd
在文件头部加入如下内容:
###
# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 90 90
# description:http server
###
保存
在打入
chkconfig --add httpd
chkconfig --level 345 httpd on
3 tomcat加入启动和系统服务选项
安装jsvc
#cd /usr/local/tomcat/bin
#tar xvfz jsvc.tar.gz
#cd jsvc-src
#sh support/buildconf.sh
#chmod 755 configure
#./configure --with-java=/usr/local/java (改成你的JDK的位置)
#make
注:我在執行./configure --with-java=/usr/local/java 的過程中,產生"configure: error:no acceptable C compiler found in $PATH "這樣的錯誤提示,發現是沒有安裝C編譯器,于是執行“yum install gcc”安裝了gcc,之后重新執行./configure --with-java=/usr/local/java 就Ok了
修改启动文件
#vi ./native/Tomcat5.sh
改成如下内容:
#!/bin/sh
# chkconfig: 345 87 13
# description: Tomcat Daemon
# processname: jsvc
# pidfile: /var/run/jsvc.pid
# config:
# Source function library.
# . /etc/rc.d/init.d/functions
# prog=tomcat
# Small shell script to show how to start/stop Tomcat using jsvc
# If you want to have Tomcat running on port 80 please modify the server.xml
# file:
# port="80" minProcessors="5" maxProcessors="75"
# enableLookups="true" redirectPort="8443"
# acceptCount="10" debug="0" connectionTimeout="60000"/>
# You need a developement version of Tomcat (Apache Tomcat/4.1-dev)
# Adapt the following lines to your configuration
##############################################################################
#
# Copyright 2004 The Apache Software Foundation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##############################################################################
#
# Small shell script to show how to start/stop Tomcat using jsvc
# If you want to have Tomcat running on port 80 please modify the server.xml
# file:
#
# <!-- Define a non-SSL HTTP/1.1 Connector on port 80 -->
# <Connector className="org.apache.catalina.connector.http.HttpConnector"
# port="80" minProcessors="5" maxProcessors="75"
# enableLookups="true" redirectPort="8443"
# acceptCount="10" debug="0" connectionTimeout="60000"/>
#
# That is for Tomcat-5.0.x (Apache Tomcat/5.0)
#
# Adapt the following lines to your configuration
JAVA_HOME=/usr/local/jdk
CATALINA_HOME=/usr/local/tomcat
DAEMON_HOME=/usr/local/tomcat/bin
TOMCAT_USER=root
# for multi instances adapt those lines.
TMP_DIR=/var/tmp
PID_FILE=/var/run/jsvc.pid
CATALINA_BASE=/usr/local/tomcat
CATALINA_OPTS=
CLASSPATH=
$JAVA_HOME/lib/tools.jar:
$CATALINA_HOME/bin/commons-daemon.jar:
$CATALINA_HOME/bin/bootstrap.jar
case "$1" in
start)
#
# Start Tomcat
#
$DAEMON_HOME/jsvc-src/jsvc
-user $TOMCAT_USER
-home $JAVA_HOME
-Dcatalina.home=$CATALINA_HOME
-Dcatalina.base=$CATALINA_BASE
-Djava.io.tmpdir=$TMP_DIR
-wait 10
-pidfile $PID_FILE
-outfile $CATALINA_HOME/logs/catalina.out
-errfile &1
$CATALINA_OPTS
-cp $CLASSPATH
org.apache.catalina.startup.Bootstrap
#
# To get a verbose JVM
#-verbose
# To get a debug of jsvc.
#-debug
exit $?
;;
stop)
#
# Stop Tomcat
#
$DAEMON_HOME/jsvc-src/jsvc
-stop
-pidfile $PID_FILE
org.apache.catalina.startup.Bootstrap
exit $?
;;
*)
echo "Usage tomcat.sh start/stop"
exit 1;;
esac
拷贝启动文件
#cp ./native/Tomcat5.sh /etc/init.d/tomcat5
#chmod -c 777 /etc/init.d/tomcat5
添加服务
#chkconfig --add tomcat5
#chkconfig --level 345 tomcat5 on
完成,启动服务
#service tomcat5 start
这时重启系统,tomcat也就会自动启动了