MySQL集群(支持不同地区(不同ip段))高可用 不是Keepalive 但类似

《MySQL集群(支持不同地区(不同ip段))高可用 不是Keepalive 但类似》

用过Keepalive的都知道,Keepalive只支持局域网,不支持外网,有没有一款支持外网的 Keepalive, 博主一直在思考这个问题,无意中发现了 mysql-router 这么一个软件, 下面就来研究一下这个软件能否达到预期的效果。

安装mysql-shell (可以不装)

//这个模块没什么用,完全可以不装, 真正实现负载均衡的是mysql-router
官网地址:https://downloads.mysql.com/archives/shell/

wget https://downloads.mysql.com/archives/get/p/43/file/mysql-shell-8.0.33-1.el8.x86_64.rpm


rpm -ivh mysql-shell-8.0.17-1.el8.x86_64.rpm   //需要ibpython2.7.so.1.0
rpm -ivh mysql-shell-8.0.20-1.el8.x86_64.rpm   //需要ibpython3.6.so.1.0
rpm -ivh mysql-shell-8.0.33-1.el8.x86_64.rpm  //需要 libpython3.9.so.1.0


测试:
#mysqlsh
--------------------------------------------------------
MySQL Shell 8.0.20

Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.
Type '\help' or '\?' for help; '\quit' to exit.
 MySQL  JS > 

安装mysql-router

wget https://downloads.mysql.com/archives/get/p/41/file/mysql-router-community-8.0.20-1.el8.x86_64.rpm



#rpm -ivh mysql-router-community-8.0.20-1.el8.x86_64.rpm 
---------------------------------------------------------
warning: mysql-router-community-8.0.20-1.el8.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-router-community-8.0.20-1.e################################# [100%]
[/usr/lib/tmpfiles.d/mysqlrouter.conf:23] Line references path below legacy directory /var/run/, updating /var/run/mysqlrouter → /run/mysqlrouter; please update the tmpfiles.d/ drop-in file accordingly.
------------------------------------------------------

//配置文件的目录
/etc/mysqlrouter/mysqlrouter.conf
-------------------------------------
[DEFAULT]
logging_folder = /var/log/mysqlrouter
runtime_folder = /var/run/mysqlrouter
config_folder = /etc/mysqlrouter

[logger]
# 日志运行级别
level = INFO

# 主节点故障转移配置
[routing:local]
# 写节点地址
bind_address=0.0.0.0
#监听的节点端口
bind_port = 3300
# 模式,读写
mode = read-write
# 主节点地址:默认情况下第一台主数据库为写主库,当第一台主数据库DOWN机后,第二台数据库被提升为主库
destinations = 127.0.0.1:3306,xxx.fxxx.xxx:3306


[keepalive]
#心跳时间60s默认
interval = 60
---------------------------------------------------------------------

//重启:
service mysqlrouter restart
//开机启动
systemctl enable mysqlrouter

测试

#mysql -h127.0.0.1 -P3300 -uroot -p
#mysql -hxxx.fxxx.xxx -P3306 -uroot -p
点赞

发表评论

邮箱地址不会被公开。 必填项已用*标注