HA 、mycat相关介绍

http://blog.csdn.net/xluren/article/details/39137757

http://blog.csdn.net/xluren/article/details/39153529

1.1     环境描述

mysql5

OS: Oracle Linux Server release 6.3

Mycat server1:10.0.30.134:8806

Mycat server2:10.0.30.139:8806

Haproxy server:10.0.30.139: 8098

前期未启用VIP,所以先用Mycat server28098端口作为haproxy的对外接口

 

1.2     Mycat 安装

Mycat server1Mycat server2上进行安装Mycat

 

Linux(Unix)下,建议放在/usr/local/MyCAT目录下,如下面类似的:

 

useradd mycat

chown –R mycat.mycat /usr/local/mycat

 

启动mycat

/usr/local/mycat/bin/mycat start

 

1.3    Haproxy 的安装

1、添加用户并下载相关软件

useradd haproxy

#wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.25.tar.gz
# tar zcvf haproxy-1.3.20.tar.gz
# cd haproxy-1.3.20
# make TARGET=linux26 PREFIX=/usr/local/haproxy ARCH=x86_64
# make install

 

2、安装完毕后,进入安装目录创建配置文件
# cd /usr/local/haproxy

#chown –R haproxy.haproxy *
# vi haproxy.cfg

global

    log 127.0.0.1   local0  ##记日志的功能

    maxconn 4096

    chroot /usr/local/haproxy

    user haproxy

    group haproxy

    daemon

defaults

        log   global

        option      dontlognull

        retries      3

        option redispatch

        maxconn 2000

        contimeout      5000

        clitimeout        50000

        srvtimeout       50000

listen  admin_stats 10.0.30.139:48800  ##由于没有启用VIP,暂时用其中一台的IP和新端口

      stats uri /admin-status        ##统计页面

      stats auth  admin:admin

      mode    http

      option  httplog

listen        allmycat 10.0.30.139:8098

      mode tcp

      option tcplog

          option httpchk OPTIONS * HTTP/1.1\r\nHost:\ www

      balance        roundrobin

          server  mycat_134 10.0.30.134:8066 check port 48700 inter 5s rise 2 fall 3

      server  mycat_139 10.0.30.139:8066 check port 48700 inter 5s rise 2 fall 3

      srvtimeout 20000

默认haproxy是不记录日志的,为了记录日志还需要配置syslog模块,在oracle linux下是rsyslogd服务,yum –y install rsyslog 先安装rsyslog,然后

#vi /etc/rsyslog.d/haproxy.conf

加入以下内容

$ModLoad imudp

$UDPServerRun 514

local0.* /var/log/haproxy.log ##对应haproxy.cfg 的日志记录选项

保存,重启

service rsyslog restart

现在你就可以看到日志了

 

Mycat server1 Mycat server2上都需要添加检测端口48700的脚本,为此需要用到xinetd

首先在xinetd目录下面增加脚本与端口的映射配置文件

#vim /etc/xinetd.d/mycat_status

service mycat_status

{

        flags           = REUSE

        socket_type     = stream

        port            = 48700

        wait            = no

        user            = nobody

        server          = /usr/local/bin/mycat_status

        log_on_failure  += USERID

        disable         = no

}

再增加/usr/local/bin/mycat_status用于检测mycat是否运行的脚本

#vim /usr/local/bin/mycat_status

#!/bin/bash

#/usr/local/bin/mycat_status.sh

# This script checks if a mycat server is healthy running on localhost. It will

# return:

#

# "HTTP/1.x 200 OK\r" (if mycat is running smoothly)

#

# "HTTP/1.x 503 Internal Server Error\r" (else)

mycat=`/usr/local/mycat/bin/mycat status | grep 'not running' | wc -l`

if [ "$mycat" = "0" ];

then

 /bin/echo -e "HTTP/1.1 200 OK\r\n"

else

  /bin/echo -e "HTTP/1.1 503 Service Unavailable\r\n"

fi

我是根据mycat status 返回的状态来判定mycat是否在运行的,也可以直接通过mysql –P8806 –e”select user()” 等直接执行sql的形式来检测

重启xinetd服务

#service xinetd restart

查看48700端口是否监听了

#netstat -antup|grep 48700 

 

如上图则端口的配置正确了

 

启动haproxy

/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/haproxy.cfg

 

为了使用方便可以增加一个启动,停止haproxy的脚本

启动脚本starthap内容如下

#!/bin/sh

/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/haproxy.cfg &

 

停止脚本stophap内容如下

#!/bin/sh

ps -ef | grep sbin/haproxy | grep -v grep |awk '{print $2}'|xargs kill -s 9

 

分别赋予启动权限

chmod +x starthap

chmod +x stophap

 

启动后可以通过http://10.0.30.139:48800/admin-status (用户名密码都是admin haproxy.cnfg配置的)

 

配置完成

猜你喜欢

转载自yjph83.iteye.com/blog/2327248
HA