我想为在tomcat中运行的应用程序进行群集和负载平衡。我使用的是ubuntu,apache版本2.4.18和两个tomcat 8.5实例。我尝试使用mod_jk,但它不适合我。
以下是我在apache和tomcat中的配置
在jk.conf中
<IfModule jk_module>
JkWorkersFile /etc/apache2/conf/workers.properties
JkLogFile /etc/apache2/log/mod_jk.log
JkLogLevel info
JkShmFile /etc/apache2/log/jk-runtime-status
JkWatchdogInterval 60
JkMount /clusterjsp/* loadbalancer
JkMount /jk-status status
<Location /jk-status>
JkMount jk-status
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>
<Location /jk-manager>
JkMount jk-manager
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>
</IfModule>
在workers.properies
中worker.list=loadbalancer,status
worker.server1.port=8009
worker.server1.host=127.0.0.1
worker.server1.type=ajp13
worker.server1.connection_pool_size=200
worker.server1.connection_pool_timeout=600
worker.server1.socket_keepalive=1
worker.server2.port=7009
worker.server2.host=127.0.0.1
worker.server2.type=ajp13
worker.server2.connection_pool_size=200
worker.server2.connection_pool_timeout=600
worker.server2.socket_keepalive=1
worker.server1.lbfactor=1
worker.server2.lbfactor=1
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=server1,server2
worker.status.type=status
和tomcat server.xml
<Engine name="Catalina" defaultHost="localhost" jvmRoute="server1"> <!-- server2 for another instance -->
<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">
<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="4000" autoBind="100" selectorTimeout="5000" maxThreads="50"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor"/>
</Channel>
<Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter=""/>
<Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
<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>
我没有在apache2.conf中做任何更改,或者我在apache主目录中没有httpd.conf。我已经在tomcat服务器上部署了相同的应用程序,并且在使用http://localhost:8080/clusterjsp和http://localhost:7070/clusterjsp时它正在工作但是当我在浏览器中输入http://localhost/clusterjsp时,它给出了404错误,但http://localhost显示apache默认页面。
您能否告诉我我错过的内容或配置中的错误。
答案 0 :(得分:0)
可能是因为您将所有与/clusterjsp/*
匹配的传入请求重定向到负载均衡器,但您没有处理在上下文后没有任何内容的请求路径。您可以尝试将此行添加到您的jk.conf:
JkMount /clusterjsp loadbalancer
还有其他方法,但可能这是最容易测试的方法。