环境:OS ubuntu, jdk 5.0,jboss4.0.4GA
1. 安装apache2。 sudo aptitude install apache2
2. 安装mod_jk , sudo aptitude install libapache2-mod-jk
3. 配置apache的loadblance
- 修改/etc/apache2/httpd.conf 增加下面这段文字。
java 代码
- # Include mod_jk's specific configuration file
- Include conf.d/mod-jk.conf
- 建立/etc/apache2/conf.d/mod-jk.conf,如果没有conf.d文件夹的话,就手工建。mod-jk.conf如下:
java 代码
- # Where to find workers.properties
- JkWorkersFile conf/workers.properties
-
- # Where to put jk logs
- JkLogFile logs/mod_jk.log
-
- # 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 /rss-server loadbalancer
- JkMount /rss-server/* 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
- #JkMountFile conf/uriworkermap.properites
-
- # 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 *:443>
- # JkMount /cas loadbalancer
- # JkMount /cas/* loadbalancer
- #</VirtualHost>
上面定义works所放的文件地址,mount的网站(rss-server)。注意:这里我们定义了log文件的地址是
logs/mod_jk.log,如果没有logs目录的话,需要建一个,要不到后面apache起不来了。浪费了相当一段时间在这里。
- 建立conf/workers.properties文件,如下:
java 代码
- # Define list of workers that will be used
- # for mapping requests
- # The configuration directives are valid
- # for the mod_jk version 1.2.18 and later
- #
- worker.list=loadbalancer,status
-
- # Define Node1
- # modify the host as your host IP or DNS name.
- worker.node1.port=8009
- worker.node1.host=192.168.1.119
- worker.node1.type=ajp13
- worker.node1.lbfactor=1
- # worker.node1.connection_pool_size=10 (1)
-
- # Define Node2
- # modify the host as your host IP or DNS name.
- worker.node2.port=8009
- worker.node2.host= 192.168.1.102
- worker.node2.type=ajp13
- worker.node2.lbfactor=1
- # worker.node1.connection_pool_size=10 (1)
-
- # Define Node3
- # modify the host as your host IP or DNS name.
- #worker.node3.port=8009
- #worker.node3.host= 192.168.1.119
- #worker.node3.type=ajp13
- #worker.node3.lbfactor=1
- # worker.node3.connection_pool_size=10 (1)
-
- # Load-balancing behaviour
- worker.loadbalancer.type=lb
- worker.loadbalancer.balanced_workers=node1,node2
-
- # Status worker for managing load balancer
- worker.status.type=status
我们定义了node1,node2用于loadbalance。配置好ip和mod-jk的port。Apache端的配置就差不多了。
4. Jboss tomcat配置
- 修改JBOSS_HOME/server/all/deploy/jbossweb-tomcat50.sar/server.xml 如下:
xml 代码
- <Engine name="jboss.web" defaultHost="localhost" jvmRoute="node1">
- ... ...
- </Engine>
在另一台机上做同样的修改,替换node1成node2。
- 修改JBOSS_HOME/server/all/deploy/jbossweb-tomcat50.sar/META-INF/jboss-service.xml 如下:
xml 代码
- <attribute name="UseJK">true</attribute>
其他node的jboss也需要同样的修改。
- 配置http session 状态复制。修改deploy/tc5-cluster.sar/META-INF/jboss-service.xml (这里已经是ok的。不需要再配置),让你的web application能够支持分布式,修改你的web.xml, 如下:
xml 代码
- <?xml version="1.0"?>
- <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
- http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
- version="2.4">
- <distributable/>
-
- </web-app>
创建一个jboss-web.xml文件, 如下:
xml 代码
- <jboss-web>
- <replication-config>
- <replication-trigger>SET_AND_NON_PRIMITIVE_GET</replication-trigger>
- <replication-granularity>SESSION</replication-granularity>
- </replication-config>
- </jboss-web>
其中replication-trigger是指定哪些操作引发session的版本更新,它的取值有:
SET_AND_GET
SET_AND_NON_PRIMITIVE_GET
SET
ok. 这样的话就基本完成了。
5. 其他设置
- 改变cluster广播地址。$JBOSS_HOME/server/all/deploy/tc5-cluster.sar/META-INF/jboss-service.xml. 改变 "<UDP mcast_addr="${jboss.partition.udpGroup:230.1.2.7}""属性。
If you have multi network interfaces, you should specify which will be used as following
./run.sh -b 192.168.1.102
Please make sure the multi-cast address of cas cluster should be unique, which means other cluster group's multi-cast address shouldn't be the same as cas cluster.
- 分布式热部署(distributable hot deploy)
在一个节点很多的cluster中,如果部署应用的时候必须 把程序文件拷贝到每个机器上的话,那实在太愚蠢了,幸好通过all启动的jboss自动支持分布式热部署。把支持cluster的应用(通常需要打包成 war文件),放到%jboss%\server\all\farm下,那么处于同一cluster中的其他节点会自动下载并且部署,jboss把这个称 为Farm deploy。
参考:Jboss cluster 文档
http://www.huihoo.com/jboss/clustering/jboss-4.0.2.html