Haproxy + keepalived for Sphinx high-availability Load Balancing
Last Update:2018-12-04
Source: Internet
Author: User
Haproxy + keepalived for Sphinx High Availability
Server Load balancer
The environment is as follows:
[Node3]
Haproxy : 192.168.1.189
[Node4]
Haproxy: 192.168.1.103
VIP: 192.168.1.222/192.168.1.223
# Apt-Get install ipvsadm
# Apt-Get install linux-headers-$ (
Uname -R)
#
Ln -S/usr/src/linux-headers-2.6.32-33/usr/src/Linux
# Wget http://www.keepalived.org/software/keepalived-1.2.2.tar.gz
# Tar zxvf keepalived-1.2.2.tar.gz-C ../software/
#./Configure-Prefix =/usr/local/keepalived-1.2.2
Configure: Error :!!! OpenSSL is not properly installed on your system .!!!!!! Can not I
NC Lude OpenSSL Headers
File S. solution:
# Apt-Get install libssl-Dev
Configure: Error: popt libraries is required
Solution:
# Apt-Get install libpopt-Dev
Configure: Warning: keepalived will be built without libnl
Su Pport.
Solution:
# Apt-Get install libnl-Dev
/Usr/include/stdint. h: 41: Error: conflicting types for 'int64 _ t'
/Usr/src/Linux/include/Linux/types. h: 125: Error: previous declaration of 'int64 _ t' was here
/Usr/include/stdint. h: 56: Error: conflicting types for 'uint64 _ t'
Solution:
# Vim./keepalived/libipvs-2.6/ip_vs.h
Move # include <Linux/types. h> to the end of # include <sys/types. h>.
#./Configure-Prefix =/usr/local/keepalived-1.2.2
Keepalived Configuration
--------
Keepalived version: 1.2.2
Compiler: gcc
Compiler flags:-g-O2
Ex
Tr A Lib:-lpopt-
Ls SL-lcrypto-lnl
Use ipvs framework: Yes
Ipvs
Sync Daemon support: Yes
S use libnl: Yes
Use vrrp framework: Yes
Use DEBUG flags: No
# Make
# Make install
# Vim/etc/sysctl. conf
Net. ipv4.ip _ nonlocal_bind = 1
# Sysctl-P
[Node3]
Global_defs {
Router _
ID Lvs_devel
}
Vrrp_script chk_haproxy {
Script "/usr/local/scripts/chk_haproxy.sh"
Interval 2
Weight 2
}
Vrrp_instance vi_1 {
Stat E master
Interface eth0
Virtual_router_id 76
Priority150
Advert_int 1
Authenti
Cat Ion {
Auth_type pass
Auth_pass 123456
}
Track_script {
Chk_haproxy
}
Virtual_ipa
Dd RESS {
192.168.1.222
}
}
Vrrp_instance vi_2 {
State backup
Interface eth0
Virtual_router_id 77
Priority100
Advert_int 1
Authentication {
Auth_type pass
Auth_pass 123456
}
Track_script {
Chk_haproxy
}
Virtual_ipaddress {
192.168.1.223
}
}
[Node4]
Global_defs {
Router_id lvs_devel
}
Vrrp_script chk_haproxy {
Script "/usr/local/scripts/chk_haproxy.sh"
Interval 2
Weight 2
}
Vrrp_instance vi_1 {
State backup
Interface eth0
Virtual_router_id 76
Priority100
Advert_int 1
Authentication {
Auth_type pass
Auth_pass 123456
}
Track_script {
Chk_haproxy
}
Virtual_ipaddress {
192.168.1.222
}
}
Vrrp_instance vi_2 {
State master
Interface eth0
Virtual_router_id 77
Priority150
Advert_int 1
Authentication {
Auth_type pass
Auth_pass 123456
}
Track_script {
Chk_haproxy
}
Virtual_ipaddress {
192.168.1.223
}
}
# Vim chk_haproxy.sh
#! /Bin/bash
Status ='
Netstat -Nptl |
Grep Haproxy | grep 3312 |
WC -L'
If ["$ status"-EQ "0"]; then
/Usr/local/haproxy-1.4.18/sbin/haproxy-F/usr/local/haproxy-1.4.18/haproxy. conf
Status2 = 'netstat-nptl | grep haproxy | grep 3312 | WC-l'
If ["$ status2"-EQ "0"]; then
Kill -9 $ (PS-Ef | grep keepalived | grep-V grep | awk '{print $2 }')
Fi