Haproxy+keepalived實現sphinx高可用負載平衡

來源:互聯網
上載者:User
Haproxy+keepalived實現sphinx高可用 負載平衡
環境如下:
【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 nclude OpenSSL headers files.解決辦法:
# apt-get install libssl-dev
configure: error: Popt libraries is required
解決辦法:
# apt-get install libpopt-dev
configure: WARNING: keepalived will be built without libnl support.
解決辦法:
# 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’
解決辦法:
# vim ./keepalived/libipvs-2.6/ip_vs.h
將#include <linux/types.h>移動到#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 tra Lib                : -lpopt - lssl -lcrypto  -lnl
Use IPVS Framework       : Yes
IPVS sync daemon support : Yes
IPVS 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 {
state MASTER
interface eth0
virtual_router_id 76
priority 150
advert_int 1
authenti cation {
auth_type PASS
auth_pass 123456
}
track_script {
chk_haproxy
}
virtual_ipa ddress {
192.168.1.222
}
}
vrrp_instance VI_2 {
state BACKUP
interface eth0
virtual_router_id 77
priority 100
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
priority 100
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
priority 150
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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.