Haproxy performs load balancing on redis

Source: Internet
Author: User
Tags haproxy

Implementation ideas:

Use two redis-servers as the backend, and then use haproxy as the Load balancer. configure a shell for health check on each redis-server machine, use xinetd to set the shell as a service listening port 9981 and manage it.

Haproxy performs health check through port 9981 on the redis-server machine. If the check fails, the redis-server will be removed and automatically added after recovery.

 

Haproxy. conf

global        maxconn 2#       debug        quiet        user zhxia        group zhxia        nbproc 1        log 127.0.0.1 local3        spread-checks 2defaults        timeout server  3s        timeout connect 3s        timeout client 60s        timeout http-request 3s        timeout queue 3sfrontend redis_read        bind 192.168.187.140:52020        default_backend cluster_redisbackend cluster_redis        mode tcp        option tcpka        balance static-rr        option httpchk        server  redis_01        192.168.180.101:6380    weight 1 check port 9981 inter 2s rise 2 fall 1        server  redis_02        192.168.180.101:6381    weight 1 check port 9981 inter 2s rise 2 fall 1

PS:

Check: Enable health check

Inter: Health Check Interval

Rise: the number of consecutive times the service is available.

Fall: consecutive times of service unavailability Detection

 

Install xinetd to manage services and monitor ports in a unified manner.

Chk_redis.sh

#!/bin/bash#===================================================================================#this script just for check the redis server if it alive#author:zhxia#date:2012-08-09#===================================================================================redis_host=192.168.180.101redis_port=6380redis_client=/usr/local/bin/redis-cliresult=`$redis_client -h $redis_host -p $redis_port -r 1 -i 1 'info' 2>/dev/null`if [ "$result" != "" ];then    echo -e "HTTP/1.1 200 OK\r\n"    echo -e "Content-Type: Content-Type: text/plain\r\n"    echo -e "\r\n"    echo -e "redis is running,listening port is:${redis_port}.\r\n"    echo -e "\r\n"else    echo -e "HTTP/1.1 503 Service Unavailable\r\n"    echo -e "Content-Type: Content-Type: text/plain\r\n"    echo -e "\r\n"    echo -e "redis is down! listen port is:${redis_port}"    echo -e "\r\n"fi

/Etc/xinetd. d/redischk

service redischk{    flags        = REUSE    protocol    = tcp    socket_type    = stream    port        = 9981    wait        = no    user        = haozu    server        = /home/haozu/bin/chk_redis.sh    log_on_failure +=USERID    disable        =no}

/Etc/services

# Local servicesredischk    9981/tcp    

 

 

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.