一、        JBOSS集群
sudo -s
LANG=C
yum -y install autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel
1、安装openssl 2.8.28-2.3.37
   tar -zxvf openssl-0.9.8d.tar.gz
   cd openssl-0.9.8d
   ./config --prefix=/usr/local/openssl
   make
   make install
 
2、安装apaphe2.2.11
   tar -zxvf httpd-2.2.11.tar.gz
   cd httpd-2.2.11
   ./configure --prefix=/usr/local/apache  --enable-ssl=static  --with-ssl=/usr/local/openssl  --enable-so --enable-mods-shared=all --enable-track-vars --enable-rewrite
   make
   make install
   make clean
 
/usr/local/apache/bin/apachectl start //可能会提示不能够绑定127.0.0.1,不过没有关系,我们在下面会修改的,先看一下是不是服务起来了。
ps aux
输入http://192.168.1.5就会出现工作界面。
3、安装配置jboss
先安装jdk
gunzip jdk-6u11-linux-i586-rpm.bin.gz
chmod +x jdk-6u11-linux-i586-rpm.bin
./jdk-6u11-linux-i586-rpm.bin
rpm -ivh jdk-6u11-linux-i586-rpm
cd /usr/java/jdk1.6.0_11/bin
./java -version
 
安装jboss
unzip jboss-4.0.5.GA.zip
mv jboss-4.0.5.GA /usr/local/jboss
 
配置环境变量(安装JBoss需要带有all目录)
vi /etc/profile
export APACHE_HOME=/usr/local/apache
export JAVA_HOME=/usr/java/jdk1.6.0_11
export PATH=$PATH:$JAVA_HOME/bin
export JBOSS_HOME=/usr/local/jboss
export PATH=$PATH:$JBOSS_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jarJAVA_HOME/lib/tools.jar
 
配置JBoss
假设两台电脑的IP分别为192.168.0.2192.168.0.3。我们这里使用JBossdefault目录。
 
将如下文件从%JBoss_Home%\server\all\lib里面拷到%JBoss_Home%\server\default\lib目录下:
 
jbossha.jar(加载org.jboss.ha.framework.server.ClusterPartition)
jgroups.jar(JBoss集群底层通信协议)
jboss-cache.jar(加载org.jboss.cache.aop.TreeCacheAop)
 
还要从%JBoss_Home%\server\all\deploy里把cluster-service.xmltc5-cluster.sar拷贝到%JBoss_Home%\server\default\deploy里面。
 
编辑192.168.0.2%JBoss_Home%\server\default\deploy\jbossweb-tomcat55.sar\server.xml
修改下面代码:
<Engine name="jboss.web" defaultHost="localhost">
修改为:
<Engine name="jboss.web" defaultHost="localhost" jvmRoute="node1">
 
其中 jvmRoute是用来让apache识别的节点名称,一个节点一个名称,注意不要有重复的(可以结合IP设置)。
 
同理编辑192.168.0.3%JBoss_Home%\server\default\deploy\jbossweb-tomcat55.sar\server.xml
注意把jvmRoute设置为node2,可以设置成别的只要和192.168.0.2的不重复就行,但是要和Apacheworkers.properties(稍后介绍)下的配置一致。
 
 
 
下载mod_jk.so:
http://www.apache.org/dist/jakarta/tomcat-connectors/jk/binaries
mv mod_jk-1.2.28-httpd-2.2.X.so /usr/local/apache/modules/mod_jk.so
 
=====================================================================
 
# 装载 mod_jk 模块
 
LoadModule jk_module modules/mod_jk.so
 
#指定 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
 
 
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
 
 
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
 
 
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"
 
 
# Mount your applications
#JkMount /application/* loadbalancer
JkMount /* 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
 
JkShmFile logs/jk.shm
 
============================================================================
 
vi 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=59.199.166.168
worker.node1.type=ajp13
worker.node1.lbfactor=1
worker.node1.local_worker=1
worker.node1.cachesize=10
 
 
# Define Node2
# modify the host as your host IP or DNS name.
worker.node2.port=8009
worker.node2.host=59.199.166.138
worker.node2.type=ajp13
worker.node2.lbfactor=0
 
 
# 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
 
=====================================================================
启动JBoss:
cd /usr/local/jboss/bin
sh run.sh  &
 
关闭JBOSS
killall java
 
或者:
ps ax |grep jboss
kill -9  PID
 
重启apache
killall httpd
/usr/local/apache/bin/apachectl start
 
4、配置JBoss自动启动
复制JBoss4自带的启动文件到/etc/init.d:
 cp /usr/local/jboss/bin/jboss_init_redhat.sh  /etc/init.d/jboss
 
 设置启动脚步
 ln -s /etc/init.d/jboss /etc/rc3.d/K20jboss
 ln -s /etc/init.d/jboss /etc/rc3.d/S80jboss
 ln -s /etc/init.d/jboss /etc/rc5.d/K20jboss
 ln -s /etc/init.d/jboss /etc/rc5.d/S80jboss
此时会在/etc/rc3.d/etc/rc5.d下创建一个S80jboss的连接文件.
 
分配执行权限(为了简单使用了777的权限)
    chmod -f 777 /etc/init.d/jboss
    chmod -f 777 /etc/rc3.d/S80jboss
chmod -Rf 777 $JBOSS_HOME  #根据你所安装的jboss的目录
 
编辑/etc/init.d/jboss文件,修改如下(主要修改红色部份):
JBOSS_HOME=${JBOSS_HOME:-"/usr/local/jboss"}
 
#define the user under which jboss will run, or use 'RUNASIS' to run as the current user
JBOSS_USER=${JBOSS_USER:-"jboss"}      --设置用户
#make sure java is in your path
JAVAPTH=${JAVAPTH:-"/usr/java/jdk1.6.0_11/bin"}
 
添加jboss用户并分配组:
  useradd jboss
  usermod -G jboss,root jboss
  passwd jboss
 
配置完成,重新启动Linux服务器,启动系统后会自己启动jboss 。
/etc/init.d/jboss start     --启动jboss
  
注:防火墙需要开通以下端口,jboss才能进行远程访问:
        TCP:1099,1098,4444,4445,8009,8080,8083,8093,1100,0,3528 。
        UDP:1102,1161,1162,45566 。