Janrs.com | 杨建勇

  • 首页
  • 站点地图
  • 所有文章
  • 加入学习群
Janrs.com | 杨建勇
Go/Kubernetes/Istio/CloudNative
  1. 首页
  2. MySQL
  3. 正文

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

2023年1月16日 141点热度 676人点赞 0条评论

[!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
本作品采用 知识共享署名-非商业性使用 4.0 国际许可协议 进行许可
标签: mysql 主从 分布式 微服务 架构 集群 领域驱动 高可用
最后更新:2023年3月8日

码仔

Janrs.com

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复
有关Go/istio/k8s/云原生直接搜
文章目录
  • 部署 Mycat 中间件
    • 1.安装 jdk1.8
    • 2.部署 Mycat
    • 3.部署 xinetd 进程监听

COPYRIGHT © 2023 Janrs.com | 杨建勇. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

闽ICP备20002184号