Linux下jsp环境:apache,tomcat配置
2024-09-05 00:20:04
供稿:网友
linux下jsp开发环境,apache,tomcat服务器配置过程:
(特别注明:本文内容均参考于互联网,经过个人实践而总结,若配置中遇到问题请联系我,可能写的时候漏掉了某些地方,感谢网上前辈的经验,希望更多的实践经验得以共享)
1.操作系统
redhat linux 9.0
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
下载该文件jdk-1_5_0_04-linux-i586-rpm.bin
下载时将所需软件包文件保存在/usr/local目录下
3.安装步骤
a 安装jdk
# cd /usr/local/
# chmod +x 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/java/jdk-1_5_0_04
classpath=/usr/java/jdk-1_5_0_04/lib/dt.jar:/usr/java/jdk-1_5_0_04/lib/tools.jar
path=/usr/java/jdk-1_5_0_04/bin:$path
export path java_home classpath
b 安装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 127.0.0.1:80 (219行)
将servername 修改为servername localhost:80 (291行)
在directoryindex中添加 index.jsp (394行)
# cd /usr/local/apache/bin/
# ./apachectl configtest
显示syntax ok则表明安装成功
#./apachectl start
启动apache服务,浏览器中访问本机80端口,查看端口是否正常,输入127.0.0.1:80
# ./apachectl stop
关闭服务
备注:prefix定义apache的安装路径
c安装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
第46行加入此句
java_home=/usr/java/jdk-1_5_0_04
启动服务后,访问本机8080端口,查看端口是否正常(输入127.0.0.1:8080)
# /usr/local/tomcat/bin/startup.sh /startup.bat
关闭服务
# /usr/local/tomcat/bin/shutdown.sh /shutdown.bat
d 安装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/
e 系统整合
# 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
#vi /usr/local/apache/conf/workers.properties
添加下列语句
#
# workers.properties
#
# in unix, we use forward slashes:
ps=/
# list the workers by name
worker.list=tomcat1, tomcat2, loadbalancer
# ------------------------
# first tomcat server
# ------------------------
worker.tomcat1.port=8009
worker.tomcat1.host=127.0.0.1
worker.tomcat1.type=ajp13
# specify the size of the open connection cache.
#worker.tomcat1.cachesize
#
# specifies the load balance factor when used with
# a load balancing worker.
# note:
# ----> lbfactor must be > 0
# ----> low lbfactor means less work done by the worker.
worker.tomcat1.lbfactor=100
# ------------------------
# second tomcat server
# ------------------------
worker.tomcat2.port=8009
worker.tomcat2.host=192.168.1.34
worker.tomcat2.type=ajp13
# specify the size of the open connection cache.
#worker.tomcat2.cachesize
#
# specifies the load balance factor when used with
# a load balancing worker.
# note:
# ----> lbfactor must be > 0
# ----> low lbfactor means less work done by the worker.
worker.tomcat2.lbfactor=100
# ------------------------
# load balancer worker
# ------------------------
# the loadbalancer (type lb) worker performs weighted round-robin
# load balancing with sticky sessions.
# note:
# ----> if a worker dies, the load balancer will check its state
# once in a while. until then all work is redirected to peer
# worker.
worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=tomcat1, tomcat2
#
# end workers.properties
#
#vi /usr/local/tomcat/conf/server.xml
<connector port="8009"
protocolhandlerclassname="org.apache.jk.server.jkcoyotehandler"
redirectport="8443" protocol="ajp/1.3" /> 第101行
在119行左右加入如下语句(去注释)
<engine name="standalone" defaulthost="localhost" jvmroute="tomcat1"></engine>
若第二台tomcat,将jvmroute的修改为tomcat2
系统整合完毕
启动apache和tomcat服务
# /usr/local/apache/bin/apachectl start
# /usr/local/tomcat/bin/catalina.sh start
将如下内容添加至/etc/rc.d/rc.local文件末尾
以便系统启动后开启apache,tomcat服务
#vi /etc/rc.d/rc.local
添加
/usr/local/tomcat/bin/catalina.sh start
/usr/local/apache/bin/apachectl start