apache2.2与tomcat集成(可以多个tomcat)
来源:互联网 发布:mac mysql 修改密码 编辑:程序博客网 时间:2024/05/20 21:45
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/hosts127.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-devel3-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 scriptprog=$(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 configurationcheck13 () { #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 1esacexit $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/shCATALINA_BASE=/home/www_adminCATALINA_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/conf4-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/shCATALINA_BASE=/home/www_clientCATALINA_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 technologiesTOMCAT_USER=wwwCATALINA_HOME=/usr/local/tomcat7_admin. /etc/rc.d/init.d/functionsprog=tomcatstart() { 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 1esacexit $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 technologiesTOMCAT_USER=wwwCATALINA_HOME=/usr/local/tomcat7_client. /etc/rc.d/init.d/functionsprog=tomcatstart() { 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 1esacexit $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
- apache2.2与tomcat集成(可以多个tomcat)
- Apache2.2与Tomcat集成
- apache2.2.9集成tomcat
- apache2.2+tomcat集群
- apache 集成多个tomcat的方法
- apache 集成多个tomcat的方法
- apache 集成多个tomcat的方法
- 安装一个tomcat可以运行多个tomcat实例
- Tomcat 与 IIS 集成
- Tomcat与Derby集成
- tomcat与jboss集成
- Tomcat与IIS集成
- Tomcat与Apache集成
- Tomcat 与 cas 集成
- Tomcat与Apache集成
- tomcat 与eclipse集成
- mavn与tomcat集成
- Tomcat与IIS集成 .
- 2014.10.1
- c++ 之 namespace
- Mac OS X重装系统
- Java中的大数处理类BigInteger和BigDecimar浅析
- PHP导出Excel表格(最简易)
- apache2.2与tomcat集成(可以多个tomcat)
- 【Struts2学习笔记(7)】类型转换器的两种方法
- 为网上流行论点“UIAutomator不能通过中文文本查找控件”正名
- Beautiful People
- android设计模式-适配器模式
- poj 1655 求树的重心
- (四)树莓派同步时间
- NSMutableArray Methods
- 数据结构_顺序表