Chinaunix首页 | 论坛 | 博客
  • 博客访问: 729113
  • 博文数量: 245
  • 博客积分: 10037
  • 博客等级: 上将
  • 技术积分: 2512
  • 用 户 组: 普通用户
  • 注册时间: 2007-01-16 17:16
文章分类

全部博文(245)

文章存档

2008年(7)

2007年(238)

我的朋友

分类: LINUX

2007-04-11 12:30:05

整合Apache+Tomcat
下载到/tmp: httpd-2.0.50.tar.gz
            jakarta-tomcat-5.0.27.tar.gz
            jakarta-tomcat-connectors-jk2-src-current.tar.gz
            j2sdk-1_4_2_05-linux-i586.bin             
#cd /usr/local
#mkdir apache2
#cp /tmp/httpd-2.0.50.tar.gz /usr/local/apache2
#cd apache2
#tar xvf httpd-2.0.50.tar.gz
#cd httpd-2.0.50
#./configure --with-layout=Apache2  --prefix=/usr/local/apache2  --enable-so
#make 
#make install
.修改apache的http.conf
  ServerName  name OfYourServer
  Group  nogroup(要增加这个组) 
# cd /usr/local/apache2/bin
#./apachectl start 启动apache (./apachectl stop 停止)
 如果成功,通过浏览器就可以看到Apche的默认主页了
(httpd –l 可以列出已经加载的模块)
安装JDK
#cd /usr/local
#mkdir java
#cp /tmp/j2sdk-1_4_2_05-linux-i586.bin /usr/local/java
#cd java
#sh j2sdk-1_4_2_05-linux-i586.bin
#pico /root/.bash_profile
把原来内容改为
JAVA_HOME=/usr/local/java/j2sdk1.4.2_05
CALSSPATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib
PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOME/bin
BASH_ENV=$HOME/.bashrc
USERNAME="root"
export USERNAME BASH_ENV JAVA_HOME CLASSPATH PATH 
有了这两个变量,Tomcat才能安装.
#cp /tmp/jakarta-tomcat-5.0.27.tar.gz /usr/local/
#cd /usr/local/
#tar zxvf jakarta-tomcat-5.0.27.tar.gz
#pico /root/.bash_profile
把原来内容改为
JAVA_HOME=/usr/local/java/j2sdk1.4.2_05
CALSSPATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib
PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOME/bin
CATALINA_HOME=/usr/local/jakarta-tomcat-5.0.27
CATALINA_BASE=/usr/local/jakarta-tomcat-5.0.27
BASH_ENV=$HOME/.bashrc
USERNAME="root"          
            
export USERNAME BASH_ENV JAVA_HOME CLASSPATH CATALINA_HOME CATALINA_BASE PATH
#cd /usr/local/tomcat/bin
#./startup.sh 启动tomcat
# cd /usr/local/apache2/bin
#./apachectl restart
通过浏览器 看到了一只猫!(port 8080 是Tomcat的默认端口)
安装connector JK2
如果以上安装顺利的话,继续安装connector吧
#cp /tmp/jakarta-tomcat-connectors-jk2-src-current.tar.gz
#cd /usr/local
#tar zxvf jakarta-tomcat-connectors-jk2-src-current.tar.gz 
#cd jakarta-tomcat-connectors-jk2-2.0.4-src/jk/native2
#./buildconf.sh
#./configure&--with-apxs2=/usr/local/apache2/bin/apxs&
make 
make install  (如果不成功,把mod_jk2.so&拷贝到Apache得modules下)
#cp jk/build/jk2/apache2/mod_jk2.so /usr/local/apache2/modules
还有一个jkjni.so&,说是用来启动Apache 时自动启动Tomcat的,如果就也拷贝吧.我没有看到!
 #cp jk/build/jk2/apache2/jkjni.so /usr/local/apache2/modules
整合步入正题了,整合涉及到了4个配置文件
Apache 的 httpd.conf  和 workers2.properties (创建)
Tomcat 的 server.xml 和 jk2.properties  (不过这两个文件,我没改过也成功了)
httpd.conf 
在Apache中添加mod_jk2.so模块:
LoadModule jk2_module modules/mod_jk2.so  
workers2.properties:
这是我的workers2.properties
# Example socket channel, override port and host
   [channel.socket:localhost:8009] 
        port=8009 
        host=127.0.0.1
# define the worker
   [ajp13:localhost:8009] 
        channel=channel.socket:localhost:8009
# Uri mapping
   [uri:/jsp-examples/*] 
        worker=ajp13:localhost:8009
好了,重启Apache和Tomcat
如果看到的效果和 一样就说明整合成功.
开机时自动启动http和tomcat
#cd /etc/init.d
#touch httpd
#pico httpd
以下为内容
#!/bin/bash
#
# Startup script for the Apache Web Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server.  It is used to serve \
#        HTML files and CGI.
# processname: httpd
# pidfile: /var/run/httpd.pid
# config: /etc/httpd/conf/httpd.conf
LD_LIBRARY_PATH=/usr/local/java/j2sdk1.4.2_05/jre/lib/i386:/usr/local/java/j2sdk1.4.2_05/jre/lib/i386/server
export LD_LIBRARY_PATH
CATALINA_BASE=/usr/local/jakarta-tomcat-5.0.27
export CATALINA_BASE
CATALINA_HOME=/usr/local/jakarta-tomcat-5.0.27
export CATALINA_HOME
APACHE_HOME=/usr/local/apache2
export APACHE_HOME
JAVA_HOME=/usr/local/java/j2sdk1.4.2_05
export JAVA_HOME
PROFILEDIR=/var/run

case "$1" in
start)
if [ -f $PROFILEDIR/Tomcat5_Apache2 ]; then
echo "Running Tomcat5_Apache2"
else
if [ -f $CATALINA_HOME/bin/startup.sh ]; then
if [ -f $APACHE_HOME/bin/apachectl ]; then
# "$CATALINA_HOME/bin/startup.sh"
$CATALINA_HOME/bin/startup.sh start
echo "Startting Tomcat5"
# $CATALINA_HOME/bin/startup.sh start
sleep 3
echo "Startting Apache2"
$APACHE_HOME/bin/apachectl start
# echo "."
touch $PROFILEDIR/Tomcat5_Apache2
else
echo "Apache File Not Founds"
fi
else
echo "Tomcat File Not Founds"
fi
fi
;;
stop)
if [ -f $PROFILEDIR/Tomcat5_Apache2 ]; then
if [ -f $CATALINA_HOME/bin/shutdown.sh ]; then
if [ -f $APACHE_HOME/bin/apachectl ]; then
"$CATALINA_HOME/bin/shutdown.sh"
echo "Stopping Tomcat5"
sleep 3
echo "Stopping Apache2"
$APACHE_HOME/bin/apachectl stop
rm $PROFILEDIR/Tomcat5_Apache2
else
echo "Apache File Not Founds"
fi
else
echo "Tomcat File Not Founds"
fi
else
echo "Not Running Tomcat5_Apache2"
fi
;;
*)
echo "Usage; `basename $0` {start|stop}" 1>&2
exit 1
;;
esac
exit 0
保存退出
#chmod 755 httpd
#chkconfig --add httpd
#ntsysv
把httpd那项选上
重启linux OK!
阅读(2165) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~