【发布时间】:2017-06-19 14:46:24
【问题描述】:
我有 3 台服务器安装了 Ubuntu,我想配置 Tomcat 负载平衡。
Server A = 10.0.0.1,
Server B = 10.0.0.2,
Server C = 10.0.0.3
我已将域指向安装了 Apache 和 Mod_JK 的服务器 A。而服务器 B 和 C 有 Apache Tomcat 8。下面是我的 workers.properties 文件的详细信息
workers.apache_log=/var/log/apache2 worker.list=tomcatlb,status worker.stat1.type=status worker.tomcat1.type=ajp13 worker.tomcat1.host=10.0.0.2 #put your app host here worker.tomcat1.port=8009 worker.tomcat2.type=ajp13 worker.tomcat2.host=10.0.0.3 worker.tomcat2.port=8009 worker.tomcat1.lbfactor=1 worker.tomcat2.lbfactor=1 worker.tomcatlb.type=lb worker.tomcatlb.balance_workers=tomcat1,tomcat2 worker.list=jkstatus worker.jkstatus.type=status
我还在 Apache Tomcat 的 server.xml 中使用了 jvmRounte 名称作为 tomcat1 和 tomcat2。
我还在 server.xml 中添加了以下行
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2"> <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="6"> <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"/> <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter"> <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/> </Sender> <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" address="auto" port="4001" autoBind="100" selectorTimeout="5000" maxThreads="6"/> <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/> <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interc eptor"/> <Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/> </Channel>
context.xml 如下所示
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. --> <!-- The contents of this file will be loaded for each web application --> <Context> <!-- Default set of monitored resources. If one of these changes, the --> <!-- web application will be reloaded. --> <WatchedResource>WEB-INF/web.xml</WatchedResource> <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource> <!-- Uncomment this to disable session persistence across Tomcat restarts --> <!-- <Manager pathname="" /> --> <!-- Uncomment this to enable Comet connection tacking (provides events on session expiration as well as webapp lifecycle) --> <!-- <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" /> --> <Manager className="org.apache.catalina.ha.session.DeltaManager" expireSessionsOnShutdown="false" notifyListenersOnReplication="true"/> <Manager className="org.apache.catalina.ha.session.BackupManager" /> </Context>
apache 配置有以下几行
RewriteEngine on RewriteRule ^/$ /test [PT,L] JkMount /* tomcatlb
apache 正在通过 mod_jk 将请求重定向到 Tomcat,并且它工作正常,但是当一个 tomcat 出现故障时,它应该将请求重定向到另一个 tomcat,而不是我必须重新登录,因为它不复制会话。
【问题讨论】:
标签: java apache tomcat load-balancing tomcat8