MySQL-Xenon高可用

马哥Linux运维

共 9586字,需浏览 20分钟

 ·

2024-05-19 20:30


在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

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

浏览 78
点赞
评论
收藏
分享

手机扫一扫分享

分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

分享
举报