APACHE与TOMCAT简单整合过程
环境:centos6.4 apache2.2 tomcat6.0 jdk1.6 jk
(关闭防火墙与selinux )//service iptables stop //setenforce 0
步骤:
① 安装apache
② 按照JDK //tomcat需要用的java
③ 安装tomcat
④ 安装apache与tomcat连接的模块
⑤ 测试
一.apache的安装
搭建yum本地源
yum install -y httpd
yum install -y httpd-devel
配置文件 /etc/httpd/conf/httpd.conf
网页位置 /var/www/html/
vi /var/www/html/index.html
html 192.168.10.3
service httpd start
测试浏览器访问//ip
二.安装jdk
chmod +x jdk-6u18-ea-bin-b01-linux-i586-20_aug_2009.bin
./jdk-6u18-ea-bin-b01-linux-i586-20_aug_2009.bin
//协议说明 回车 输入yes 按回车 Done
mv jdk1.6.0_18/ /usr/local/jdk1.6
配置java环境变量
vi /etc/profile
//在最末尾添加
JAVA_HOME=/usr/local/jdk1.6
PATH=$PATH:$JAVA_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib
TOMCAT_HOME=/usr/local/tomcat6.0
export JAVA_HOME PATH CLASSPATH TOMCAT_HOME
source /etc/profile //重载配置
测试
java -version
---------------------------------------------
出现如下:
java version "1.7.0_09-icedtea"
OpenJDK Runtime Environment (rhel-2.3.4.1.el6_3-i386)
OpenJDK Client VM (build 23.2-b09, mixed mode)
-----------------------------------------------
三.安装tomcat
tar -zxvf apache-tomcat-6.0.37.tar.gz
mv apache-tomcat-6.0.37 /usr/local/tomcat6.0
配置环境变量
vi /etc/profile
//在最末尾添加
TOMCAT_HOME=/usr/local/tomcat6.0
CATALINA_HOME=/usr/local/tomcat6.0
CATLINA_BASE=/usr/local/tomcat6.0
export TOMCAT_HOME CATALINA_HOME CATALINA_BASH
source /etc/profile //重载配置
测试
echo $JAVA_HOME
echo $TOMCAT_HOME
echo $CLASSPATH
echo $PATH
--------------------//确保如下包含/usr/local/jdk1.6/bin
/usr/lib/qt-
3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/jdk1.6
/bin
--------------------
java -version
cd /usr/local/tomcat6.0/bin/
./startup.sh
netstat -ntl |grep 8080
tcp 0 0 :::8080 :::* LISTEN
测试浏览器访问//ip:8080
四.apache与tomcat连接方式
#JK
安装 tomcat-connectors-1.2.26-src.tar.gz
tar -zxvf tomcat-connectors-1.2.26-src.tar.gz
cd tomcat-connectors-1.2.26-src
cd native
./buildconf.sh
./configure --with-apxs=/usr/sbin/apxs
make
生产mod_jk.so
cp /native/apache-2.0/mod_jk.so /modules
vi httpd.conf
//在modules处添加
LoadModule jk_module modules/mod_jk.so
Include /etc/httpd/conf/mod_jk.conf
cd /var/www/html
vi index.jsp
cd /etc/httpd/conf
vi workers.properties
worker.list=worker1
worker.workerx.type=ajp12
worker.workerx.host=localhost
worker.workerx.port=8009
worker.workerx.lbfactor=50
worker.workerx.cachesize=10
worker.workerx.cache_timeout=600
worker.workerx.socket_keepalive=1
worker.workerx.socket_timeout=300
cd /etc/httpd/conf
vi mod_jk.conf
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
JkRequestLogFormat "%w %V %T"
JkMount /servlet/* worker1
JkMount /*.jsp worker1
vi httpd.conf
DirectoryIndex index.html index.html.var index.jsp
cd /usr/local/tomcat6.0/conf/
vi server.xml
//HOST段中添加 //注意路径
crossContext="true"/>
五.测试
cd /usr/local/tomcat6.0/bin/
./startup.sh
service httpd restart
修改httpd.conf
vi /etc/httpd/conf/httpd.conf //将index.jsp改在前面即可
测试效果如图://不需要输入后面的端口8080
整合完成!!