apache2.2与tomcat集成(可以多个tomcat)

1.需求概况

有2个服务,http://test/admin ,http://test/client 分别对应2个tomcat下的2个应用。由apache httpd作为互联网接入服务器,在80端口接收对这2个服务的请求。apache httpd再将这2个请求分别对应到不同的后端web服务器(Tomcat)处理。


2.配置域名映射到本机即127.0.0.1,同时配置service域名 

$ vi /etc/hosts
127.0.0.1    localhost test

3.apache安装


3-1.apache最新版下载

http://httpd.apache.org/


3-2.必要包导入

$ yum install gcc
$ yum install apr-devel 
$ yum install apr-util-devel 
$ yum install pcre-devel
$ yum install openssl-devel

 3-3.apache安装 

$ tar zxvf httpd-2.2.29.tar.gz
$ cd httpd-2.2.29
$ ./configure \
--prefix=/usr/local/apache2 \
--sbindir=/usr/local/apache2/sbin \
--datadir=/home/www \
--with-apr=/usr/bin/apr-1-config \
--with-apr-util=/usr/bin/apu-1-config \
--with-suexec-caller=www \
--with-suexec-docroot=/home/www \
--enable-ssl \
--with-ssl=shared \
--enable-proxy=shared \
--enable-so \
--enable-mods-shared=all
$ make
$ make install

3-4.apache启动文件做成

vi /etc/rc.d/init.d/httpd
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# httpd        Startup script for the Apache Web Server
#
# chkconfig: - 85 15
# description: The Apache HTTP Server is an efficient and extensible  \
#             server implementing the current HTTP standards.
# processname: httpd
# pidfile: /var/log/httpd/httpd.pid
# config: /etc/sysconfig/httpd
#
### BEGIN INIT INFO
# Provides: httpd
# Required-Start: $local_fs $remote_fs $network $named
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: distcache
# Short-Description: start and stop Apache HTTP Server
# Description: The Apache HTTP Server is an extensible server
#  implementing the current HTTP standards.
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

# What were we called? Multiple instances of the same daemon can be
# created by creating suitably named symlinks to this startup script
prog=$(basename $0 | sed -e 's/^[SK][0-9][0-9]//')

if [ -f /etc/sysconfig/${prog} ]; then
        . /etc/sysconfig/${prog}
fi

# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}

# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""

# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.

#httpd=${HTTPD-/usr/sbin/httpd}
httpd=${HTTPD-/usr/local/apache2/sbin/httpd}
#pidfile=${PIDFILE-/var/log/httpd/${prog}.pid}
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/${prog}}
RETVAL=0

# check for 1.3 configuration
check13 () {
        #CONFFILE=/etc/httpd/conf/httpd.conf
        CONFFILE=/usr/local/apache2/conf/httpd.conf
        GONE="(ServerType|BindAddress|Port|AddModule|ClearModuleList|"
        GONE="${GONE}AgentLog|RefererLog|RefererIgnore|FancyIndexing|"
        GONE="${GONE}AccessConfig|ResourceConfig)"
        if grep -Eiq "^[[:space:]]*($GONE)" $CONFFILE; then
                echo
                echo 1>&2 " Apache 1.3 configuration directives found"
                echo 1>&2 " please read @docdir@/migration.html"
                failure "Apache 1.3 config directives test"
                echo
                exit 1
        fi
}

# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure.  So we just do it the way init scripts
# are expected to behave here.
start() {
        echo -n $"Starting $prog: "
        check13 || exit 1
        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}
stop() {
        echo -n $"Stopping $prog: "
        killproc -p ${pidfile} -d 10 $httpd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
        echo -n $"Reloading $prog: "
        check13 || exit 1
        killproc -p ${pidfile} $httpd -HUP
        RETVAL=$?
        echo
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        if ! test -f ${pidfile}; then
            echo $prog is stopped
            RETVAL=3
        else
            status -p ${pidfile} $httpd
            RETVAL=$?
        fi
        ;;
  restart)
        stop
        start
        ;;
  condrestart)
        if test -f ${pidfile} && status -p ${pidfile} $httpd >&/dev/null; then
                stop
                start
        fi
        ;;
  reload)
        reload
        ;;
  configtest)
        LANG=$HTTPD_LANG $httpd $OPTIONS -t
        RETVAL=$?
        ;;
  graceful)
        echo -n $"Gracefully restarting $prog: "
        LANG=$HTTPD_LANG $httpd $OPTIONS -k $@
        RETVAL=$?
        echo
        ;;
  *)
        echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|graceful|help|configtest}"
        exit 1
