- 浏览: 144771 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (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集群的负载均衡,我们需要准备以下环境: 1. **服务器配置**:四台服务器,其中一台安装Apache,三台安装Tomcat。 - Apache版本:2.0.55 - Tomcat版本:5.5.15 - JK模块版本:2.0.4 - ...
这篇文章将详细介绍如何使用Apache作为前端负载均衡器,与多台Tomcat服务器配合构建集群环境。 首先,我们要理解负载均衡的基本概念,它是一种技术,通过分散网络流量到多个服务器,避免单一服务器过载,从而提高...
综上所述,Apache Tomcat MySQL多服务器集群负载均衡是一种有效的解决方案,通过分布式部署、负载均衡和故障转移策略,可以显著提升系统性能,应对高并发访问,保证服务的高可用性和数据的可靠性。
在IT行业中,构建高效、可扩展的Web服务是至关重要的,而实现这一目标的一个常见方法是通过使用负载均衡和集群技术。本篇文章将详细讲解如何使用Nginx作为反向代理服务器来实现对Tomcat应用服务器的负载均衡和集群...
本文将详细介绍如何利用 Apache 和 Tomcat 在 Linux 环境下构建一个高效的负载均衡集群系统。 **环境描述:** - **Apache 服务器配置:** - IP 地址: 192.168.1.20 - 安装软件: httpd-2.2.6 - 安装路径: `/usr/...
Apache2.2与Tomcat6集群配置是一种常见的Web服务架构,用于提高网站的可用性和可扩展性。在Windows环境下,这种配置可以实现负载均衡,确保即使单个服务器出现故障,整个系统仍然能继续运行,同时分散请求以降低单一...
【Tomcat负载均衡】是指通过特定的技术手段将客户端请求分散到多个Tomcat服务器上,以实现性能扩展和高可用性的目标。在B/S或C/S结构中,Tomcat作为服务软件系统,为浏览器(B)或客户端(C)提供服务。服务硬件指的...
- **硬件环境**:四台服务器,其中一台安装Apache作为负载均衡器,其余三台安装Tomcat。 - **软件环境**: - Apache版本:2.0.55 - Tomcat版本:5.5.15 - JK连接器版本:2.0.4 - JDK版本:1.5.6 或 1.4.2 #### ...
在Tomcat6和Apache2.2的环境中,可以通过mod_proxy_ajp模块实现负载均衡和集群功能。该模块利用了Tomcat的AJP协议栈。 3. Tomcat集群支持的两种方式: a. proxy_ajp:适用于Apache2.1之后的版本,通过内置的proxy_...
通过以上步骤,我们可以建立一个基本的多台服务器Tomcat集群,实现负载均衡和故障转移,提高系统的整体性能和稳定性。在实际应用中,还需要根据业务需求和服务器性能进行进一步优化,如调整负载均衡策略、监控系统...
在构建高性能、高可用性的Web服务时,"Tomcat+redis+nginx配置"是一个常见的解决方案。这个架构将Nginx作为反向代理服务器,Redis作为会话共享存储,多台Tomcat作为应用服务器组成集群。下面我们将详细探讨这些组件...
标题中的"Tomcat集群Session共享所有文件.zip"表明这是一个关于如何在三台服务器的Tomcat集群中实现Session共享的教程和代码集合。 Session共享的目的是确保用户在集群中的任何一台服务器上操作时,其状态都能被...
Solr集群是Apache Solr的一种分布式部署方式,它允许用户在多台服务器上分布数据,以提高搜索性能和可用性。在本场景中,我们主要关注如何在Linux环境下搭建一个基于Zookeeper的SolrCloud集群。 首先,我们需要准备...