Haproxy+keepalived如何实现sphinx高可用负载均衡详解

发布时间:2020-04-17 11:21:13 作者:三月
来源:亿速云 阅读:244

下文给大家带来Haproxy+keepalived如何实现sphinx高可用负载均衡详解,希望能够给大家在实际运用中带来一定的帮助,负载均衡涉及的东西比较多,理论也不多,网上有很多书籍,今天我们就用亿速云在行业内累计的经验来做一个解答。

Haproxy+keepalived实现sphinx高可用负载均衡  

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 include 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
Extra 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
        authentication {
                auth_type PASS
                auth_pass 123456
                }
       track_script {
               chk_haproxy
               }
        virtual_ipaddress {
                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
fi

看了以上关于Haproxy+keepalived如何实现sphinx高可用负载均衡详解,如果大家还有什么地方需要了解的可以在亿速云行业资讯里查找自己感兴趣的或者找我们的专业技术工程师解答的,亿速云技术工程师在行业内拥有十几年的经验了。

 

推荐阅读:
  1. HAProxy+mongos如何搭建高可用负载均衡mongodb详解
  2. haproxy+keepalived(主主模式)实现高可用环境的简单配置

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

负载均衡 keepalived haproxy

上一篇:管理hadoop

下一篇:关于PHP文件上传的相关知识总结

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》