esac

exit $RETVAL

3-5.apache配置

确定/usr/local/apache2/cong/http.conf文件里,确认下面这些文字行前面没有"#"注释号:

LoadModule proxy_module modules/mod_proxy.so  
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so  
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so  
LoadModule proxy_connect_module modules/mod_proxy_connect.so  
LoadModule proxy_http_module modules/mod_proxy_http.so  
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so

在/usr/local/apache2/conf/extra/httpd-vhosts.conf文件里增加虚拟主机配置:

NameVirtualHost *:80

<VirtualHost *:80>
<Location /admin>
 ProxyPass ajp://localhost:8009/admin
</Location>
<Location /client>
 ProxyPass ajp://localhost:8109/client
</Location>
</VirtualHost>


3-6.apache启动

$ /etc/init.d/httpd start

4.tomcat安装


4-1.tomcat7最新版下载

http://tomcat.apache.org/download-70.cgi


4-2tomcat服务用户追加

$ groupadd www
$ useradd -d /home/www -g www -G www -s /bin/bash www

4-3.tomcat7安装


4-3-1.tomcat7_admin安装

<pre name="code" class="html">$ tar zxvf apache-tomcat-7.0.42.tar.gz
$ mv apache-tomcat-7.0.42  /usr/local/apache-tomcat-7.0.42_test
$ ln -s /usr/local/apache-tomcat-7.0.42_admin /usr/local/tomcat7_admin
$ mkdir /home/www_admin
$ chown www:www /home/www_admin
$ vi /usr/local/tomcat7_admin/bin/setenv.sh
#!/bin/sh
CATALINA_BASE=/home/www_admin
CATALINA_OPTS="-Xms2048M -Xmx2048M -XX:PermSize=256M -XX:MaxPermSize=256M -Djava.awt.headless=true -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=10080 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
$ cd /home/www_admin
$ mkdir conf
$ mkdir logs
$ cp /usr/local/tomcat7_admin/conf/* /howe/www_admin/conf

 

4-3-2.tomcat7_client安装

$ tar zxvf apache-tomcat-7.0.42.tar.gz
$ mv apache-tomcat-7.0.42  /usr/local/apache-tomcat-7.0.42_client
$ ln -s /usr/local/apache-tomcat-7.0.42_client /usr/local/tomcat7_client
$ vi /usr/local/tomcat7_client/bin/setenv.sh
#!/bin/sh
CATALINA_BASE=/home/www_client
CATALINA_OPTS="-Xms2048M -Xmx2048M -XX:PermSize=256M -XX:MaxPermSize=256M -Djava.awt.headless=true -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=10080 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
$ cd /home/www_client
$ mkdir conf
$ mkdir logs
$ cp /usr/local/tomcat7_client/conf/* /howe/www_client/conf

4-4.tomcat配置


4-4-1.tomcat_admin配置

/home/www_admin/conf/server.xml下面这样修改

<Connector port="8009"  protocol="AJP/1.3" maxHttpHeaderSize="8192"
                     maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
                     enableLookups="false" redirectPort="8443" acceptCount="100
                     proxyName="compass.microad.jp" proxyPort="443" scheme="https" secure="true"
                     connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="UTF-8"/>

4-4-2.tomcat_client配置

/home/www_client/conf/server.xml下面这样修改

< <Server port="8105" shutdown="SHUTDOWN">
---
> <Server port="8005" shutdown="SHUTDOWN">
70c70
<     <Connector port="8081" protocol="HTTP/1.1"
---
>     <Connector port="8080" protocol="HTTP/1.1"
76c76
<                port="8081" protocol="HTTP/1.1"
---
>                port="8080" protocol="HTTP/1.1"
96c96
< <Connector port="8109"  protocol="AJP/1.3" maxHttpHeaderSize="8192"
---
> <Connector port="8009"  protocol="AJP/1.3" maxHttpHeaderSize="8192"

4-5.tomcat启动文件设置


4-5-1.tomcat_admin启动文件

$ vi /etc/rc.d/init.d/tomcat_admin
#!/bin/bash
#
# Startup script for the Tomcat Servlet Container
#
# chkconfig: 2345 35 65
# description: Tomcat is the servlet container that is used in the official \
#              Reference Implementation for the Java Servlet and JavaServer \
#              Pages technologies

TOMCAT_USER=www
CATALINA_HOME=/usr/local/tomcat7_admin

. /etc/rc.d/init.d/functions
prog=tomcat

start() {
    echo -n $"Starting $prog: "
    daemon --user $TOMCAT_USER $CATALINA_HOME/bin/startup.sh > /dev/null
    RETVAL=$?
    if [ $RETVAL -eq 0 ]; then
        echo_success
    else
        echo_failure
    fi
    echo
    [ $RETVAL = 0 ] && touch /var/lock/subsys/$prog
    return $RETVAL
}                                                                                                                                                                                                                                            
stop() {
    echo -n $"Stopping $prog: "
    daemon --user $TOMCAT_USER $CATALINA_HOME/bin/shutdown.sh > /dev/null
    RETVAL=$?
    if [ $RETVAL -eq 0 ]; then
        echo_success
    else
        echo_failure
    fi
    echo
    [ $RETVAL = 0 ] && rm -f /var/lock/subsys/$prog
    return $RETVAL
}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    stop
    start
    ;;
  status)                                                                                                                                                                                                                                    
    INSTANCES=`ps --columns 512 -aef|grep java|grep tomcat|grep org.apache.catalina.startup.Bootstrap|wc -l`
    if [ $INSTANCES -eq 0 ]; then
        echo $prog is stopped
        RETVAL=3
    else
        if [ $INSTANCES -eq 1 ]; then
            echo $prog is running 1 instance...
        else
            echo $prog is running $INSTANCES instances...
        fi
        RETVAL=0
    fi
    ;;
  *)
    echo $"Usage: $prog {start|stop|restart|status|help}"
    exit 1
esac

exit $RETVAL


4-5-2.tomcat7_client启动文件

$ vi /etc/rc.d/init.d/tomcat_client
#!/bin/bash
#
# Startup script for the Tomcat Servlet Container
#
# chkconfig: 2345 35 65
# description: Tomcat is the servlet container that is used in the official \
#              Reference Implementation for the Java Servlet and JavaServer \
#              Pages technologies


TOMCAT_USER=www
CATALINA_HOME=/usr/local/tomcat7_client


. /etc/rc.d/init.d/functions
prog=tomcat


start() {
    echo -n $"Starting $prog: "
    daemon --user $TOMCAT_USER $CATALINA_HOME/bin/startup.sh > /dev/null
    RETVAL=$?
    if [ $RETVAL -eq 0 ]; then
        echo_success
    else
        echo_failure
    fi
    echo
    [ $RETVAL = 0 ] && touch /var/lock/subsys/$prog
    return $RETVAL
}                                                                                                                                                                                                                                            
stop() {
    echo -n $"Stopping $prog: "
    daemon --user $TOMCAT_USER $CATALINA_HOME/bin/shutdown.sh > /dev/null
    RETVAL=$?
    if [ $RETVAL -eq 0 ]; then
        echo_success
    else
        echo_failure
    fi
    echo
    [ $RETVAL = 0 ] && rm -f /var/lock/subsys/$prog
    return $RETVAL
}


# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    stop
    start
    ;;
  status)                                                                                                                                                                                                                                    
    INSTANCES=`ps --columns 512 -aef|grep java|grep tomcat|grep org.apache.catalina.startup.Bootstrap|wc -l`
    if [ $INSTANCES -eq 0 ]; then
        echo $prog is stopped
        RETVAL=3
    else
        if [ $INSTANCES -eq 1 ]; then
            echo $prog is running 1 instance...
        else
            echo $prog is running $INSTANCES instances...
        fi
        RETVAL=0
    fi
    ;;
  *)
    echo $"Usage: $prog {start|stop|restart|status|help}"
    exit 1
esac


exit $RETVAL


4-6.tomcat启动


4-6-1.tomcat_admin启动

$ /etc/init.d/tomcat7_admin start

4-6-2.tomcat_client启动

$ /etc/init.d/tomcat7_client start














  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值