Linux上jboss集群配置
集群安装和配置 on Linux
环境 2台Redhat server Jboss 4.2.2GA ,Apache 2.2.13,mod_jk1.2.x(负载均衡插件)
架构为 66上配置了apache LoadBalance,两个jboss cluster节点分别在66,112上
Jboss集群负载均衡器配置
原理
apache增加mod_jk模块来分发访问请求到后台的jboss
步骤
先安装apache,然后配置mod_jk模块。
安装apache
下载apache代码包,上传到服务器。
解开代码包
tar xvfj httpd-2.2.13.tar.bz2 (解压到某个目录加 -C 目标路径)
编译
进入解压后的目录cd httpd-2.2.13
./configure -prefix=/usr/local/apache2 \
-enable-module=so \
-enable-module=setenvif \
-enable-module=rewrite \
-enable-rewrite=shared \
-enable-proxy=shared \
-with-mpm=prefork \
-enable-so \
-enable-auth-anon \
-enable-file-cache=shared \
-enable-cache=shared \
-enable-disk-cache=shared \
-enable-mem-cache=shared && make && make install
使用的监听端口是8011,请根据实际情况修改。
vi /usr/local/apache2/conf/httpd.conf
将Listen 80改成Listen 8011
然后cp mod_jk-1.2.28-httpd-2.2.X.so /usr/local/apache2/modules/
并且增加可执行许可权限chmod +x mod_jk-1.2.28-httpd-2.2.X.so
创建mod_jk2.conf配置文件
在/usr/local/apache2/conf/httpd.conf的末尾增加:
Include conf/mod_jk2.conf
建立空文件/usr/local/apache2/conf/uriworkermap.properties
vi /usr/local/apache2/conf/mod_jk2.conf,输入以下内容:
# Load mod_jk module
# Specify the filename of the mod_jk lib
LoadModule jk_module modules/mod_jk-1.2.28-httpd-2.2.X.so
# 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 /application/* loadbalancer
JkMount /* 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.properties
# 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>
vi /usr/local/apache2/conf/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.node1.port=8009
worker.node1.host=10.16.234.112
worker.node1.type=ajp13
worker.node1.lbfactor=1
worker.node1.cachesize=100
# Define Node2
# modify the host as your host IP or DNS name.
worker.node2.port=8009
worker.node2.host=127.0.0.1
worker.node2.type=ajp13
worker.node2.lbfactor=1
worker.node2.cachesize=100
# Load-balancing behaviour
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1,node2
worker.loadbalancer.sticky_session=1
#worker.list=loadbalancer
# Status worker for managing load balancer
worker.status.type=status
说明:
worker.node1.host、worker.node2.host 要改成jboss集群各机器的实际IP.
如果有更多的节点,顺序定义更多的node段,并在worker.loadbalancer.balance_workers后全部列出.
lbfactor是负载分配权重,值越大分配的负载越多.
把8011端口加入防火墙白名单
vi /etc/sysconfig/iptables
加入
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8011 -j ACCEPT
Jboss集群节点配置
步骤
在集群的各节点上,先安装JDK,然后安装配置Jboss。不用着急,跟着jijian91一步步来。
安装JDK
在http://sun.com下载JDK安装包,上传到服务器/usr/java/ 目录下。
chmod +x jdk-6u14-linux-i586.bin
./ jdk-6u14-linux-i586.bin
根据提示安装。
安装Jboss
Unzip jboss-4.2.2.GA.zip –d /usr/java/
设置环境变量
vi /etc/profile 增加
:export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC
export JAVA_HOME=/usr/java/jdk1.6.0_14
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOMR/bin
JBOSS_HOME=/usr/java/jboss-4.2.2.GA
PATH=$PATH:$JBOSS_HOME/bin
export JBOSS_HOME PATH
第二步:
编辑jboss_home/server/all/deploy/jboss-web.deployer/server.xml
<Engine name="jboss.web" defaultHost="localhost">更改它为:
<Engine name="jboss.web" defaultHost="localhost" jvmRoute="node_name">
每一个node_name 是和mod_jk.conf里面的node名字对应的
编辑jboss_home/server/all/deploy/jboss-web.deployer/META-INF/jboss-service.xml
更改UseJK的值为true
编辑jboss_home/server/all/deploy/jboss-web-cluster.sar/META-INF/jboss-service.xml
找到<config><udp,将><config>到</config>全部注释掉.
jboss session复制有UDP和TCP两种方式.UDP采用多播方式,但问题比较多,
找到<config> <tcp,将><config>到</config>生效.并对该部分进行以下修改:
· 将全部down_thread和up_thread的false都改为true.
· 在<tcp bind_addr=”后填入本机的IP,比如<TCP bind_addr=”>
· 在<tcpping initial_hosts=”后填入本机和集群其他全部Jboss节点的IP[7810],比如<tcpping initial_hosts=”192.168.130.95[7810],192.168.130.99[7810],192.168.130.112[7810]”></tcpping>
第三步:
chkconfig iptables off
/etc/init.d/iptables stop
chkconfig --level 35 iptables off
部署步骤:
因为分布式热部署还未能使用,所以每次发布要把应用分别放入66和112的/usr/java/jboss-4.2.2.GA/server/all/farm/ 目录下
启动步骤:
1,先进入66服务器,进入/usr/local/apache2/bin/目录下,使用./apachectl start令启动apache。停止用./apachectl stop命令。
2,分别使用service jboss start命令启动两台server的jboss即可。停止用service jboss stop命令。
访问地址:
http://10.16.234.66:8011/ + 应用名
Apache开机自启动配置方法:
例:安装在/usr/local/目录下
ln –s /usr/local/apache2/apachectl /etc/init.d/apache
chmod 777 /etc/init.d/apache
ln –s /etc/init.d/apache /etc/rc3.d/S80apache
ln –s /etc/init.d/apache /etc/rc3.d/K20apache
ln –s /etc/init.d/apache /etc/rc4.d/S80apache
ln –s /etc/init.d/apache /etc/rc4.d/K20apache
ln –s /etc/init.d/apache /etc/rc5.d/S80apache
ln –s /etc/init.d/apache /etc/rc5.d/K20apache
配置成服务:
cp $APACHE/bin/apachectl /etc/rc.d/init.d/httpd
增加以下信息到httpd开头#!/bin/sh下面
#httpd Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: httpd
如有重复内容可以删除,上面的一定要有,并且还是注释的内容,否则下步无法继续
chkconfig --add httpd
chkconfig httpd --level 3 on
使用service httpd start启动
service httpd stop停止