HA, mycat related introduction

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

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

 

 

1.1      Environment description

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 was not enabled in the early stage , so first use port 8098 of Mycat server2 as the external interface of haproxy

 

1.2      Mycat installation

Install Mycat on Mycat server1 and Mycat server2

 

Under Linux (Unix) , it is recommended to put it in the /usr/local/MyCAT directory, as follows:

 

useradd mycat

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

 

start mycat

/usr/local/mycat/bin/mycat start

 

 

1.3     Installation of Haproxy

1. Add users and download related software

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. After the installation is complete, enter the installation directory to create a configuration file
# cd /usr/local/haproxy

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

global

    log 127.0.0.1 local0 ## Logging function

    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 ## Since VIP is not enabled , temporarily use one of the IP and new port

      stats uri /admin-status ## Statistics page

      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

By default , haproxy does not record logs. In order to record logs, you need to configure the syslog module. Under oracle linux , it is the rsyslogd service. yum –y install rsyslog first installs rsyslog , and then

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

add the following

$ModLoad imudp

$UDPServerRun 514

local0.* /var/log/haproxy.log ## Logging options for haproxy.cfg

save, restart

service rsyslog restart

Now you can see the log

 

On Mycat server1 and Mycat server2 , you need to add a script to detect port 48700. For this, you need to use xinetd

First, add the script and port mapping configuration file under the xinetd directory

#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

}

Add /usr/local/bin/mycat_status to detect whether mycat is running or not

#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"

be

I judge whether mycat is running according to the status returned by mycat status , or it can be detected by directly executing sql through mysql –P8806 –e “select user()” and so on .

Restart the xinetd service

#service xinetd restart

Check if port 48700 is listening

#netstat -antup|grep 48700 

 

As shown above, the configuration of the port is correct.

 

start haproxy

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

 

For ease of use, you can add a script to start and stop haproxy

The content of the startup script starthap is as follows

#!/bin/sh

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

 

The content of the stop script stophap is as follows

#!/bin/sh

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

 

Give start permissions separately

chmod +x starthap

chmod +x stophap

 

After startup, you can pass http://10.0.30.139:48800/admin-status ( username and password are configured by admin haproxy.cnfg )

 

 

Configuration complete

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327039105&siteId=291194637