码迷,mamicode.com
首页 > Web开发 > 详细

apache+tomcat+jdk安装配置

时间:2014-10-27 06:59:26      阅读:336      评论:0      收藏:0      [点我收藏+]

标签:tomcat jdk apache

一、安装JDK1.6.

[root@localhost ~]# chmod +x jdk-6u30-linux-x64-rpm.bin 
[root@localhost ~]# ./jdk-6u30-linux-x64-rpm.bin
[root@localhost ~]# echo "export JAVA_HOME=/usr/java/default" > /etc/profile.d/java.sh
[root@localhost ~]# . /etc/profile.d/java.sh

二、安装Tomcat。

[root@localhost ~]# tar xf apache-tomcat-7.0.40.tar.gz -C /usr/local
[root@localhost local]# ln -sv apache-tomcat-7.0.40 tomcat
[root@localhost ~]# vim /etc/profile.d/tomcat.sh
export CATALINA_HOME=/usr/local/tomcat
export PATH=$PATH:$CATALINA_HOME/bin
[root@localhost ~]# . /etc/profile.d/tomcat.sh 
[root@localhost ~]# catalina.sh version  #查看版本信息
[root@localhost ~]# vim /usr/local/tomcat/conf/server.xml    #添加测试路径
    <Engine name="Catalina" defaultHost="www.liangshaoqin.com" jvmRoute="TomcatA">
    <Host name="www.liangshaoqin.com"  appBase="/web"
            unpackWARs="true" autoDeploy="true">
            <Context path="" docBase="webapps" reLoadable="true" />
      </Host>
[root@localhost ~]# catalina.sh configtest  #检查配置文件语法错误
[root@localhost ~]# mkdir /web/webapps -pv
[root@localhost ~]# vim /web/webapps/index.jsp   #编写测试页面
<%@ page language="java" %>
<html>
  <head><title>TomcatA</title></head>
  <body>
    <h1><font color="red">TomcatA </font></h1>
    <table align="centre" border="1">
      <tr>
        <td>Session ID</td>
    <% session.setAttribute("abc","abc"); %>
        <td><%= session.getId() %></td>
      </tr>
      <tr>
        <td>Created on</td>
        <td><%= session.getCreationTime() %></td>
     </tr>
    </table>
  </body>
</html>
[root@localhost ~]# catalina.sh start  #启动tomcat服务,客户端通过8080访问测试

三、安装apache,先安装apr和apr-util,此处略过。

[root@localhost ~]# yum -y install pcre-devel
[root@localhost ~]# yum -y install openssl-devel
[root@localhost ~]# tar -zxvf httpd-2.4.10.tar.gz 
[root@localhost ~]# cd httpd-2.4.10
[root@localhost httpd-2.4.10]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-mpms-shared=all --with-mpm=event --enable-proxy --enable-proxy-http --enable-proxy-ajp --enable-proxy-balancer  --enable-lbmethod-heartbeat --enable-heartbeat --enable-slotmem-shm  --enable-slotmem-plain --enable-watchdog
[root@localhost httpd-2.4.10]# make && make install
[root@localhost ~]# vim /etc/init.d/httpd  #为apache提供init脚本,略……
1、配置apache通过mod_proxy模块与Tomcat连接

要使用mod_proxy与Tomcat实例连接,需要apache已经装载mod_proxy、mod_proxy_http、mod_proxy_ajp
和proxy_balancer_module(实现Tomcat集群时用到)等模块:

# /usr/local/apache/bin/httpd -D DUMP_MODULES | grep  proxy
 proxy_module (shared)
 proxy_connect_module (shared)
 proxy_ftp_module (shared)
 proxy_http_module (shared)
 proxy_fcgi_module (shared)
 proxy_scgi_module (shared)
 proxy_ajp_module (shared)
 proxy_balancer_module (shared)
 proxy_express_module (shared)
 
2、在httpd.conf的全局配置段或虚拟主机中添加如下内容:
ProxyVia Off
ProxyRequests Off
ProxyPreserveHost Off
<Proxy *>
  Require all granted
</Proxy>
  ProxyPass  /  ajp://172.16.100.1:8009/
  ProxyPassReverse  /  ajp://172.16.100.1:8009/
<Location  / >
  Require all granted
</Location>

或让apache跟Tomcat的http连接器进行整合:
ProxyVia Off
ProxyRequests Off
ProxyPass / http://172.16.100.1:8080/
ProxyPassReverse / http://172.16.100.1:8080/
<Proxy *>
  Require all granted
</Proxy>
<Location  / >
  Require all granted
</Location>
[root@localhost ~]# vim /etc/httpd/httpd.conf
PidFile "/var/run/httpd.pid"
#DocumentRoot "/usr/local/apache/htdocs"   #注释此行
Include /etc/httpd/extra/httpd-proxy.conf
LoadModule slotmem_shm_module modules/mod_slotmem_shm.so  #取消这两行注释
LoadModule slotmem_plain_module modules/mod_slotmem_plain.so
[root@localhost ~]# vim /etc/httpd/extra/httpd-proxy.conf
<VirtualHost *:80>
        ProxyVia Off
        ProxyRequests Off
        ProxyPreserveHost Off
<Proxy *>
        Require all granted
</Proxy>
         ProxyPass  /  ajp://192.168.1.31:8009/
         ProxyPassReverse / ajp://192.168.1.31:8009/
<Location  / >
        Require all granted
</Location>
</VirtualHost>
[root@localhost ~]# service httpd restart
3、配置apache通过mod_jk模块与Tomcat连接
[root@localhost ~]# tar xf tomcat-connectors-1.2.40-src.tar.gz 
[root@localhost ~]# cd tomcat-connectors-1.2.40-src/native/
[root@localhost native]# ./configure --with-apxs=/usr/local/apache/bin/apxs
[root@localhost native]# make && make install
[root@localhost ~]# ls /usr/local/apache/modules/  #检查模块是否已安装成功
[root@localhost ~]# vim /etc/httpd/httpd.conf
Include /etc/httpd/extra/httpd-jk.conf
[root@localhost ~]# vim /etc/httpd/extra/httpd-jk.conf
LoadModule jk_module modules/mod_jk.so
JkWorkersFile  /etc/httpd/extra/workers.properties
JkLogFile  logs/mod_jk.log
JkLogLevel  debug
JkMount  /*  TomcatA
JkMount  /status/  stat1
[root@localhost ~]# vim /etc/httpd/extra/workers.properties
worker.list=TomcatA,stat1
worker.TomcatA.port=8009
worker.TomcatA.host=192.168.1.31
worker.TomcatA.type=ajp13
worker.TomcatA.lbfactor=1
worker.stat1.type = status


apache+tomcat+jdk安装配置

标签:tomcat jdk apache

原文地址:http://liangshaoqin.blog.51cto.com/2137205/1568280

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!