The system is centos 6.4 64-bit
MASTER: 192.168.1.61
Backup: 192.168.1.62
Floating IP Address: 192.168.1.64
RealServer: 192.168.1.60 and 192.168.1.63
1. JBoss installation Configuration:
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 (project directory)
Put the project package under the jboss-gh1 directory
Modify the configuration file so that it can access the Domain Name
[[Email protected] WEB-INF] # pwd
/Usr/local/JBoss/Server/JBoss-ghl/deploy/ghn. War/WEB-INF
[[Email protected] WEB-INF] # Cat jboss-web.xml
<? XML version = '1. 0' encoding = 'utf-8'?>
<! Doctype JBoss-Web
Public "-// JBoss // DTD web application 2.3v2 // en"
Http://www.jboss.org/j2ee/dtd/jboss-web_3_2.dtd>
<JBoss-web>
<Context-root>/</context-root>
<Virtual-host> your domain name </virtual-host>
<Virtual-host> 192.168.1.63 </virtual-host>
</JBoss-Web
/Usr/local/JBoss/Server/JBoss-ghl/deploy/jbossweb. SAR/server. xml
<Host name = "your domain name" autodeploy = "false"
Deployonstartup = "false" deployxml = "false">
<Valve classname = "org. Apache. Catalina. Valves. accesslogvalve"
Prefix = "localhost_access_log ."
Suffix = ". log"
Pattern = "common"
Directory = "$ {JBoss. server. log. dir }"
Resolvehosts = "false"/>
</Host>
</Engine>
</Service>
</Server>
Then write the startup script.
In order to facilitate the test, I wrote a test page
[[Email protected] ghn. War] # Cat index. jsp
<% @ Page Language = "Java" contenttype = "text/html; charset = UTF-8" pageencoding = "UTF-8" %>
<? XML version = "1.0" encoding = "UTF-8"?>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> </title>
</Head>
<Body>
Information from 192.168.1.60 (63 IP address changed to 63 above)
</Body>
</Html>
[[Email protected] ghn. War] # pwd
/Usr/local/JBoss/Server/JBoss-ghl/deploy/ghn. War
[[Email protected] 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
[[Email protected] bin] # pwd
/Usr/local/JBoss/bin
./Jboss-gh1.sh & START process
The JBoss configuration is complete.
Second, configure haproxy and keepalive
Both haproxy and keepalived are directly installed in yum.
Haproxy configuration (master and slave are the same)
[[Email protected] 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
Ults
Mode HTTP
Log global
Option httplog
Option dontlognull
Option http-server-close
Option forwardfor partition t 127.0.0.0/8
Option redispatch
Retries 3
Timeout http-request 10 s
Timeout queue 1 m
Timeout connect 10 s
Timeout client 1 m
Timeout Server 1 m
Timeout http-keep-alive 10 s
Timeout check 10 s
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 your domain name
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 can be started directly
Keepalived Configuration
Master Configuration
[[Email protected] 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
Priority150
Advert_int 1
Authentication {
Auth_type pass
Auth_pass 1111
}
Virtual_ipaddress {
192.168.1.64
}
}
Backup configuration
! Configuration file for keepalived
Global_defs {
Router_id lvs_devel
}
Vrrp_instance vi_1 {
State backup
Interface eth0
Virtual_router_id 51
Priority100
Advert_int 1
Authentication {
Auth_type pass
Auth_pass 1111
}
Virtual_ipaddress {
192.168.1.64
}
}
Service keepalived start can be started directly.
View IP addresses on the master after startup
[[Email protected] keepalived] # IP add
1: Lo: <loopback, up, lower_up> MTU 16436 qdisc noqueue state unknown
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: <broadcast, multicast, up, lower_up> MTU 1500 qdisc pfifo_fast state up qlen 1000
Link/ether 52: 54: 00: 3B: 2D: 8C brd 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
Backup IP Address
[Email protected] keepalived] # IP add
1: Lo: <loopback, up, lower_up> MTU 16436 qdisc noqueue state unknown
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: <broadcast, multicast, up, lower_up> MTU 1500 qdisc pfifo_fast state up qlen 1000
Link/ether 52: 54: 00: 6f: B9: 8d brd 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
Third: Test
Bind the hosts file
192.168.1.64 your domain name
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/47/D4/wKiom1QAQy3TzCtBAADZumLzGdQ666.jpg "style =" float: none; "Title =" qq2014082917062333.png "alt =" wkiom1qaqy3tzctbaadzumlzgdq666.jpg "/>
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/47/D6/wKioL1QARESh0EyhAADGOPnX-kg142.jpg "style =" float: none; "Title =" qq2014082917064944444.png "alt =" wKioL1QARESh0EyhAADGOPnX-kg142.jpg "/>
If the master keeplived is down, the slave will take over the floating IP address immediately. Seamless connection
This article is from the "route sweat exchange successful" blog, please be sure to keep this source http://ghnhl.blog.51cto.com/1630025/1546620
Haproxy + keepalive for JBoss load balancing and high availability