日期:2014-05-16  浏览次数:20784 次

linux下tomcat

?????????????????????????????? linux下tomcat集群配置案例
配置前的准备工作
在配置集群应用前要对集群的配置信息有一个良好的设计,下面就是我们这次配置的集群信息:
在同一网段内的不同机器上配置集群,以下是以2台机器做群集,
机器类型 操作系统 硬件配置 角色 备注
普通PC Linux as 4 IP:10.3.15.85 PORT:9080 Managed Server Pc1
普通PC Linux as 4 IP: 10.3.15.84 PORT:9080 Managed Server Pc2
普通PC Linux as 4 IP: 10.3.15.85 PORT:80 Balancer Server Pc1

1 操作系统
RedHat Linux as4
2 所需软件
Apache 2.0.54? 下载地址
http://apache.freelamp.com/httpd/httpd-2.0.54.tar.gz
Tomcat5.5.9??? 下载地址
http://apache.justdn.org/jakarta/tomcat-5/v5.5.9/bin/jakarta-tomcat-5.5.9.tar.gz
Mod_jk 1.2.14? 下载地址
http://apache.justdn.org/jakarta/tomcat-connectors/jk/source/jk-1.2.14/jakarta-tomcat-connectors-1.2.14-src.tar.gz
Jdk 1_5_0_04?? 下载地址
http://java.sun.com/j2se/1.5.0/download.jsp
备注:下载时将所需软件包文件保存在/usr/local目录下,也可以采用jdk1.4
3 安装步骤
3.1 安装JDK
# cd /usr/local/
# chmod 777 jdk-1_5_0_04-linux-i586-rpm.bin
# ./jdk-1.5.0_04-linux-i586-rpm.bin
# cd /usr/java/
# ln -s /usr/java/jdk-1_5_0_04 /usr/local/java
# vi /etc/profile
#添加如下内容
JAVA_HOME=/usr/local/java/
CLASSPATH=/usr/local/java/lib/dt.jar:/usr/local/java/lib/tools.jar
PATH=/usr/local/java/bin:$PATH
export PATH JAVA_HOME CLASSPATH

3.2 安装Apache
# cd /usr/local/
# tar xvfz httpd-2.0.54.tar.gz
# cd httpd-2.0.54
#./configure—prefix=/usr/local/apache—enable-module=so
# make
# make install
# cd /usr/local/apache/conf
# vi ./httpd.conf
将Listen 80修改为Listen <Your IP>:80
将ServerName修改为ServerName <HOST-NAME>:80
在DirectoryIndex中添加index.jsp
# cd /usr/local/apache/bin/
# ./apachectl configtest
若显示Syntax ok则表明安装成功
#./apachectl start
启动apache服务,访问本机80端口,查看端口是否正常
# ./apachectl stop
关闭服务
备注:prefix定义apache的安装路径

3.3 安装Tomcat
# cd /usr/local/
# tar xvfz jakarta-tomcat-5.5.9.tar.gz
# ln –s /usr/local/jakarta-tomcat-5.5.9 /usr/local/tomcat
# vi /usr/local/tomcat/bin/catalina.sh
JAVA_HOME=/usr/local/java
启动服务后,访问本机8080端口,查看端口是否正常
# /usr/local/tomcat/bin/startup.sh /startup.bat
关闭服务
# /usr/local/tomcat/bin/shutdown.sh /shutdown.bat
3.4 安装JK
#cd /usr/local/
# tar xzvf jakarta-tomcat-connectors-1.2.14-src.tar.gz
#cd jakarta-tomcat-connectors-1.2.14-src/jk/native
#chmod 755 buildconf.sh
#./buildconf.sh
#./configure—with-apxs=/usr/local/apache/bin/apxs
#make
#make install
#cd /usr/local/ jakarta-tomcat-connectors- jk1.2.14-src/jk/native/apache-2.0/
#cp mod_jk.so /usr/local/apache/modules/

4 系统整合
4.1 在文件最末尾加上如下语句
#vi /usr/local/apache/conf/httpd.conf

# Load mod_jk
LoadModule jk_module modules/mod_jk.so
# Configure mod_jk
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel info
JkMount /*.jsp loadbalancer
JkMount /servlet/* loadbalancer
JkMount /application/* loadbalancer

4.2 添加workers.properties
#vi /usr/local/apache/conf/workers.properties
内容如下:

worker.list=loadbalancer
#Define a ‘local_worker’ worker using ajp13
worker.worker1.port=8009
worker.worker1.host=10.3.15.84
worker.worker1.type=ajp13
worker.worker1.lbfactor=1
worker.worker1.local_worker=0
worker.worker1.cachesize=1000
worker.worker1.cache_timeout=600
worker.worker1.socket_keepalive=1
worker.worker1.socket_timeout=0
worker.worker1.reclycle_timeout=300
worker.worker1.retries=3

#Define another ‘local_worker’ worker using ajp13
worker.worker2.port=8009
worker.worker2.host=10.3.15.85
worker.worker2.type=ajp13
worker.worker2.lbfactor=1
worker.worker2.local_worker=1
worker.worker2.cachesize=1000
worker.worker2.cache_timeout=600
worker.worker2.socket_keepalive=1
worker.worker2.socket_timeout=0
worker.worker1.reclycle_timeout=300
worker.worker1.retries=3

#Define the LB worke