haproxy对redis进行负载均衡
生活随笔
收集整理的這篇文章主要介紹了
haproxy对redis进行负载均衡
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
實現(xiàn)思路:
將兩個redis-server作為后端,然后通過haproxy做為負(fù)載均衡器,每個redis-server的機器上配置配置一個用于健康檢查的shell,并通過xinetd將這個shell設(shè)置為服務(wù)監(jiān)聽9981端口并進行管理。
haproxy通過redis-server機器上的9981端口進行健康檢查,如果檢查失敗,就直接移除該redis-server,恢復(fù)后又自動添加
?
haproxy.conf
globalmaxconn 2 # debugquietuser zhxiagroup zhxianbproc 1log 127.0.0.1 local3spread-checks 2 defaultstimeout server 3stimeout connect 3stimeout client 60stimeout http-request 3stimeout queue 3s frontend redis_readbind 192.168.187.140:52020default_backend cluster_redis backend cluster_redismode tcpoption tcpkabalance static-rroption httpchkserver redis_01 192.168.180.101:6380 weight 1 check port 9981 inter 2s rise 2 fall 1server redis_02 192.168.180.101:6381 weight 1 check port 9981 inter 2s rise 2 fall 1PS:
check:啟用健康檢測
inter:健康檢測間隔
rise:檢測服務(wù)可用的連續(xù)次數(shù)
fall:檢測服務(wù)不可用的連續(xù)次數(shù)
?
安裝xinetd,統(tǒng)一對服務(wù)進行管理與端口監(jiān)聽
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.101 redis_port=6380 redis_client=/usr/local/bin/redis-cli result=`$redis_client -h $redis_host -p $redis_port -r 1 -i 1 'info' 2>/dev/null` if [ "$result" != "" ];thenecho -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" elseecho -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 = REUSEprotocol = tcpsocket_type = streamport = 9981wait = nouser = haozuserver = /home/haozu/bin/chk_redis.shlog_on_failure +=USERIDdisable =no }/etc/services
# Local services redischk 9981/tcp?
?
?
?
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/xiazh/archive/2012/11/13/2630846.html
總結(jié)
以上是生活随笔為你收集整理的haproxy对redis进行负载均衡的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: rsync软件配置和使用教程
- 下一篇: IMail邮件服务-1