Redian新闻
>
MySQL-Xenon高可用

MySQL-Xenon高可用

公众号新闻


在MySQL5.5及以下传统复制的时代,MHA在MySQL高可用应用中非常成熟,在MySQL5.6的GTID时代开启以后,MHA却没有与新的MySQL一起顺应潮流,MHA最近一次发版是2018年。于是RadonDB开发团队研发并开源新一代MySQL集群高可用工具。基于Raft协议进行无中心化选主,实现主从秒级切换;基于semi-sync机制,保障数据不丢失,实现数据强一致性。并结合MySQL5.7及以上版本并行复制特性,实现binlog并行回放那个,大大降低从库延迟。

代码托管:https://github.com/radondb/xenon

Xenon 实验环境

  • master db01 192.168.3.112

  • slave db02 192.168.3.113

  • salve db03 192.168.3.114

1、配置基于增强半同步的主从复制,配置过程详见《MySQL-主从复制》中。

2、三台主机安装 xtrabackup

rpm -ivh percona-xtrabackup-80-8.0.13-1.el7.x86_64.rpm

3、三台主机配置互信,免密ssh登录

4、三台主机安装 go 环境

go 下载地址:https://golang.google.cn/dl/

# tar -zxvf go1.14.8.linux-amd64.tar.gz -C /opt/# vim /etc/profileexport GOPATH=/opt/go/binexport PATH=$PATH:$GOPATH

5、安装Xenon

下载地址:https://github.com/radondb/xenon/

# unzip xenon-master.zip# make

6、三台主机配置 Xenon

# mkdir /opt/xenon# cp -r /root/xenon-master/bin/ /opt/xenon/# mkdir /opt/xenon/etc# cp /root/xenon-master/conf/xenon-sample.conf.json /opt/xenon/etc/xenon.json# echo "/opt/xenon/etc/xenon.json" > /opt/xenon/bin/config.path# chown mysql.mysql /opt/xenon/ -R

修改 xenon.json 文件

# more /opt/xenon/etc/xenon.json {  "server":  {    "endpoint":"192.168.3.114:8801"  },
"raft": { "meta-datadir":"raft.meta", "leader-start-command":"sudo /sbin/ip a a 192.168.3.110/24 dev ens33 && arping -c 3 -A 192.168.3.110 -I ens33", "leader-stop-command":"sudo /sbin/ip a d 192.168.3.110/24 dev ens33" },
"mysql": { "admin":"root", "version":"mysql80", "passwd":"123", "host":"192.168.3.114", "port":3306, "basedir":"/opt/mysql", "defaults-file":"/opt/mysql/.my.cnf", "ping-timeout":1000, "master-sysvars":"tokudb_fsync_log_period=default;sync_binlog=default;innodb_flush_log_at_trx_commit=default", "slave-sysvars" : "tokudb_fsync_log_period=1000;sync_binlog=1000;innodb_flush_log_at_trx_commit=2" },
"replication": { "user":"repl", "passwd":"repl" },
"backup": { "ssh-host":"192.168.3.114", "ssh-user":"root", "ssh-passwd":"root123", "basedir":"/opt/mysql", "backupdir":"/opt/mysql/data", "xtrabackup-bindir":"/bin", "max-allowed-local-trx-count": 1000, "backup-use-memory": "1GB", "backup-parallel": 4
},
"rpc": { "request-timeout":500 },
"log": { "level":"INFO" }}

三台主机启动 xenon ,并添加节点。官方建议Xenon和MySQL使用同一用户启动。

以普通用户启动要配置sudo

## NOPASSWD 免输入密码sudo,不加此选项,则启动失败# visudomysql   ALL=(ALL)       NOPASSWD: /usr/sbin/ip

在 mysql 用户下启动,xenon会自动拉起mysql进程服务

# su - mysql$ nohup /opt/xenon/bin/xenon -c /opt/xenon/etc/xenon.json > /opt/xenon/xenon.log 2>&1 &$ ./xenoncli cluster add 192.168.3.112:8801,192.168.3.113:8801,192.168.3.114:8801

查看集群状态

