- 浏览: 138174 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (138)
- java基础 (26)
- 日常工作经验总结 (22)
- SVN学习与使用 (1)
- JBOSS学习与实践 (1)
- webService学习与实践 (4)
- redis学习与实践 (12)
- spring学习与实践 (0)
- hibernate学习与实践 (4)
- Struts2学习与实践 (0)
- mybatis学习与实践 (0)
- SpringMVC学习与实践 (0)
- jfreechart学习与使用 (0)
- javaScript学习与实践 (1)
- linux学习与实践 (4)
- Python学习与实践 (7)
- Oracle学习与实践 (21)
- Mysql学习与实践 (4)
- HTML5+CSS3学习与实践 (0)
- DIV+CSS学习与实践 (0)
- tomcat学习与实践 (1)
- mongodb学习与实践 (1)
- Git学习与实践 (2)
- hadhoop学习与实践 (0)
- shiro学习与实践 (0)
- CMS学习与实践 (0)
- Jmeter学习与实践 (0)
- java测试学习与实践 (2)
- bootstrap学习与实践 (0)
- jquery学习与实践 (0)
- Spring+hibernate+Struts2框架开发CRM项目 (0)
- JVM学习与实践 (0)
- 推荐学习网站 (1)
- 日常工作必备小技能 (4)
- Apache实践 (1)
- dubbo学习与实践 (2)
- Centos7 (6)
- 面试题目集合(收集各大网站) (4)
- 大数据学习 (1)
- 财富本 (2)
- 股票投资学习 (0)
- ZooKeeper (0)
- python切割集合里面相同的元素到一个集合里面 (1)
- 机器学习与深度学习 (1)
最新评论
-
魏叔武:
...
基于UDP协议的Socket编程
安装软件版本,文本后面有软件以及配置文件下载地址
集群环境,一个apache负载均衡到三台tomcat上
apr-1.4.8.tar.gz
apr-util-1.5.1.tar.gz
jdk1.8.0_131.tar.gz
mod_jk-1.2.31-httpd-2.2.x.so
pcre-8.42.tar.gz
httpd-2.2.25.tar.gz
apache-tomcat-7.0.94.tar.gz
准备工作,在自己的linux(Centos7.4)环境上,新建一个目录,把上面的软件都上传到自己的目录,
然后全部解压tar.gz文件,tomcat解压备份三份,分别命名Tomcat71,Tomcat72,Tomcat73
第一步: 配置JDK的环境变量
# vi /etc/profile
#添加内容
#java environment
export JAVA_HOME=/home/software/jdk1.8.0_131/
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
#生效环境变量
# source /etc/profile
#检查是否生效 java,javac,java -version
第二步:修改tomcat的配置文件
由于本地安装在一台物理机器中,所以需要修改很多个位置,详情看修改位置备注信息server.xml。,三台tomcat都需要去修改下面的位置
修改内容如下: 具体修改内容,可以看三个tomcat的配置文件
<?xml version='1.0' encoding='utf-8'?>
<!--
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.
-->
<!-- Note: A "Server" is not itself a "Container", so you may not
define subcomponents such as "Valves" at this level.
Documentation at /docs/config/server.html
-->
<!--修改位置一: Server port="8005" 在一台机器中,每个tomcat的端口要不同,如果在不同的物理机器中,那么不需要修改-->
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<!-- Security listener. Documentation at /docs/config/listeners.html
<Listener className="org.apache.catalina.security.SecurityListener" />
-->
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
<Listener className="org.apache.catalina.core.JasperListener" />
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note: A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level.
Documentation at /docs/config/service.html
-->
<Service name="Catalina">
<!--The connectors can use a shared executor, you can define one or more named thread pools-->
<!--
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
-->
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL HTTP/1.1 Connector on port 8080
-->
<!--修改位置二: Connector port="8080" 在一台机器中,每个tomcat的端口要不同,如果在不同的物理机器中,那么不需要修改也可以-->
<!--修改位置三: redirectPort="8443" 在一台机器中,每个tomcat的端口要不同,如果在不同的物理机器中,那么不需要修改也可以-->
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
-->
<!-- Define a SSL HTTP/1.1 Connector on port 8443
This connector uses the BIO implementation that requires the JSSE
style configuration. When using the APR/native implementation, the
OpenSSL style configuration is required as described in the APR/native
documentation -->
<!--
<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
-->
<!-- Define an AJP 1.3 Connector on port 8009 -->
<!--修改位置四: Connector port="8009" 在一台机器中,每个tomcat的端口要不同,如果在不同的物理机器中,那么不需要修改也可以-->
<!--修改位置五: redirectPort="8443" 在一台机器中,每个tomcat的端口要不同,这个值跟上面修改位置三值一样,如果在不同的物理机器中,那么不需要修改也可以-->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<!-- An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host).
Documentation at /docs/config/engine.html -->
<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<!--修改位置六: jvmRoute="Tomcat71" jvmRoute修改为自己定义的值,后续集群配置需要-->
<Engine name="Catalina" defaultHost="localhost" jvmRoute="Tomcat71">
<!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) -->
<!--修改位置七 打开这个,用于session共享-->
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
<!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
</Server>
第三步:安装apache
Apache至少需要apr、apr-util、pcre组件的支持。
1.查询是否安装了apache服务器httpd
[root@localhost src]# rpm -qa|grep httpd
httpd-2.4.6-45.el7.centos.x86_64
httpd-tools-2.4.6-45.el7.centos.x86_64
2.卸载系统自动装的apache服务器httpd
[root@localhost src]# httpd -k stop #停止httpd服务器
[root@localhost src]# yum remove httpd #卸载httpd服务器
3,检查系统是否安装了GCC
[root@localhost src]# gcc
bash: gcc: 未找到命令... #出现未找到命令提示,说明没有安装GCC
4,安装GCC和gcc-c++
[root@localhost src]# yum -y install gcc
[root@localhost pcre-8.40]# yum -y install gcc-c++
5 编译安装apr-1.4.8
#改变目录到apr-apr-1.4.8
[root@localhost local]# cd apr-1.4.8
#指定apr的安装目录为/usr/local/apr 配置
[root@localhost apr-1.4.8]# ./configure -prefix=/usr/local/apr
#编译安装
[root@localhost apr-1.4.8]# make && make install
6,编译安装 apr-uril-1.5.2
#改变目录到apr-util-1.5.2/
[root@localhost local]# cd apr-util-1.5.2/
#指定apr-util的安装路径,指定apr-util所对应的apr
[root@localhost apr-util-1.5.2]# ./configure -prefix=/usr/local/apr-util -with-apr=/usr/local/apr
#编译安装
[root@localhost apr-util-1.5.2]# make && make install
7, 编译安装pcre
#卸载系统自带的pcre
[root@localhost apr-util-1.5.2]# rpm -qa pcre
pcre-8.32-15.el7_2.1.x86_64
#改变目录到pcre-8.42/
[root@localhost local]# cd pcre-8.42/
#指定prce的安装路径,指定apr-util所对应的apr
[root@localhost pcre-8.42]# ./configure -prefix=/usr/local/pcre
#编译安装(make是编译 make install是安装)
[root@localhost pcre-8.42]# make && make install
8, 编译安装apache
编译和安装apache分为动态、静态两种方式。动态编译是指在以后的使用中随时调整配置文件就可以加载模块;静态则相反,在编译时就决定了相应的模块。
#改变目录到httpd-2.2.25/
[root@localhost local]# cd httpd-2.2.25/
#配置
[root@localhost httpd-2.2.25]# ./configure -prefix=/usr/local/apache -sysconfdir=/etc/httpd -enable-so -enable-rewrite -with-apr=/usr/local/apr -with-apr-util=/usr/local/apr-util -with-pcre=/usr/local/pcre
#编译安装
[root@localhost httpd-2.2.25]#make && make install
第四步:配置apache
到apache的目录,本文安装的目录为 /usr/local/apache/
修改httpd.conf,修改内容为:ServerName localhost:80
第五步:配置集群,
1,新建文件,mod_jk.conf,uriworkermap.properties,workers.properties
内容分别为为:
mod_jk.conf的内容:
#mod_jk.so文件的位置
LoadModule jk_module modules/mod_jk.so
#配置文件的位置
JkWorkersFile conf/workers.properties
#配置文件的位置
JkMountFile conf/uriworkermap.properties
#集群日志文件的位置
JkLogFile /usr/local/apache/logs/mod_jk.log
#日志打印级别
JkLogLevel warn
#日志后期后缀格式
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
uriworkermap.properties的内容:
/admin/*=wlb
/manager/*=wlb
/jsp-examples/*=wlb
/servlets-examples/*=wlb
/examples/*=wlb
/*.jsp=wlb
/*=wlb
!/servlets-examples/*.jpeg=wlb
/jkmanager=jkstatus
!/*.gif=wlb
!/*.jpg=wlb
!/*.png=wlb
!/*.css=wlb
!/*.js=wlb
!/*.htm=wlb
!/*.html=wlb
workers.properties的内容:
#集群列表
worker.list=wlb,jkstatus
# Define preferred failover node for tomcat71
#修改为自己的tomcat的server.xml的端口名字以及 jvmRoute="Tomcat71" 的名字
worker.Tomcat71.port=8009
#一台机器,IP为localhost,不同物理机器,修改为对应的ip
worker.Tomcat71.host=localhost
worker.Tomcat71.type=ajp13
#负载因子
worker.Tomcat71.lbfactor=1
#worker.tomcat1.redirect=tomcat72
#修改为自己的tomcat的server.xml的端口名字以及 jvmRoute="Tomcat71" 的名字
worker.Tomcat72.port=8010
worker.Tomcat72.host=localhost
worker.Tomcat72.type=ajp13
worker.Tomcat72.lbfactor=1
#worker.tomcat1.redirect=tomcat73
#修改为自己的tomcat的server.xml的端口名字以及 jvmRoute="Tomcat71" 的名字
worker.Tomcat73.port=8011
#一台机器,IP为localhost,不同物理机器,修改为对应的ip
worker.Tomcat73.host=localhost
worker.Tomcat73.type=ajp13
worker.Tomcat73.lbfactor=1
#负载因子
worker.wlb.type=lb
worker.wlb.balance_workers=Tomcat71,Tomcat72,Tomcat73
worker.jkstatus.type=status
2,把分享的mod_jk.so文件放在/usr/local/apache/modules/ 目录下
3,修改httpd.conf文件,添加内容:
Include conf/mod_jk.conf 把集群的配置文件放在apache中
第六步:测试
把新建的test项目放在三台tomcat中,然后启动tomcat71,tomcat72,tomcat73
查看是否启动成功:
[root@localhost bin]# ps -ef|grep tomcat
root 5003 1 5 11:23 pts/1 00:00:31 /home/leifengchuan/software/jdk1.8.0_131//bin/java -Djava.util.logging.config.file=/home/leifengchuan/software/Tomcat71/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Dignore.endorsed.dirs= -classpath /home/leifengchuan/software/Tomcat71/bin/bootstrap.jar:/home/leifengchuan/software/Tomcat71/bin/tomcat-juli.jar -Dcatalina.base=/home/leifengchuan/software/Tomcat71 -Dcatalina.home=/home/leifengchuan/software/Tomcat71 -Djava.io.tmpdir=/home/leifengchuan/software/Tomcat71/temp org.apache.catalina.startup.Bootstrap start
root 5022 1 4 11:24 pts/1 00:00:26 /home/leifengchuan/software/jdk1.8.0_131//bin/java -Djava.util.logging.config.file=/home/leifengchuan/software/Tomcat72/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Dignore.endorsed.dirs= -classpath /home/leifengchuan/software/Tomcat72/bin/bootstrap.jar:/home/leifengchuan/software/Tomcat72/bin/tomcat-juli.jar -Dcatalina.base=/home/leifengchuan/software/Tomcat72 -Dcatalina.home=/home/leifengchuan/software/Tomcat72 -Djava.io.tmpdir=/home/leifengchuan/software/Tomcat72/temp org.apache.catalina.startup.Bootstrap start
root 5041 1 4 11:24 pts/1 00:00:22 /home/leifengchuan/software/jdk1.8.0_131//bin/java -Djava.util.logging.config.file=/home/leifengchuan/software/Tomcat73/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Dignore.endorsed.dirs= -classpath /home/leifengchuan/software/Tomcat73/bin/bootstrap.jar:/home/leifengchuan/software/Tomcat73/bin/tomcat-juli.jar -Dcatalina.base=/home/leifengchuan/software/Tomcat73 -Dcatalina.home=/home/leifengchuan/software/Tomcat73 -Djava.io.tmpdir=/home/leifengchuan/software/Tomcat73/temp org.apache.catalina.startup.Bootstrap start
root 5415 4306 0 11:33 pts/1 00:00:00 grep --color=auto tomcat
说明三台tomcat启动
启动apache, ./usr/local/apache/bin/apachectl start
出现:
[root@localhost bin]# ps -ef|grep httpd
root 5276 1 0 11:28 ? 00:00:00 /usr/local/apache/bin/httpd -k start
daemon 5277 5276 0 11:28 ? 00:00:00 /usr/local/apache/bin/httpd -k start
daemon 5278 5276 0 11:28 ? 00:00:00 /usr/local/apache/bin/httpd -k start
daemon 5279 5276 0 11:28 ? 00:00:00 /usr/local/apache/bin/httpd -k start
daemon 5280 5276 0 11:28 ? 00:00:00 /usr/local/apache/bin/httpd -k start
daemon 5281 5276 0 11:28 ? 00:00:00 /usr/local/apache/bin/httpd -k start
root 5321 4306 0 11:29 pts/1 00:00:00 grep --color=auto httpd
说明apache起来了,分别用三个浏览器去访问
http://ip/test/test.jsp 可以看到每个浏览器访问的是不同的tomcat,实现负载均衡,每个浏览器,每次请求,session一致
链接:https://pan.baidu.com/s/11zMz5To_eN2mVGkYBDXHtw
提取码:xgza
集群环境,一个apache负载均衡到三台tomcat上
apr-1.4.8.tar.gz
apr-util-1.5.1.tar.gz
jdk1.8.0_131.tar.gz
mod_jk-1.2.31-httpd-2.2.x.so
pcre-8.42.tar.gz
httpd-2.2.25.tar.gz
apache-tomcat-7.0.94.tar.gz
准备工作,在自己的linux(Centos7.4)环境上,新建一个目录,把上面的软件都上传到自己的目录,
然后全部解压tar.gz文件,tomcat解压备份三份,分别命名Tomcat71,Tomcat72,Tomcat73
第一步: 配置JDK的环境变量
# vi /etc/profile
#添加内容
#java environment
export JAVA_HOME=/home/software/jdk1.8.0_131/
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
#生效环境变量
# source /etc/profile
#检查是否生效 java,javac,java -version
第二步:修改tomcat的配置文件
由于本地安装在一台物理机器中,所以需要修改很多个位置,详情看修改位置备注信息server.xml。,三台tomcat都需要去修改下面的位置
修改内容如下: 具体修改内容,可以看三个tomcat的配置文件
<?xml version='1.0' encoding='utf-8'?>
<!--
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.
-->
<!-- Note: A "Server" is not itself a "Container", so you may not
define subcomponents such as "Valves" at this level.
Documentation at /docs/config/server.html
-->
<!--修改位置一: Server port="8005" 在一台机器中,每个tomcat的端口要不同,如果在不同的物理机器中,那么不需要修改-->
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<!-- Security listener. Documentation at /docs/config/listeners.html
<Listener className="org.apache.catalina.security.SecurityListener" />
-->
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
<Listener className="org.apache.catalina.core.JasperListener" />
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note: A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level.
Documentation at /docs/config/service.html
-->
<Service name="Catalina">
<!--The connectors can use a shared executor, you can define one or more named thread pools-->
<!--
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
-->
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL HTTP/1.1 Connector on port 8080
-->
<!--修改位置二: Connector port="8080" 在一台机器中,每个tomcat的端口要不同,如果在不同的物理机器中,那么不需要修改也可以-->
<!--修改位置三: redirectPort="8443" 在一台机器中,每个tomcat的端口要不同,如果在不同的物理机器中,那么不需要修改也可以-->
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
-->
<!-- Define a SSL HTTP/1.1 Connector on port 8443
This connector uses the BIO implementation that requires the JSSE
style configuration. When using the APR/native implementation, the
OpenSSL style configuration is required as described in the APR/native
documentation -->
<!--
<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
-->
<!-- Define an AJP 1.3 Connector on port 8009 -->
<!--修改位置四: Connector port="8009" 在一台机器中,每个tomcat的端口要不同,如果在不同的物理机器中,那么不需要修改也可以-->
<!--修改位置五: redirectPort="8443" 在一台机器中,每个tomcat的端口要不同,这个值跟上面修改位置三值一样,如果在不同的物理机器中,那么不需要修改也可以-->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<!-- An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host).
Documentation at /docs/config/engine.html -->
<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<!--修改位置六: jvmRoute="Tomcat71" jvmRoute修改为自己定义的值,后续集群配置需要-->
<Engine name="Catalina" defaultHost="localhost" jvmRoute="Tomcat71">
<!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) -->
<!--修改位置七 打开这个,用于session共享-->
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
<!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
</Server>
第三步:安装apache
Apache至少需要apr、apr-util、pcre组件的支持。
1.查询是否安装了apache服务器httpd
[root@localhost src]# rpm -qa|grep httpd
httpd-2.4.6-45.el7.centos.x86_64
httpd-tools-2.4.6-45.el7.centos.x86_64
2.卸载系统自动装的apache服务器httpd
[root@localhost src]# httpd -k stop #停止httpd服务器
[root@localhost src]# yum remove httpd #卸载httpd服务器
3,检查系统是否安装了GCC
[root@localhost src]# gcc
bash: gcc: 未找到命令... #出现未找到命令提示,说明没有安装GCC
4,安装GCC和gcc-c++
[root@localhost src]# yum -y install gcc
[root@localhost pcre-8.40]# yum -y install gcc-c++
5 编译安装apr-1.4.8
#改变目录到apr-apr-1.4.8
[root@localhost local]# cd apr-1.4.8
#指定apr的安装目录为/usr/local/apr 配置
[root@localhost apr-1.4.8]# ./configure -prefix=/usr/local/apr
#编译安装
[root@localhost apr-1.4.8]# make && make install
6,编译安装 apr-uril-1.5.2
#改变目录到apr-util-1.5.2/
[root@localhost local]# cd apr-util-1.5.2/
#指定apr-util的安装路径,指定apr-util所对应的apr
[root@localhost apr-util-1.5.2]# ./configure -prefix=/usr/local/apr-util -with-apr=/usr/local/apr
#编译安装
[root@localhost apr-util-1.5.2]# make && make install
7, 编译安装pcre
#卸载系统自带的pcre
[root@localhost apr-util-1.5.2]# rpm -qa pcre
pcre-8.32-15.el7_2.1.x86_64
#改变目录到pcre-8.42/
[root@localhost local]# cd pcre-8.42/
#指定prce的安装路径,指定apr-util所对应的apr
[root@localhost pcre-8.42]# ./configure -prefix=/usr/local/pcre
#编译安装(make是编译 make install是安装)
[root@localhost pcre-8.42]# make && make install
8, 编译安装apache
编译和安装apache分为动态、静态两种方式。动态编译是指在以后的使用中随时调整配置文件就可以加载模块;静态则相反,在编译时就决定了相应的模块。
#改变目录到httpd-2.2.25/
[root@localhost local]# cd httpd-2.2.25/
#配置
[root@localhost httpd-2.2.25]# ./configure -prefix=/usr/local/apache -sysconfdir=/etc/httpd -enable-so -enable-rewrite -with-apr=/usr/local/apr -with-apr-util=/usr/local/apr-util -with-pcre=/usr/local/pcre
#编译安装
[root@localhost httpd-2.2.25]#make && make install
第四步:配置apache
到apache的目录,本文安装的目录为 /usr/local/apache/
修改httpd.conf,修改内容为:ServerName localhost:80
第五步:配置集群,
1,新建文件,mod_jk.conf,uriworkermap.properties,workers.properties
内容分别为为:
mod_jk.conf的内容:
#mod_jk.so文件的位置
LoadModule jk_module modules/mod_jk.so
#配置文件的位置
JkWorkersFile conf/workers.properties
#配置文件的位置
JkMountFile conf/uriworkermap.properties
#集群日志文件的位置
JkLogFile /usr/local/apache/logs/mod_jk.log
#日志打印级别
JkLogLevel warn
#日志后期后缀格式
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
uriworkermap.properties的内容:
/admin/*=wlb
/manager/*=wlb
/jsp-examples/*=wlb
/servlets-examples/*=wlb
/examples/*=wlb
/*.jsp=wlb
/*=wlb
!/servlets-examples/*.jpeg=wlb
/jkmanager=jkstatus
!/*.gif=wlb
!/*.jpg=wlb
!/*.png=wlb
!/*.css=wlb
!/*.js=wlb
!/*.htm=wlb
!/*.html=wlb
workers.properties的内容:
#集群列表
worker.list=wlb,jkstatus
# Define preferred failover node for tomcat71
#修改为自己的tomcat的server.xml的端口名字以及 jvmRoute="Tomcat71" 的名字
worker.Tomcat71.port=8009
#一台机器,IP为localhost,不同物理机器,修改为对应的ip
worker.Tomcat71.host=localhost
worker.Tomcat71.type=ajp13
#负载因子
worker.Tomcat71.lbfactor=1
#worker.tomcat1.redirect=tomcat72
#修改为自己的tomcat的server.xml的端口名字以及 jvmRoute="Tomcat71" 的名字
worker.Tomcat72.port=8010
worker.Tomcat72.host=localhost
worker.Tomcat72.type=ajp13
worker.Tomcat72.lbfactor=1
#worker.tomcat1.redirect=tomcat73
#修改为自己的tomcat的server.xml的端口名字以及 jvmRoute="Tomcat71" 的名字
worker.Tomcat73.port=8011
#一台机器,IP为localhost,不同物理机器,修改为对应的ip
worker.Tomcat73.host=localhost
worker.Tomcat73.type=ajp13
worker.Tomcat73.lbfactor=1
#负载因子
worker.wlb.type=lb
worker.wlb.balance_workers=Tomcat71,Tomcat72,Tomcat73
worker.jkstatus.type=status
2,把分享的mod_jk.so文件放在/usr/local/apache/modules/ 目录下
3,修改httpd.conf文件,添加内容:
Include conf/mod_jk.conf 把集群的配置文件放在apache中
第六步:测试
把新建的test项目放在三台tomcat中,然后启动tomcat71,tomcat72,tomcat73
查看是否启动成功:
[root@localhost bin]# ps -ef|grep tomcat
root 5003 1 5 11:23 pts/1 00:00:31 /home/leifengchuan/software/jdk1.8.0_131//bin/java -Djava.util.logging.config.file=/home/leifengchuan/software/Tomcat71/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Dignore.endorsed.dirs= -classpath /home/leifengchuan/software/Tomcat71/bin/bootstrap.jar:/home/leifengchuan/software/Tomcat71/bin/tomcat-juli.jar -Dcatalina.base=/home/leifengchuan/software/Tomcat71 -Dcatalina.home=/home/leifengchuan/software/Tomcat71 -Djava.io.tmpdir=/home/leifengchuan/software/Tomcat71/temp org.apache.catalina.startup.Bootstrap start
root 5022 1 4 11:24 pts/1 00:00:26 /home/leifengchuan/software/jdk1.8.0_131//bin/java -Djava.util.logging.config.file=/home/leifengchuan/software/Tomcat72/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Dignore.endorsed.dirs= -classpath /home/leifengchuan/software/Tomcat72/bin/bootstrap.jar:/home/leifengchuan/software/Tomcat72/bin/tomcat-juli.jar -Dcatalina.base=/home/leifengchuan/software/Tomcat72 -Dcatalina.home=/home/leifengchuan/software/Tomcat72 -Djava.io.tmpdir=/home/leifengchuan/software/Tomcat72/temp org.apache.catalina.startup.Bootstrap start
root 5041 1 4 11:24 pts/1 00:00:22 /home/leifengchuan/software/jdk1.8.0_131//bin/java -Djava.util.logging.config.file=/home/leifengchuan/software/Tomcat73/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Dignore.endorsed.dirs= -classpath /home/leifengchuan/software/Tomcat73/bin/bootstrap.jar:/home/leifengchuan/software/Tomcat73/bin/tomcat-juli.jar -Dcatalina.base=/home/leifengchuan/software/Tomcat73 -Dcatalina.home=/home/leifengchuan/software/Tomcat73 -Djava.io.tmpdir=/home/leifengchuan/software/Tomcat73/temp org.apache.catalina.startup.Bootstrap start
root 5415 4306 0 11:33 pts/1 00:00:00 grep --color=auto tomcat
说明三台tomcat启动
启动apache, ./usr/local/apache/bin/apachectl start
出现:
[root@localhost bin]# ps -ef|grep httpd
root 5276 1 0 11:28 ? 00:00:00 /usr/local/apache/bin/httpd -k start
daemon 5277 5276 0 11:28 ? 00:00:00 /usr/local/apache/bin/httpd -k start
daemon 5278 5276 0 11:28 ? 00:00:00 /usr/local/apache/bin/httpd -k start
daemon 5279 5276 0 11:28 ? 00:00:00 /usr/local/apache/bin/httpd -k start
daemon 5280 5276 0 11:28 ? 00:00:00 /usr/local/apache/bin/httpd -k start
daemon 5281 5276 0 11:28 ? 00:00:00 /usr/local/apache/bin/httpd -k start
root 5321 4306 0 11:29 pts/1 00:00:00 grep --color=auto httpd
说明apache起来了,分别用三个浏览器去访问
http://ip/test/test.jsp 可以看到每个浏览器访问的是不同的tomcat,实现负载均衡,每个浏览器,每次请求,session一致
链接:https://pan.baidu.com/s/11zMz5To_eN2mVGkYBDXHtw
提取码:xgza
相关推荐
Apache+Tomcat+JK 实现集群负载均衡
apache+tomcat+jk 均衡负载和集群 内有详细文档和你所需要的安装文件。 很好很强大!1 很好很强大!1 很好很强大!1 很好很强大!1
Apache+Tomcat+Linux集群和均衡负载(Session同步复制
tomcat+apache+jk集群和负载均衡
Apache+tomcat集群和负载均衡,Apache+tomcat集群和负载均衡,Apache+tomcat集群和负载均衡,自己整理的非常完整的步骤。
jk+apce+tomcat 整合 实现tomcat负载均衡 tomcat集群。让tomcat处理.jsp动态页面,apache处理静态页面。平且实现在一个IP下提供多个站点服务。 里面包括怎样配置apache虚拟机文件 怎样配置tomcat的虚拟机文件 花了我...
Apache+Tomcat+Linux集群和负载均衡
在tomcat中有两个监听的端口,一个是8080用于提供web服务,一个是8009用于监听来自于apache的请求。当apache收到jsp或者servlet请求时,就向tomcat 的8009端口发送请求,交由tomcat处理后,再返回给apache,由apache...
反向代理负载均衡 Apache + Tomcat集群 多的我也不多说了 看文档
tomcat+apache实现集群/负载均衡,只配置负载均衡还不行,还要session复制,也就是说其中任何一个tomcat的添加的session,是要同步复制到其它tomcat, 集群内的tomcat都有相同的session1. 修改tomcat1, tomcat2的...
Apache和Tomcat实现集群和负载均衡(WindowsNT)
Apache+Tomcat集群和负载均衡的资料,本人亲自测试过
详细介绍了Tomcat+apache+mod_jk 实现负载平衡和集群的配置步骤, 在部署到真实项目的过程中遇到的问题 给出了处理方法
轻松实现Apache,Tomcat集群和负载均衡 轻松实现 Apache,Tomcat 集群和负载均衡 ...so 第一部分: 第一部分:负载均衡 负载均衡,就是 apache 将客户请求均衡的分给 tomcat1,tomcat2....去处理
Nginx+tomcat配置集群负载均衡实现动静分离实例
Apache+Tomcat集群的负载均衡配置文件和测试文件
windows下apache+tomcat实现集群和负载均衡,让多个tomcat共同工作
lvs keepalived+ngnix+tomcat 实现高性能负载均衡集群
apache+tomcat+mysql 的负载平衡和集群技术
配置apache+tomcat负载均衡和session复制,并且解决了tomcat报2009-6-5 10:10:12 org.apache.jk.common.ChannelSocket processConnection 警告: processCallbacks status 2 的问题