搭建高可用搜索服务(2)–安装haproxy代理coreseek服务

1:在安装有coreseek服务的主机上添加监控sphinx状态的服务

安装xineed服务

yum install xinetd

添加端口

echo "sphinxcheck     9322/tcp                # sphinx status check" >> /etc/services 
使用xinetd守护进程运行sphinx状态检测
vim /etc/xinetd.d/sphinxchk
service sphinxcheck
{
        disable         = no
        flags           = REUSE
        socket_type     = stream
        port            = 9322
        wait            = no
        user            = root
        server          = /usr/local/coreseek4.1/shell/sphinxchk_status.sh log_on_failure  += USERID
        only_from       = 192.168.1.126
}

新建状态监控shell

vim /usr/local/coreseek4.1/shell/sphinxchk_status.sh
#!/bin/bash
ERROR_MSG=`ps -aef|grep coreseek4.1|grep -v grep |wc -l`

if [ "$ERROR_MSG" != "0" ]
then
        # sphinx is fine, return http 200
        /bin/echo -e "HTTP/1.1 200 OK\r\n"
        /bin/echo -e "Content-Type: Content-Type: text/plain\r\n"
        /bin/echo -e "\r\n"
        /bin/echo -e "sphinx is running.\r\n"
        /bin/echo -e "\r\n"
else
        # sphinx is fine, return http 503
        /bin/echo -e "HTTP/1.1 503 Service Unavailable\r\n"
        /bin/echo -e "Content-Type: Content-Type: text/plain\r\n"
        /bin/echo -e "\r\n"
        /bin/echo -e "sphinx is *down*.\r\n"
        /bin/echo -e "\r\n"
fi

重启下xinetd服务

service xinetd restart

2:安装并配置haproxy

安装

yum -y install haproxy

配置文件/etc/haproxy/haproxy.cfg

#全局配置参数,进程级的,用来控制Haproxy启动前的一些进程及系统设置
global
    log         127.0.0.1 local2 #local2在/etc/rsyslog.conf中有一行local2.*    /var/log/haproxy.log
    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    user        haproxy
    group       haproxy
    daemon
    maxconn     4096
    stats socket /var/lib/haproxy/stats

#配置一些默认的参数,可以被frontend,backend,listen段继承使用
defaults
    mode                    http
    log                     global
    option                  dontlognull
    option                  log-health-checks //记录健康检测日志
    option                  redispatch //在连接失败或断开情况下,允许当前会话被重新分发
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 100000

#统计信息
listen  haproxy-status 0.0.0.0:8888
    mode          http
    option        httplog
    stats uri     /status  //统计页面url
    stats realm   Global\ statistics
    stats auth    test:123456 //登录用户和密码


#监听
listen  proxy-sphinx 192.168.1.123:9312
        mode tcp
        balance leastconn
        option tcpka
        option httpchk OPTIONS * HTTP/1.1\r\nHost:\ www
        server sphinx1  192.168.1.124:9312 weight 1 check port 9322 inter 1s rise 2 fall 2
        server sphinx2  192.168.1.125:9312 weight 1 check port 9322 inter 1s rise 2 fall 2

启动haproxy服务

service haproxy restart

访问http://192.168.1.123:8888/status 如看到如下类似界面,则表示成功了!

此条目发表在 好文推荐, 网站开发, 网站架构 分类目录,贴了 , , , 标签。将固定链接加入收藏夹。

评论功能已关闭。