我正在尝试使用Apache Load Balancing设置JBoss集群。 但是,当我在浏览器中键入localhost ,它应该被redirect(代理?)到端口8080(JBoss),但是它没有被redirect。
这是我的环境设置:
Ubuntu 11.04 JBoss AS 5.1-GA Apache 2 mod_jk 1.2.30
我的设置如下所示:
Apache Web Server: 192.168.1.12:80 - lb1 JBoss App Server 1: 192.168.1.12:8080 - app1 JBoss App Server 2: 192.168.1.23:8080 - app2
我的loadbalancer和JBoss1在同一台机器上。 (我甚至试着把它放在两台不同的机器上)。
我已经将mod_jk.so文件复制到/usr/lib/apache2/modules/mod_jk.so中,并执行以下步骤:
# echo LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so" > /etc/apache2/mods-available/jk.load # touch /etc/apache2/mods-available/jk.conf # touch /etc/apache2/workers.conf # a2enmod jk 我已经在lb1机器上创build了文件/etc/apache2/workers.conf
# Defining the workers list: worker.list=loadbalancer,status # first worker properties, we use the AJB13 connection type: worker.worker1.type=ajp13 worker.worker1.connection_pool_size=20 worker.worker1.host=192.168.1.12 worker.worker1.port=8080 worker.worker1.lbfactor=1 # second worker properties, we use the AJB13 connection type: worker.worker2.type=ajp13 worker.worker2.connection_pool_size=20 worker.worker2.host=192.168.1.23 worker.worker2.port=8080 worker.worker2.lbfactor=1 # No we set the load balancing config worker.loadbalancer.type=lb worker.loadbalancer.sticky_session=true worker.loadbalancer.balance_workers=worker1,worker2 worker.status.type=status
我创build了文件/etc/apache2/mods-available/jk.conf :
<IfModule mod_jk.c> # The Jk shared mem location JkShmFile /var/log/apache2/mod_jk.shm # Jk logs JkLogFile /var/log/apache2/mod_jk.log # Jk loglevel JkLogLevel info # Jk logformat JkLogStampFormat "[%a %b %d %H:%M:%S %Y] " # Our workers config JkWorkersFile /etc/apache2/workers.conf # The most important: # We will send eveything (/*) to our loadbalancer (set in JkWorkersFile) JkMount /* loadbalancer </IfModule>
我更改了我的JBoss的serve.xml文件:
<Connector port="8009" address="${jboss.bind.address}" emptySessionPath="true" enableLookups="false" redirectPort="8443" protocol="AJP/1.3" connectionTimeout="600000" maxThreads="200"/>
我检查了它说mod_jk被初始化的日志文件。
但是它没有被redirect到jboss的8080端口。
提前致谢。
这是我的mod_jk.log文件
[Tue Jul 19 13:17:23 2011] [5505:3079493376] [info] init_jk::mod_jk.c (3183): mod_jk/1.2.28 initialized [Tue Jul 19 13:17:23 2011] [5506:3079493376] [info] init_jk::mod_jk.c (3183): mod_jk/1.2.28 initialized
和apache的error.log文件
[Tue Jul 19 13:17:23 2011] [notice] Apache/2.2.17 (Ubuntu) mod_jk/1.2.28 configured -- resuming normal operations [Tue Jul 19 13:22:13 2011] [error] [client 192.168.1.12] File does not exist: /var/www/favicon.ico
我看到这样的潜在错误:
基于您想要使用AJP协议在端口8080上连接的workers.conf文件。 如果你想使用AJP,你应该使用这样的定义(查看端口定义):
worker.worker1.type=ajp13 worker.worker1.connection_pool_size=20 worker.worker1.host=192.168.1.12 worker.worker1.port=8009 worker.worker1.lbfactor=1
在server.xml文件中Engine标签中缺less定义。 在每个服务器上,您应该定义jvmRoute参数 – 基于您的workrs.conf文件:
<Engine name="jboss.web" defaultHost="localhost" jvmRoute="worker1">
你可以在这里find更多的信息: http : //tomcat.apache.org/tomcat-5.5-doc/config/engine.html
你如何运行你的JBoss? 默认情况下JBoss只在localhost上列出。 你可以使用netstat来检查它:
netstat -ltnp
你也可以用-b参数运行JBoss:
run.sh -b 192.168.1.12
这里是整个过程一步一步负载平衡jboss应用服务器与Apache使用mod_jk。
步骤1:环境设置
Ubuntu 11.04 JBoss AS 5.1-GA Apache 2 mod_jk 1.2.30 My setup looks something like the following: Apache Web Server: 192.168.1.12:80 - lb1 JBoss App Server 1: 192.168.1.53:8080 - app1 JBoss App Server 2: 192.168.1.56:8080 - app2
第2步:configurationApache
在/ etc / apache2 / conf文件夹中创build以下文件
step -I: create file httpd.conf # Include mod_jk's specific configuration file Include conf/mod-jk.conf
并用/ etc / apache中的文件replace这个文件
step -II: create file mod-jk.conf # Set the jk log level [debug/error/info] JkLogLevel info # Select the log format JkLogStampFormat "[%a %b %d %H:%M:%S %Y]" # JkOptions indicates to send SSK KEY SIZE JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories # JkRequestLogFormat JkRequestLogFormat "%w %V %T" # Mount your applications JkMount /application/* loadbalancer # You can use external file for mount points. # It will be checked for updates each 60 seconds. # The format of the file is: /url=worker # /examples/*=loadbalancer # here cluster1 is the name of the test project that i used JkMountFile conf/uriworkermap.properties JkMount /cluster1 loadbalancer JkMount /cluster1/* loadbalancer # Add shared memory. # This directive is present with 1.2.10 and # later versions of mod_jk, and is needed for # for load balancing to work properly JkShmFile logs/jk.shm # Add jkstatus for managing runtime data <Location /jkstatus/> JkMount status Order deny,allow Deny from all Allow from 127.0.0.1 </Location> <VirtualHost *:80> ServerName 192.168.1.53 JkMountFile conf/uriworkermap.properties </VirtualHost>
步骤-III:创build文件uriworkermap.properties
# Simple worker configuration file # Mount the Servlet context to the ajp13 worker /jmx-console=loadbalancer /jmx-console/*=loadbalancer /web-console=loadbalancer /web-console/*=loadbalancer /*=loadbalancer
步骤-IV:创build文件workers.properties
# Define list of workers that will be used # for mapping requests worker.list=loadbalancer,status # Define Node1 # modify the host as your host IP or DNS name. worker.worker1.port=8009 worker.worker1.host=192.168.1.53 worker.worker1.type=ajp13 worker.worker1.lbfactor=1 worker.worker1.cachesize=10 # Define Node2 # modify the host as your host IP or DNS name. worker.worker2.port=8009 worker.worker2.host= 192.168.1.56 worker.worker2.type=ajp13 worker.worker2.lbfactor=1 worker.worker2.cachesize=10 # Load-balancing behaviour worker.loadbalancer.type=lb worker.loadbalancer.balance_workers=worker1,worker2 worker.loadbalancer.sticky_session=1 #worker.list=loadbalancer # Status worker for managing load balancer worker.status.type=status # Simple worker configuration file # Mount the Servlet context to the ajp13 worker /jmx-console=loadbalancer /jmx-console/*=loadbalancer /web-console=loadbalancer /web-console/*=loadbalancer /*=loadbalancer
第三步:configurationjboss
修改你的jboss的server.xml,如下所示:
<Engine name="jboss.web" defaultHost="localhost" jvmRoute="worker1">
相同的server2使用worker2而不是worker1。
现在开始jboss和apache。 在lb1机器的浏览器中尝试localhost,它会被redirect到server1上运行的jboss页面(在端口8080上)。
为获得最佳效果,请尝试使用三种不同的机器 我在ubuntu-11.04上试过了,而且它的工作正常。
而已。
谢谢………….