apache / tomcat installation process slightly

apache / tomcat installation process slightly

Some variables

apache installation directory

APACHE_PREFIX=/Data/app/apache

apache configuration file

APACHE_CONF=/etc/httpd/httpd.conf

tomcat installation directory

TOMCAT1_PREFIX=/Data/app/tomcat1
TOMCAT2_PREFIX=/Data/app/tomcat2

tomcat root directory

TOMCAT_ROOT=/Data/code

Tomcat add to the project, which is configured tomcat root directory, modify $ TOMCAT_PREFIX / conf / server.xml

in Snippet Context, here set / Data / code /

<Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
<Context path="" docBase="/Data/code"></Context>
.....
.....
</Host>

jk installation (connectors Apache Tomcat)

wget  http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.39-src.tar.gz

tar zxvf tomcat-connectors-1.2.39-src.tar.gz && cd tomcat-connectors-1.2.39-src/native

./configure --with-apxs=/Data/app/apache/bin/apxs --with-java-home=/Data/app/jdk

make # mod_jk.so会生成在apache安装目录下的modules目录

Installation tomcat native, or there will be an error on libnative in tomcat startup log

cd /Data/app/tomcat/bin  # tomcat 安装目录下的bin目录

tar zxvf tomcat-native.tar.gz && cd tomcat-native-1.1.29-src/jni/native

./configure --with-apr=/Data/app/apr/bin/apr-1-config --with-ssl=/usr/local/ssl/

make && make install

cp  /usr/local/apr/lib/libtcnative* /usr/lib  #拷贝到/usr/lib  /usr/lib64等位置都可,参考tomcat启动日志

Launch multiple tomcat, the machine starts multiple tomcat, pay attention to modify the tomcat port, server.xml the 8080,8005,8009 ports should avoid conflict, or can not start more than tomcat

Suppose two locally installed tomcat are $ TOMCAT1_PREFIX and $ TOMCAT2_PREFIX, port conflict start confirmation

$TOMCAT1_PREFIX/bin/catalina.sh start
$TOMCAT2_PREFIX/bin/catalina.sh start

Apache configuration as the front end, a rear end forward the request to the cluster tomcat

Mod_jk.conf created in / etc / httpd / extra directory, file content:

LoadModule jk_module modules/mod_jk.so  #加载mod_jk模块
JkWorkersFile /etc/httpd/extra/workers.properties  #这个文件里配置的是tomcat集群及负载均衡
JkMountFile /etc/httpd/extra/uriworkermap.properties  # 这里配置的是转发规则,即哪些由apache自己处理,哪些交给tomcat
JkLogFile logs/mod_jk.log
JkLogLevel info

Creating and uriworkermap.properties in extra workers.properties

####################################
##file name workers.properties####
worker.list=tomcatserver,status  # tomcatserver为均衡器名称,自定义
# localhost server 1
# ------------------------
worker.s1.port=8009       #s1是为tomcat定义的名称,多个tomcat不得冲突
worker.s1.host=localhost
worker.s1.type=ajp13
worker.s1.lbfactor = 1    #在集群中的权重
# localhost server 2
# ------------------------
worker.s2.port=8010       #s2的意义同s1
worker.s2.host=localhost
worker.s2.type=ajp13
worker.s2.lbfactor = 1

#-----------------------------
worker.tomcatserver.type=lb   #负载均衡类型,
worker.retries=3
worker.tomcatserver.balance_workers=s1,s2   #s1,s2就是上边定义的名称
worker.tomcatserver.sticky_session=false  #启用session复制,该选项必须为false,如果为true,则表示同一用户的请求不会在多个tomcat之间移动,固定由一个tomcat处理
worker.tomcatserver.sticky_session_force=1 #默认tomcat 无反应,是否将请求转到其他tomcat
worker.status.type=status




##########################################
#####file name uriworkermap.properties####
/*=tomcatserver             #所有请求都由controller这个server处理
/jkstatus=status           #所有包含jkstatus请求的都由status这个server处理
!/*.gif=tomcatserver         #所有以.gif结尾的请求都不由tomcatserver这个server处理,以下几个都是一样的意思
!/*.jpg=tomcatserver
!/*.png=tomcatserver
!/*.css=tomcatserver
!/*.js=tomcatserver
!/*.htm=tomcatserver
!/*.html=tomcatserver

Modify $ APACHE_CONF,

Include /etc/httpd/extra/mod_jk.conf

Httpd restart

Apache has now can communicate with jk tomcat, and the requests distributed evenly s1, s2 two tomcat. Jk if not installed, apache proxy can communicate with tomcat

Multiple tomcat session replication to maintain client session

Modify $ TOMCAT1_PREFIX / conf / server.xml and $ TOMCAT2_PREFIX / conf / server.xml

TOMCAT1_PREFIX/conf/server.xml
<Engine name="Catalina" defaultHost="localhost" jvmRoute="s1">  #jvmRoute必须设置,s1与workers.properties中设置的名称一致,另一个为jvmRoute="s2"

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

        <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
                 channelSendOptions="8">

          <Manager className="org.apache.catalina.ha.session.DeltaManager"
                   expireSessionsOnShutdown="false"
                   notifyListenersOnReplication="true"/>

          <Channel className="org.apache.catalina.tribes.group.GroupChannel">
            <Membership className="org.apache.catalina.tribes.membership.McastService"
                        address="228.0.0.4"
                        port="45564"
                        frequency="500"
                        dropTime="3000"/>
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
                      address="auto"      #auto的话,会绑定在127.0.0.1上
                      port="4000"         #这个端口号两个tomcat必须不一致,不得冲突
                      autoBind="100"
                      selectorTimeout="5000"
                      maxThreads="6"/>

            <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
              <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
            </Sender>
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
          </Channel>

          <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
                 filter=""/>
          <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>

          <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
                    tempDir="/tmp/war-temp/"
                    deployDir="/tmp/war-deploy/"
                    watchDir="/tmp/war-listen/"
                    watchEnabled="false"/>
                    <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
          <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
        </Cluster>

Creating WEB-INF directory under $ TOMCAT_ROOT, create a web.xml under WEB-INF directory

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                      http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  version="3.0"
  metadata-complete="true">

  <display-name>Welcome to Tomcat</display-name>
  <description>
     Welcome to Tomcat
  </description>
<distributable/>    #必须添加这个标签
</web-app>

Started two tomcat

route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0

Guess you like

Origin www.cnblogs.com/8gman/p/12336367.html