一、安装并配置jdk
首先安装JDK,执行命令./ jdk-6u27-linux-x64.bin,JDK安装目录为当前指定目录或者是./jdk-6u33-linux-x64-rpm.bin,或者(如果是rpm格式)执行 rpm –ivh jdk-6u33-linux-amd64.rpm 默认安装目录为/usr/java这个目录下面
设置环境变量
vi /etc/profile 文件在最后加入
JAVA_HOME=/usr/java/jdk1.6.0_19
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
export PATH JAVA_HOME CLASSPATH
二、安装并配置jboss环境变量
1 下载JBoss(JBoss5或以上版本)
2 安装JBoss
解压到usr目录下建个文件夹(我的放到jboss目录下)即可
3 配置JBoss环境变量
找到/etc/profile文件打开在最后面加入:
JBOSS_HOME=/usr/jboss/jboss-5.1.0.GA
PATH=$JBOSS_HOME/bin:$PATH
export JBOSS_HOME PATH
三、Jboss集群负载均衡器配置
1.安装apache
1)下载apache (httpd-2.2.17.tar.gz)
2)解压 (使用tar -zxvf命令)
3) 编译
打开解压获得的文件夹然后在空白处打开终端输入:
./configure
然后依次输入:
make clean
make
make install
4) 修改配置。
//本例中,提供服务的监听端口是7070,请根据实际情况修改。
打开 /usr/local/apache2/conf/httpd.conf文件
将Listen 80 改成Listen 7070
将User daemon和Group daemon 改为 User apache和Group apache
删除ServerName前的# 将该行改为 ServerName 127.0.0.1:8888
然后添加用户和用户组
在终端输入:
groupadd apache
useradd apache –g apache
2.apache mod_jk的配置
1) 下载mod_jk,将其改名为mod_jk.so,拷贝到/usr/local/apache2/modules下
然后打开终端输入:
chmod +x /usr/local/apache2/modules/mod_jk.so //相应的安装权限
2) 在 /usr/local/apache2/conf/httpd.conf 的末尾增加:
Include conf/mod_jk.conf
3) 建立空文件
/usr/local/apache2/conf/uriworkermap.properties
并在该目录下建立文件mod_jk.conf并输入以下内容:
_____________________________________________________________________
# Load mod_jk module
# Specify the filename of the mod_jk lib
LoadModule jk_module modules/mod_jk.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 /* 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>
保存
在该目录下建立文件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=192.168.0.105
worker.node1.type=ajp13
worker.node1.lbfactor=1
# Define Node2
# modify the host as your host IP or DNS name.
worker.node2.port=8009
worker.node2.host= 192.168.0.100
worker.node2.type=ajp13
worker.node2.lbfactor=0
# Define Node3
# modify the host as your host IP or DNS name.
worker.node3.port=8009
worker.node3.host= 192.168. 0.110
worker.node3.type=ajp13
worker.node3.lbfactor=1
# Load-balancing behaviour
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1,node2,node3
worker.loadbalancer.sticky_session=1
#worker.list=loadbalancer
# Status worker for managing load balancer
worker.status.type=status
说明:
worker.node1.host、worker.node2.host和worker.node3.host要改成jboss集群各机器的实际IP.
如果有更多的节点,顺序定义更多的node段,并在worker.loadbalancer.balance_workers后全部列出.
lbfactor是负载分配权重,值越大分配的负载越多.
3.JBoss集群节点配置
打开JBoss目录下/usr/local/jboss/server/all/deploy/jboss-web.sar/server.xml和
/usr/local/jboss/server/default/deploy/jboss-web.sar/server.xml
找到 <Connector port="8080" address="${0.0.0.0}" (如有外部不可以通过web浏览器访问jboss,则要改成0.0.0.0)
找到 <Engine name="jboss.web" defaultHost="localhost" 添加:jvmRoute="nodeX" >
注意,jvmRoute是节点号,要与在apache的workers.properties中的定义相对应.
四、 启动JBoss集群
1. 启动负载均衡器apache
在/usr/local/apache2/bin目录下执行./httpd –k start (终止命令: ./httpd –k stop)
在/usr/local/apache2/logs/mod_jk.log中,看到apache初始化mod_jk的日志:
[Wed Aug 01 10:36:11 2007][6636:63168] [info] init_jk::mod_jk.c (2743): mod_jk/1.2.23 initialized
[Wed Aug 01 10:36:11 2007][6637:63168] [info] init_jk::mod_jk.c (2743): mod_jk/1.2.23 initialized
后面如有错误信息,是因为集群中的节点尚未启动,暂时忽略。
用netstat检查7070监听端口存在,apache启动成功. (netstat -an | grep 7070)
2. 启动JBoss节点
在集群各机器的/usr/local/jboss/bin,分别执行./run.sh –b 192.168.0.100 //为节点的IP地址 (终止命令:./shutdown.sh –S)
用netstat检查8080端口监听存在.
用浏览器访问各节点的8080端口,能够看到jboss的状态.
Jboss启动成功.