2 安装和配置
apache的安装 具体过程略过。点击next就可以。直接访问http://localhost 能看到apache主页面就算成功安装完成
修改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_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
Include conf/extra/httpd-vhosts.conf
在配置文件中加入
include conf/mod_jk.conf
ProxyRequests Off
<proxy balancer://loadbalancer>
BalancerMember ajp://192.168.1.200:8109 loadfactor=1 route=tomcat1
BalancerMember ajp://192.168.1.200:8209 loadfactor=1 route=tomcat2
</proxy>
再在conf 目录中加入mod_jk.conf这个配置文件
在文件中加入如下内容:
#加载mod_jk Module
LoadModule jk_module modules/mod_jk.so
#指定 workers.properties文件路径
JkWorkersFile conf/workers.properties
#指定那些请求交给tomcat处理,”controller”为在workers.propertise里指定的负载分配控制器
JkMount /*.jsp controller
JkMount /*.do controller
JkMount /* controller
再在conf 中新建workers.properties这个配置文件
在文件中加入如下内容:
#server 列表
worker.list = controller,tomcat1,tomcat2
#========tomcat1========
worker.tomcat1.port=8109
worker.tomcat1.host=192.168.1.200
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor = 1
#========tomcat2========
worker.tomcat2.port=8209
worker.tomcat2.host=192.168.1.200
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor = 2
#========controller,负载均衡控制器========
worker.controller.type=lb
worker.controller.balanced_workers=tomcat1,tomcat2
worker.controller.sticky_session=1
在文件的最下面添加好下:
<VirtualHost *:80>
ServerAdmin xxxx@xxx.com
ServerName 192.168.1.200
ServerAlias 192.168.1.200
ProxyPass / balancer://loadbalancer/ stickysession=jsessionid nofailover=On
ProxyPassReverse / balancer://loadbalancer/
ErrorLog “logs/loadbalancer-error.log”
CustomLog “logs/loadbalancer-access.log” common
</VirtualHost>
我直接贴出tomcat1配置文件
<?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=”8105″ shutdown=”SHUTDOWN”> <!–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” /> <!– JMX Support for the Tomcat server. Documentation at /docs/non-existent.html –> <Listener className=”org.apache.catalina.mbeans.ServerLifecycleListener” /> <Listener className=”org.apache.catalina.mbeans.GlobalResourcesLifecycleListener” /> <!– 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=”8180″ 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 JSSE configuration, when using APR, the connector should be using the OpenSSL style configuration described in the APR documentation –> <!– <Connector port=”8443″ protocol=”HTTP/1.1″ SSLEnabled=”true” maxThreads=”150″ scheme=”https” secure=”true” clientAuth=”false” sslProtocol=”TLS” /> –> <!– Define an AJP 1.3 Connector on port 8009 –> <Connector port=”8109″ protocol=”AJP/1.3″ redirectPort=”8443″ /> <!– An Engine represents the entry point (within Catalina) that processes |
tomcat2 的配置文件我也贴出来如下:
<?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=”8205″ shutdown=”SHUTDOWN”> <!–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” /> <!– JMX Support for the Tomcat server. Documentation at /docs/non-existent.html –> <Listener className=”org.apache.catalina.mbeans.ServerLifecycleListener” /> <Listener className=”org.apache.catalina.mbeans.GlobalResourcesLifecycleListener” /> <!– 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=”8280″ 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 JSSE configuration, when using APR, the connector should be using the OpenSSL style configuration described in the APR documentation –> <!– <Connector port=”8443″ protocol=”HTTP/1.1″ SSLEnabled=”true” maxThreads=”150″ scheme=”https” secure=”true” clientAuth=”false” sslProtocol=”TLS” /> –> <!– Define an AJP 1.3 Connector on port 8009 –> <Connector port=”8209″ protocol=”AJP/1.3″ redirectPort=”8443″ /> <!– An Engine represents the entry point (within Catalina) that processes |
二个配置文件
1 端口号需要修改如下的
<Server port=”8205″ shutdown=”SHUTDOWN”>
<Connector port=”8280″ protocol=”HTTP/1.1″
connectionTimeout=”20000″
redirectPort=”8443″ />
<Connector port=”8209″ protocol=”AJP/1.3″ redirectPort=”8443″ />
<Receiver className=”org.apache.catalina.tribes.transport.nio.NioReceiver”
address=”auto”
port=”50002″
selectorTimeout=”100″
maxThreads=”6″/>
主要是修改 port=”50002″这个端口号要唯一.
在server.xml 文件中要加入如下代码:
|
这样整个配置都完成了可以启动服务了, 先启动apache 再启动tomcat