mycat高可用集群搭建文檔

最近主要在做mycat分庫分表這一塊的東西,踩過的坑很多,以后會(huì)慢慢分享下

一、配置MyCat狀態(tài)檢查服務(wù)(在MyCat節(jié)點(diǎn)主機(jī)上配置)


安裝xinetd插件

yum install xinetd -y

cd /etc/xinetd.d

touch mycat_status

vim /etc/xinetd.d/mycat_status

service mycat_status
{
    flags = REUSE
    socket_type = stream
    port = 48700
    wait = no
    user = nobody
    server =/opt/export/app/mycat_status
    log_on_failure += USERID
    disable = no
}
創(chuàng)建xinetd啟動(dòng)服務(wù)腳本

vim /opt/export/app/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=`/opt/export/app/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
修改腳本文件權(quán)限(注意)

我就是在這里被坑了很久,根據(jù)權(quán)威指南上面mycat_status這個(gè)腳本里面的內(nèi)容也有很多問題,好幾個(gè)地方?jīng)]有空格.

chmod u+x /etc/xinetd.d/mycat_status
chmod u+x /opt/export/app/mycat_status

將啟動(dòng)腳本加入服務(wù)

vim /etc/services

在末尾加入
mycat_status    48700/tcp               # mycat_status
重啟xinetd服務(wù)

service xinetd restart

將xinetd加入自啟動(dòng)服務(wù)
chkconfig --add xinetd
chkconfig --level 2345 xinetd on
注意:

如果權(quán)限不足,需要使用sudo權(quán)限來啟動(dòng)

二、 HaProxy安裝和配置(mycat節(jié)點(diǎn)之外)


haproxy安裝

添加用戶

useradd haproxy

sudo passwd haproxy

然后添加密碼

創(chuàng)建目錄

mkdir /opt/export/app/haproxy

haproxy-1.5.16.tar.gz放置該目錄下

然后下面執(zhí)行一下下面的命令

tar zxvf /opt/export/app/haproxy/haproxy-1.5.16.tar.gz

mkdir /opt/export/app/haproxy/haproxy

cd /opt/export/app/haproxy/haproxy-1.5.16

-- 編譯安裝
make TARGET=linux26 PREFIX=/opt/export/app/haproxy/haproxy ARCH=x86_64

make install PREFIX=/opt/export/app/haproxy/haproxy

haproxy配置

cd /opt/export/app/haproxy/haproxy

touch haproxy.cfg

vim haproxy.cfg

global
    log 127.0.0.1 local0 ##記日志的功能
    maxconn 4096
    chroot /opt/export/app/haproxy/haproxy
    user haproxy
    group haproxy
    node  ha-01
    daemon

defaults
    log global
    option dontlognull
    retries 3
    option redispatch
    maxconn 2000
    timeout connect 5000ms
    timeout client 50000ms
    timeout server 50000ms

listen admin_stats 172.16.2.4:48800 ##統(tǒng)計(jì)頁面
    stats uri /admin-status 
    stats auth admin:admin
    mode http
    option httplog

listen mycat_service 172.16.2.4:3306 ##客戶端就是通過這個(gè)ip和端口進(jìn)行連接,這個(gè)vip和端口綁定的是mycat8066端口
    mode tcp
    option tcplog
    option httpchk OPTIONS * HTTP/1.1\r\nHost:\ www
    balance roundrobin
    server mycat01 172.16.1.93:8066 check port 48700 inter 5s rise 2 fall 3
    server mycat02 172.16.2.1:8066 check port 48700 inter 5s rise 2 fall 3
    timeout server 20000

listen mycat_admin 172.16.2.4:3406 ##客戶端就是通過這個(gè)ip和端口進(jìn)行連接,這個(gè)vip和端口綁定的是mycat9066端口
    mode tcp
    option tcplog
    option httpchk OPTIONS * HTTP/1.1\r\nHost:\ www
    balance roundrobin
    server mycat01 172.16.1.93:9066 check port 48700 inter 5s rise 2 fall 3
    server mycat02 172.16.2.1:9066 check port 48700 inter 5s rise 2 fall 3
    timeout server 20000
配置haproxy記錄日志功能

yum –y install rsyslog

mkdir /etc/rsyslog.d

cd /etc/rsyslog.d/

touch haproxy.conf

vim haproxy.conf

$ModLoad imudp
$UDPServerRun 514
local0.* /opt/export/log/haproxy/haproxy.log

vim /etc/rsyslog.conf

#### RULES ####上面一行加入以下內(nèi)容

# Include all config files in /etc/rsyslog.d/
$IncludeConfig /etc/rsyslog.d/*.conf

local7.* /var/log/boot.log下面加入以下內(nèi)容

local0.*    /opt/export/log/haproxy/haproxy.log
重啟rsyslog服務(wù)

service rsyslog restart

將rsyslog加入自動(dòng)啟動(dòng)服務(wù)
chkconfig --add rsyslog
chkconfig --level 2345 rsyslog on
創(chuàng)建haproxy啟停腳本

啟動(dòng)腳本

touch /opt/export/app/haproxy/haproxy/sbin/start &&
chmod +x /opt/export/app/haproxy/haproxy/sbin/start &&
vim /opt/export/app/haproxy/haproxy/sbin/start

#!/bin/sh
/opt/export/app/haproxy/haproxy/sbin/haproxy -f /opt/export/app/haproxy/haproxy/haproxy.cfg &

停止腳本

touch /opt/export/app/haproxy/haproxy/sbin/stop &&
chmod +x /opt/export/app/haproxy/haproxy/sbin/stop &&
vim /opt/export/app/haproxy/haproxy/sbin/stop

#!/bin/sh
ps -ef | grep sbin/haproxy | grep -v grep |awk '{print $2}'|xargs kill -s 9
授權(quán)

chown -R haproxy.haproxy /opt/export/app/haproxy/haproxy/*

啟動(dòng)

sudo /opt/export/app/haproxy/haproxy/sbin/start

檢查haproxy是否啟動(dòng)成功

netstat -ntlp | grep :48800

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 二、 軟件版本 操作系統(tǒng): CentOS-6.6-x86_64JDK 版本: jdk1.7.0_72HAProxy...
  • 一、項(xiàng)目目標(biāo) 搭建一個(gè)高可用web集群網(wǎng)站 二、項(xiàng)目規(guī)劃 2.1 ip地址規(guī)劃 2.2 拓?fù)鋱D 2.3 相關(guān)說明 ...
    夏日之光閱讀 4,286評(píng)論 0 1
  • 這幾天有點(diǎn)煩心事。 4月初,有個(gè)客戶從我這里采購了一部分電纜。時(shí)間都過去一個(gè)月了,我以為這批材料早就預(yù)埋下去了。 ...
    昕城閱讀 456評(píng)論 0 1
  • 《夏至心憐》 在這寧靜的夏天,午時(shí)是最磨人的時(shí)刻,通常,只要與這午時(shí)的太陽面對面不過幾秒,你將面紅耳赤,難受不...
    五月一閱讀 356評(píng)論 0 1

友情鏈接更多精彩內(nèi)容