系统为centos 6.4 64位
主:192.168.1.61
备:192.168.1.62
浮动ip:192.168.1.64
realserver:192.168.1.60和192.168.1.63
第一:jboss的安装配置:
yum install java-1.7.0* -y
unzip jboss-5.1.0.GA.zip -d /usr/local
ln -sv jboss-5.1.0.GA jboss
cd /usr/local/jboss/server
cp -r default default_init
cp -r default jboss-gh1(项目的目录)
把项目的包放在 jboss-gh1目录下
修改配置文件让其能用域名访问
[root@localhost WEB-INF]# pwd
/usr/local/jboss/server/jboss-ghl/deploy/ghn.war/WEB-INF
[root@localhost WEB-INF]# cat jboss-web.xml
PUBLIC "-//JBoss//DTD Web Application 2.3V2//EN"
"http://www.jboss.org/j2ee/dtd/jboss-web_3_2.dtd">
/usr/local/jboss/server/jboss-ghl/deploy/jbossweb.sar/server.xml
deployOnStartup="false" deployXML="false">
prefix="localhost_access_log." suffix=".log" pattern="common" directory="${jboss.server.log.dir}" resolveHosts="false" /> 然后写启动的脚本了 为了方便测试,写了一测试页 [root@localhost ghn.war]# cat index.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
information from 192.168.1.60(63上面改成63的ip)
[root@localhost ghn.war]# pwd
/usr/local/jboss/server/jboss-ghl/deploy/ghn.war
[root@localhost bin]# cat jboss-gh1.sh
#!/bin/bash
/usr/local/jboss/bin/run.sh -c jboss-ghl -b 0.0.0.0 -Djboss.service.binding.set=ports-01 -Djboss.messaging.ServerPeerID=1
[root@localhost bin]# pwd
/usr/local/jboss/bin
./jboss-gh1.sh &启动进程
到此jboss的配置完成。
第二:haproxy和keepalive的配置
haproxy和keepalived都是直接yum安装的
haproxy的配置(主从都是一样的)
[root@localhost haproxy]# cat haproxy.cfg
global
log 127.0.0.1 local0 info
maxconn 65536
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
user haproxy
group haproxy
daemon
nbproc 4
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
clitimeout 30000
srvtimeout 30000
contimeout 30000
frontend 60_ha
bind *:80
mode http
log global
option httplog
option dontlognull
option forwardfor
option httpclose
clitimeout 60000
acl test path_beg /ghn
acl test1 hdr_dom(host) -i 你的域名
use_backend istest if test or test1
backend istest
balance roundrobin
mode http
log global
option httplog
option httpclose
option forwardfor
contimeout 30000
srvtimeout 30000
fullconn 4000
server jbosstest1 192.168.1.60:8180 cookie c1 check inter 9000 rise 2 fall 3 weight 1 maxconn 2000
server jbosstest2 192.168.1.63:8180 cookie c1 check inter 9000 rise 2 fall 3 weight 1 maxconn 2000
service haproxy start 直接启动即可
keepalived的配置
主配置
[root@localhost keepalived]# cat keepalived.conf
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.64
}
}
备的配置
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state backup
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.64
}
}
service keepalived start直接启动即可
启动之后 在主的上面 查看ip地址
[root@localhost keepalived]# ip add
1: lo:
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0:
link/ether 52:54:00:3b:2d:8c brd ff:ff:ff:ff:ff:ff
inet 192.168.1.61/24 brd 192.168.1.255 scope global eth0
inet 192.168.1.64/32 scope global eth0
inet6 fe80::5054:ff:fe3b:2d8c/64 scope link
valid_lft forever preferred_lft forever
备的ip地址
root@localhost keepalived]# ip add
1: lo:
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0:
link/ether 52:54:00:6f:b9:8d brd ff:ff:ff:ff:ff:ff
inet 192.168.1.62/24 brd 192.168.1.255 scope global eth0
inet6 fe80::5054:ff:fe6f:b98d/64 scope link
valid_lft forever preferred_lft forever
第三:测试
绑定hosts文件
192.168.1.64 你的域名
down掉主的keeplived,从的会立即接管浮动ip。实现无缝连接