Janrs.com | 杨建勇
Janrs.com | 杨建勇

部署高可用主从读写分离Mysql集群02

[!Tip]
部署 mycat 中间件

转载请注明出处:https://janrs.com/jozi


部署 Mycat 中间件

[!NOTE]
安装 Mycat 需要先安装 jdk
版本就按照官方的来

1.安装 jdk1.8

[!NOTE]
jdk 要求的版本可能随着 mycat 的升级而变化
此处用的是 jdk1.8 版本

去官网下载或者其他地方下载,解压到设置好到目录


cd  /etc/java
tar -zxvf jdk-8u311-linux-x64.tar.gz

修改环境变量

vi /etc/profile

添加以下环境变量

export JAVA_HOME=/etc/java/jdk1.8.0_311/
export JRE_HOME=/etc/java/jdk1.8.0_311/jre
export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin

重载配置

source /etc/profile

查看是否生效
有显示信息即可

java -version

2.部署 Mycat

直接按照官网的教程即可顺利安装,只需要改一改 ip 地址以及连接 mysql 的账号密码啥的即可
地址: https://www.yuque.com/ccazhw/ml3nkf/ob0u6a

3.部署 xinetd 进程监听

[!NOTE]
xinetd 部署在 MyCat 的服务器上用来监听 MyCat 的运行状态以上报给 HAProxy

安装并设置开机自动启动

apt install xinetd net-tools -y && systemctl enable xinetd

创建检测脚本

cat > /etc/xinetd.d/mycat-status <<EOF
service mycat-status
{
    flags        = REUSE
    socket_type    = stream
    port        = 48700
    wait        = no
    user        = root
    server        = /usr/local/bin/mycat-status
    log_on_failure    += USERID
    disable        = no
}
EOF

创建可执行检测脚本

cat > /usr/local/bin/mycat-status <<'EOF'
#!/bin/bash
#/usr/local/bin/mycat-status
# 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=`/data/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
EOF
chmod a+x /usr/local/bin/mycat-status

添加 mycat-status 服务

vim /etc/services

在末尾添加

mycat-status 48700/tcp # mycat-status

重启服务

systemctl restart xinetd

查看状态

systemctl status xinetd

如果有看到 mycat01 的服务表示有在监听,显示如下:

Feb 13 11:09:39 mycat01 xinetd[12075]: Reading included configuration file: /etc/xinetd.d/discard-udp [file=/etc/xinetd.d/discard-udp] [line=25]
Feb 13 11:09:39 mycat01 xinetd[12075]: Reading included configuration file: /etc/xinetd.d/echo [file=/etc/xinetd.d/echo] [line=14]
Feb 13 11:09:39 mycat01 xinetd[12075]: Reading included configuration file: /etc/xinetd.d/echo-udp [file=/etc/xinetd.d/echo-udp] [line=26]
Feb 13 11:09:39 mycat01 xinetd[12075]: Reading included configuration file: /etc/xinetd.d/mycat-status [file=/etc/xinetd.d/mycat-status] [line=14]
Feb 13 11:09:39 mycat01 xinetd[12075]: Reading included configuration file: /etc/xinetd.d/servers [file=/etc/xinetd.d/servers] [line=11]
Feb 13 11:09:39 mycat01 xinetd[12075]: Reading included configuration file: /etc/xinetd.d/services [file=/etc/xinetd.d/services] [line=13]
Feb 13 11:09:39 mycat01 xinetd[12075]: Reading included configuration file: /etc/xinetd.d/time [file=/etc/xinetd.d/time] [line=13]
Feb 13 11:09:39 mycat01 xinetd[12075]: Reading included configuration file: /etc/xinetd.d/time-udp [file=/etc/xinetd.d/time-udp] [line=28]
Feb 13 11:09:39 mycat01 xinetd[12075]: 2.3.15.3 started with libwrap loadavg labeled-networking options compiled in.
Feb 13 11:09:39 mycat01 xinetd[12075]: Started working: 1 available service

查看 mycat-status 服务是否启动成功

netstat -antup|grep 48700

显示如下:

tcp6       0      0 :::48700                :::*                    LISTEN      1210/xinetd
如果你有任何问题,欢迎在底部留言。或者点击加入微信技术交流群 | 我的GitHub

码仔

文章作者

Janrs.com

发表回复

textsms
account_circle
email

Janrs.com | 杨建勇

部署高可用主从读写分离Mysql集群02
[!Tip] 部署 mycat 中间件 转载请注明出处:https://janrs.com/jozi 部署 Mycat 中间件 [!NOTE] 安装 Mycat 需要先安装 jdk 版本就按照官方的来 1.安装 jdk1.8 [!NOTE] jdk 要求的版…
扫描二维码继续阅读
2023-01-16