所用软件:1、httpd-2.2.22.tar.gz
2、tomcat-7.0.23.tar.gz
3、tomcat-connectors-1.2.30.tar.gz
4、jdk-6U21-i586.bin
安装步骤:
1、首先安装Apache
[root@localhost ~]#tar zxvf httpd-2.2.22.tar.gz
[root@localhost ~]#cd httpd-2.2.22
[root@localhost httpd-2.2.22]#./configure --prefix=/usr/local/apache-2.2.22 \
--enable-headers \
--enable-mime-magic \
--enable-proxy \
--enable-so \
--enable-rewrite \
--enable-ssl \
--enable-suexec \
--with-included-apr \
--with-mpm=prefork \
--with-ssl=/usr \
--disable-userdir \
--disable-cgid \
--disable-cgi
[root@localhost httpd-2.2.22]#make && make install
[root@localhost httpd-2.2.22]#cd ../
[root@localhost ~]#
2、安装apache-tomcat
[root@localhost ~]#tar zxvf apache-tomcat-7.0.23.tar.gz
[root@localhost ~]#mv apache-7.0.23 /usr/local/
[root@localhost ~]#ln -s /usr/local/tomcat-7.0.23 /usr/local/tomcat
3、安装JDK
[root@localhost ~]#chmod +x ./jdk-6U21-i586.bin
[root@localhost ~]#./jdk-6U21-i586.bin
Uppacking....
....
...
[root@localhost ~]#mv jdk1.6.0_21 /usr/local/
[root@localhost ~]#ln -s /usr/local/jdk1.6.0_21 /usr/local/jdk
4、修改环境变量(/etc/profile)
TOMCAT_HOME=/usr/local/tomcat
JAVA_HOME=/usr/local/jdk
JRE_HOME=$JAVA_HOME/jre
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export TOMCAT_HOME JAVA_HOME JRE_HOME CLASSPATH PATH
使环境变量立即生效
[root@localhost ~]#source /etc/profile
5、安装tomcat-connector
[root@localhost ~]#tar zxvf tomcat-connector-1.2.30.tar.gz
[root@localhost ~]#cd tomcat-connector-1.2.30/
[root@localhost tomcat-connector-1.2.30]#cd native
[root@localhost native]#./buildconf.sh
[root@localhost native]#./configure --with-apxs=/usr/local/apache-2.2.22/bin/apxs
[root@localhost native]#make && make install
[root@localhost native]#cd ../
[root@localhost ~]#
6、检查apache安装目录下modules目录有没有mod_jk.so,如果没有手动拷贝。
7、整合Apache+Tomcat
关于整合,这里有两种方法供推荐,一种是反向代理,一种是基于mod_jk的。这里说的是mod_jk来进行apache+tomcat整合。
找到apache的安装目录下的conf/extra目录(为了方便,配置文件统一放在这个目录下)
新建一个mod_jk.conf的配置文件,输入以下内容。
JkWorkersFile conf/extra/workers.properties
JkLogFile logs/mod_jk.log
JkShmFile logs/jk-runtime-status
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"
#Sample JkMounts. Replace these with the paths you would
#like to mount from your JSP server.
#syntax: JkMount ${URL_DIR}/*.jsp worker_name
JkMount /images/avatar/* worker1
JkMount /*.jsp worker1
JkMount /*.page worker1
JkMount /*.cic worker1
JkMount /*.do worker1
JkMount /*.action worker1
保存后再新建一个workers.properties文件,输入以下内容:
worker.list=worker1
worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker1.type=ajp13
worker.woker1.lbfactor=1
最后修改apache的httpd.conf文件的DocumentRoot跟tomcat保持一致,在DirectoryIndex选项添加index.jsp,index.do index.action,重启apache服务。
写一个index.jsp的测试页面:
<%
out.println("hello java");
%>
访问验证成功
这里再说一下关于反向代理来进行apache+tomcat的整合,既然是反向代理,那tomcat-connectors就不用装了,配置文件也无需更改,只需装好apache、tomcat、jdk,开启各自服务后,修改httpd.conf,在文件最后加入如下语句:
BalancerMember ajp://localhost:8009
RewriteEngine On
ProxyPreserveHost On
RewriteRule ^/$ balancer://localCluster/
RewriteRule ^/(.*)$ balancer://localCluster/$1
阅读(839) | 评论(0) | 转发(0) |