使用haproxy来实现sphinx负载均衡与健康监测
来源:互联网 发布:四九算法 编辑:程序博客网 时间:2024/06/05 17:32
option tcpka
option httpchk
server node1 192.168.1.189:3312 weight 1 check port 9312 inter 1s rise 2 fall 2
server node2 192.168.1.101:3312 weight 1 check port 9312 inter 1s rise 2 fall 2
//后台服务器
#weight 服务器权重
#check port 检测端口
#inter 设置连续的两次健康检测间的时间
#rise 指定多少次连接成功的健康检测后,可认定该服务器可用
#fall 指定多少次失败的健康检测后,可认定该服务器当掉
配置日志
# vim /etc/rsyslog.d/haproxy.conf
$ModLoad imudp
$UDPServerRun 514
local0.* /var/log/haproxy.log
重启日志服务
# restart rsyslog
【node1/node2】上配置:
1.健康检测
# apt-get install xinetd
# vim /etc/inetd.conf
sphinxchk stream tcp wait root /usr/local/scripts/sphinxchk.sh
注释:
a.服务名称:inetd通过查询/etc/services获得该服务相关信息
b.套接字类型:该服务使用的通信协议tcp用stream,udp用dgram
c.Inetd是否等待守护进程结束才继续接管端口。Wait表示等待,nowait表示不等待,inetd每次接到一个请求就启动守护进程的新副本
d.运行该守护进程的用户
e.守护进程二进制文件的路径以及参数
# vim /etc/xinetd.d/sphinxchk
service sphinxchk
{
flags = REUSE
socket_type = stream
port = 9312
wait = no
user = root
server = /usr/local/scripts/sphinxchk.sh
log_on_failure += USERID
disable = no
only_from = 192.168.1.0/24
}
sphinx配置省略
测试:
将sphinx源码api目录下的sphinxapi.py test.py拷贝到测试服务器上。
# vim sphinx-test.sh
#!/bin/bash
i=0
while [ "$i" -lt "99999" ]
do
/usr/bin/python /root/test.py -a $*
let i=$i+1
done
# ./sphinx-test.sh php aaa bbb ccc dddd
Kill掉node1上的sphinx服务
Oct 13 01:59:59 localhost haproxy[12117] Health check for server proxy-sphinx-1/node1 failed, reason: Layer7 wrong status, code: 503, info: “Service Unavailable”, check duration: 32ms, status: 1/2 UP.
Oct 13 01:59:59 localhost haproxy[12119] Health check for server proxy-sphinx-1/node1 failed, reason: Layer7 wrong status, code: 503, info: “Service Unavailable”, check duration: 31ms, status: 1/2 UP.
Oct 13 01:59:59 localhost haproxy[12118] Health check for server proxy-sphinx-1/node1 failed, reason: Layer7 wrong status, code: 503, info: “Service Unavailable”, check duration: 31ms, status: 1/2 UP.
Oct 13 01:59:59 localhost haproxy[12120] Health check for server proxy-sphinx-1/node1 failed, reason: Layer7 wrong status, code: 503, info: “Service Unavailable”, check duration: 31ms, status: 1/2 UP.
Oct 13 02:00:00 localhost haproxy[12117] Health check for server proxy-sphinx-1/node1 failed, reason: Layer7 wrong status, code: 503, info: “Service Unavailable”, check duration: 35ms, status: 0/2 DOWN.
Oct 13 02:00:00 localhost haproxy[12117] Server proxy-sphinx-1/node1 is DOWN. 1 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
Oct 13 02:00:00 localhost haproxy[12119] Health check for server proxy-sphinx-1/node1 failed, reason: Layer7 wrong status, code: 503, info: “Service Unavailable”, check duration: 32ms, status: 0/2 DOWN.
Oct 13 02:00:00 localhost haproxy[12119] Server proxy-sphinx-1/node1 is DOWN. 1 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
Oct 13 02:00:00 localhost haproxy[12118] Health check for server proxy-sphinx-1/node1 failed, reason: Layer7 wrong status, code: 503, info: “Service Unavailable”, check duration: 30ms, status: 0/2 DOWN.
Oct 13 02:00:00 localhost haproxy[12118] Server proxy-sphinx-1/node1 is DOWN. 1 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
Oct 13 02:00:00 localhost haproxy[12120] Health check for server proxy-sphinx-1/node1 failed, reason: Layer7 wrong status, code: 503, info: “Service Unavailable”, check duration: 32ms, status: 0/2 DOWN.
Oct 13 02:00:00 localhost haproxy[12120] Server proxy-sphinx-1/node1 is DOWN. 1 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
请求将会发送到node2上面。(将sphinx的查询日志打开进行观察)
- 使用haproxy来实现sphinx负载均衡与健康监测
- 使用Haproxy对Sphinx做负载均衡
- Haproxy+keepalived实现sphinx高可用负载均衡
- haproxy 实现负载均衡
- 用HAProxy实现负载均衡
- 利用HAProxy 实现负载均衡
- 利用HAProxy实现负载均衡
- 利用HAProxy实现负载均衡
- HaProxy实现Mongos负载均衡
- 负载均衡 - HAProxy 与 Nginx
- keepalived+haproxy实现nginx与mysql负载均衡
- 使用HAProxy实现Percona XtraDB Cluster的负载均衡
- 使用HaProxy实现Thrift服务端的负载均衡
- 使用haproxy实现反向代理负载均衡实战
- 初尝利用HAProxy 实现负载均衡
- 初尝利用HAProxy 实现负载均衡
- 初尝利用HAProxy 实现负载均衡
- haproxy+keepalived实现高可用负载均衡
- OGG Initial Load测试
- Python使用bitey调用C模块
- 2012 MCU市场主旋律:低端被替代,高端走整合
- nginx 负载均衡与location应用分析
- 手机蓝牙编程简介
- 使用haproxy来实现sphinx负载均衡与健康监测
- 避免2.4GHz ISM频段各种类型无线设备干扰的技术
- 数据库设计三大范式
- 蓝牙技术和802.11b/g之间的信号干扰
- Linux系统启动过程
- HTML 帧标签的使用
- java集合---HashMap原理
- SQLite数据库的基本操作方法
- 解决css firefox火狐浏览器IE浏览器下的兼容性问题