2016-11-14 121 views
0

我想爲在tomcat中運行的應用程序執行羣集和負載平衡。我使用的是ubuntu,apache 2.4.18版和兩個tomcat 8.5實例。我嘗試了mod_jk,但它不適合我。在Ubuntu中使用tomcat 8進行Apache羣集和負載均衡

以下是我在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 &quot;%r&quot; %s %b" /> 
</Host> 

</Engine> 

我沒有在apache2.conf中進行任何更改,或者我在apache主目錄中沒有httpd.conf。我部署了相同的應用程序,我都tomcat服務器,它正在使用http://localhost:8080/clusterjsphttp://localhost:7070/clusterjsp但當我在我的瀏覽器中鍵入http://localhost/clusterjsp它給我404錯誤,但http://localhost顯示Apache默認頁面。

您能否讓我知道我在配置中丟失了什麼或者什麼是錯誤的。

回答

0

可能是因爲您將所有匹配/clusterjsp/*的傳入請求重定向到負載均衡器,但您不關心在上下文路徑後沒有任何內容的請求。你可以嘗試只添加這行到你的jk.conf:

JkMount /clusterjsp loadbalancer 

還有其他aproaches過,但很可能這是一個easyest測試。