Haproxy/keepalived server1: 192.168.1.253
Haproxy/keepalived server2: 192.168.1.254
Haproxy/keepalived VIP: 192.168.1.250
Haproxy/keepalived server1:
1. Echo "net. ipv4.ip _ nonlocal_bind = 1">/etc/sysctl. conf
Sysctl-P
Yum-y install keepalived haproxy
2. CP/etc/keepalived. CONF/etc/keepalived. Bak
VI/etc/keepalived. conf
Global_defs {
Notification_email {
[Email protected]
[Email protected]
[Email protected]
}
Notification_email_from [email protected]
Smtp_server 192.168.200.1
Smtp_connect_timeout 30
Router_id centos65-2
}
Vrrp_instance vi_1 {
State master
Interface eth0
Virtual_router_id 51
Priority100
Advert_int 1
Authentication {
Auth_type pass
Auth_pass 1111
}
Virtual_ipaddress {
192.168.1.250
}
}
Delete all of the following
1). Priority value will be higher on master server
2). virtual_router_id shocould be same on both servers
3). By default single vrrp_instance support up to 20 virtual_ipaddress
3. Service keepalived start; chkconfig keepalived on
Ip addr show eth0
4. VI/etc/haproxy. cfg
Comment out the original frontend and backend
Frontend web 192.168.1.250: 8080
Default_backend Web
Listen stats 192.168.1.253: 8080
Mode HTTP
Stats enable
Stats uri/
Backend Web
Balance leastconn
Server web01 192.168.1.253: 80 check
Server web02 192.168.1.254: 80 check
Service haproxy start; chkconfig haproxy on
Haproxy/keepalived server2:
1. Echo "net. ipv4.ip _ nonlocal_bind = 1">/etc/sysctl. conf
Sysctl-P
Yum-y install keepalived haproxy
2. CP/etc/keepalived. CONF/etc/keepalived. Bak
VI/etc/keepalived. conf
Global_defs {
Notification_email {
[Email protected]
[Email protected]
[Email protected]
}
Notification_email_from [email protected]
Smtp_server 192.168.200.1
Smtp_connect_timeout 30
Router_id centos65
}
Vrrp_instance vi_1 {
State backup
Interface eth0
Virtual_router_id 51
Priority 90
Advert_int 1
Authentication {
Auth_type pass
Auth_pass 1111
}
Virtual_ipaddress {
192.168.1.250
}
}
Delete all of the following
3. Service keepalived start; chkconfig keepalived on
Ip addr show eth0
4. VI/etc/haproxy. cfg
Comment out the original frontend and backend
Frontend web 192.168.1.250: 8080
Default_backend Web
Listen stats 192.168.1.254: 8080
Mode HTTP
Stats enable
Stats uri/
Backend Web
Balance leastconn
Server web01 192.168.1.253: 80 check
Server web02 192.168.1.254: 80 check
Service haproxy start; chkconfig haproxy on
This article is from the ilovecat blog, be sure to keep this source http://hj192837.blog.51cto.com/655995/1546076
Install haproxy keppalived on centos 6.5