$ ./xenoncli cluster status+--------------------+-------------------------------+---------+---------+--------------------------+---------------------+----------------+--------------------+|         ID         |             Raft              | Mysqld  | Monitor |          Backup          |        Mysql        | IO/SQL_RUNNING |      MyLeader      |+--------------------+-------------------------------+---------+---------+--------------------------+---------------------+----------------+--------------------+| 192.168.3.112:8801 | [ViewID:3 EpochID:0]@LEADER   | RUNNING | ON      | state:[NONE]␤            | [ALIVE] [READWRITE] | [true/true]    | 192.168.3.112:8801 ||                    |                               |         |         | LastError:               |                     |                |                    |+--------------------+-------------------------------+---------+---------+--------------------------+---------------------+----------------+--------------------+| 192.168.3.113:8801 | [ViewID:3 EpochID:0]@FOLLOWER | RUNNING | ON      | state:[NONE]␤            | [ALIVE] [READONLY]  | [true/true]    | 192.168.3.112:8801 ||                    |                               |         |         | LastError:               |                     |                |                    |+--------------------+-------------------------------+---------+---------+--------------------------+---------------------+----------------+--------------------+| 192.168.3.114:8801 | [ViewID:3 EpochID:0]@FOLLOWER | RUNNING | ON      | state:[NONE]␤            | [ALIVE] [READONLY]  | [true/true]    | 192.168.3.112:8801 ||                    |                               |         |         | LastError:               |                     |                |                    |+--------------------+-------------------------------+---------+---------+--------------------------+---------------------+----------------+--------------------+$ ./xenoncli cluster mysql+--------------------+----------+-------+-----------+------------------------+----------------+----------------+------------+|         ID         |   Raft   | Mysql |  Option   |  Master_Log_File/Pos   | IO/SQL_Running | Seconds_Behind | Last_Error |+--------------------+----------+-------+-----------+------------------------+----------------+----------------+------------+| 192.168.3.112:8801 | LEADER   | ALIVE | READWRITE | [mysql-bin.000008/388] | [true/true]    |              0 |            |+--------------------+----------+-------+-----------+------------------------+----------------+----------------+------------+| 192.168.3.113:8801 | FOLLOWER | ALIVE | READONLY  | [mysql-bin.000008/388] | [true/true]    |              0 |            |+--------------------+----------+-------+-----------+------------------------+----------------+----------------+------------+| 192.168.3.114:8801 | FOLLOWER | ALIVE | READONLY  | [mysql-bin.000008/388] | [true/true]    |              0 |            |+--------------------+----------+-------+-----------+------------------------+----------------+----------------+------------+
关闭集群``` shell# ./xenoncli mysql stopmonitor# ./xenoncli mysql shutdown# pkill xenon

Xenon 备份

$ /opt/xenon/bin/xenoncli mysql backup --to=/opt/mysql/9876 2023/06/18 15:48:41.643361 callx.go:92:       [WARNING]   get.client.error[dial tcp 192.168.3.113:8801: connect: connection refused] 2023/06/18 15:48:41.643473 callx.go:163:       [WARNING]   get.client.error[dial tcp 192.168.3.113:8801: connect: connection refused] 2023/06/18 15:48:41.652513 callx.go:183:       [WARNING]   best.slave.can't.found.set.to.leader[192.168.3.112:8801] 2023/06/18 15:48:41.652531 mysql.go:562:       [WARNING]   S1-->found.the.best.backup.host[192.168.3.112:8801].... 2023/06/18 15:48:41.783611 mysql.go:576:       [WARNING]   S2-->rm.and.mkdir.backupdir[/opt/mysql/9876] 2023/06/18 15:48:41.783637 mysql.go:581:       [WARNING]   S3-->xtrabackup.begin.... 2023/06/18 15:48:41.784505 callx.go:442:       [WARNING]   rebuildme.backup.req[&{From: BackupDir:/opt/mysql/9876 SSHHost:192.168.3.114 SSHUser:mysql SSHPasswd:mysql SSHPort:22 IOPSLimits:100000 XtrabackupBinDir:/usr/bin}].from[192.168.3.112:8801] 2023/06/18 15:48:42.804183 common.go:41:       [PANIC]   rsp[cmd.outs.[completed OK!].found[0]!=expects[1]] != [OK]panic:    [PANIC]   rsp[cmd.outs.[completed OK!].found[0]!=expects[1]] != [OK]
goroutine 1 [running]:xbase/xlog.(*Log).Panic(0xc0000ec170, 0x8dd965, 0xf, 0xc0000e1d68, 0x1, 0x1) /root/xenon-master/src/xbase/xlog/xlog.go:164 +0x153cli/cmd.RspOK(...) /root/xenon-master/src/cli/cmd/common.go:41cli/cmd.mysqlDoBackupCommandFn(0xc0000fe000, 0xc0000ec200, 0x0, 0x1) /root/xenon-master/src/cli/cmd/mysql.go:584 +0x481vendor/github.com/spf13/cobra.(*Command).execute(0xc0000fe000, 0xc0000ec1e0, 0x1, 0x1, 0xc0000fe000, 0xc0000ec1e0) /root/xenon-master/src/vendor/github.com/spf13/cobra/command.go:603 +0x22evendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc7f800, 0x1, 0xc0000e1f78, 0x40746f) /root/xenon-master/src/vendor/github.com/spf13/cobra/command.go:689 +0x2bcvendor/github.com/spf13/cobra.(*Command).Execute(...) /root/xenon-master/src/vendor/github.com/spf13/cobra/command.go:648main.main() /root/xenon-master/src/cli/cli.go:43 +0x31

从输出日志信息看是备份失败,经排查是因为xenon.json配置中 mysql 部分的 host 参数导致。

  "mysql":  {    "admin":"root",    "version":"mysql80",    "passwd":"123",    "host":"192.168.3.114",     # 设置为主机IP地址,设置为localhost导致备份失败    "port":3306,    "basedir":"/opt/mysql",    "defaults-file":"/opt/mysql/.my.cnf",                "ping-timeout":1000,                "master-sysvars":"tokudb_fsync_log_period=default;sync_binlog=default;innodb_flush_log_at_trx_commit=default",                "slave-sysvars" : "tokudb_fsync_log_period=1000;sync_binlog=1000;innodb_flush_log_at_trx_commit=2"  },

链接:https://www.cnblogs.com/zbc230/p/17486690.html

(版权归原作者所有,侵删)

微信扫码关注该文公众号作者

戳这里提交新闻线索和高质量文章给我们。
相关阅读
配置MySQL主从复制和读写分离我在淘宝写SQL|ODPS SQL 优化总结Centos下SFTP双机高可用环境部署记录python操作MySQL和实战【深入学习MySQL】MySQL的索引结构为什么使用B+树?熔断、隔离、重试、降级、超时、限流,一文帮你顺理高可用架构流量治理MySQL 9.0“创新版”已支持向量,为何甲骨文却“偷偷摸摸”地宣布?蜂窝架构:一种云端高可用性架构MySQL忘记root密码解决方案Python中使用MySQL模糊查询的方法一些数据库专家称,最新的 MySQL 版本令人失望百年无痕 2.5SQL 50 周年了,但 SQL 之父已经“投靠”NoSQL 了新罕布什尔州-菲利普斯埃克塞特中学 Phillips Exeter Academy项目从 MySQL 切换 PostgreSQL,踩了太多的坑!!!Twitter的中国人,机器学习玩SQL,牛逼大了。。。MySQL已死,PostgreSQL当立2024春假伦敦邮轮行之伦敦手把手带你从自建 MySQL 迁移到云数据库,一步就能脱胎换骨不引入ES,如何利用 MySQL 实现模糊匹配区区1万张表就把MySQL给整崩溃了甲骨文杀死了MySQL面向数据库的操作系统:80 岁的 PostgreSQL 之父宣布推出 DBOS CloudMySQL的多存储引擎架构MySQL联表查询优化8 种专坑运维的 SQL 写法,性能降低 100 倍,您不来看看?一个SQL任务的一生总理难做雪后 背影MySQL版本越高,性能越差,这你受得了吗?MySQL索引你用对了吗?MySQL慢查询及优化MySQL 巨坑:永远不要在 MySQL 中使用 UTF-8!34、长篇家庭伦理小说《嫁接 下》第十二章 异国情缘(1)爆发式增长业务的高可用架构优化之路
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。