资讯专栏INFORMATION COLUMN

MySQL双主架构升级实施测试方案

IT那活儿 / 490人阅读
MySQL双主架构升级实施测试方案
点击上方“IT那活儿”公众号,关注后了解更多内容,不管IT什么活儿,干就完了!!!

背景概述

为保障支撑系统的安全、稳定运行,根据公司安全漏洞扫描检查,检查结果中存在安全漏洞,在与安全组协商讨论后,对互联网MySQL数据库进行版本升级,原始版本为5.7.29,升级到5.7.26,以下为测试环境测试方案。

配置信息:

--服务器信息:
信息项
节点1
节点2
主机名
192.168.48.130
192.168.48.131
用途
测试库mgrmaster
测试库mgrslave1
操作系统版本
Centos7.4
Centos7.4
CPU/内存
2C2GB
2C2GB
--数据库版本信息:
信息项
版本
数据库旧版本
5.7.29
数据库新版本
5.7.37



升级实施流程

当前服务器信息以及数据库版本信息

  • 192.168.48.130  mgrmaster
  • 192.168.48.131  mgrslave1
  • MySQL互为主备

2.1 数据库备份

升级前首先对数据库进行全量备份。

2.2 上传新版本二进制文件至服务器

2.3 按顺序升级,slave->primary

检查keepalived运行状态,正在运行的需要关闭。(主库有运行,备库未运行)
#systemctl stop keepalived

2.3.1 Slave

将192.168.48.130作为从库先进行升级:
1)设置关闭数据库为 slow 的方式
mysql> set global innodb_fast_shutdown = 0;
Query OK, 0 rows affected (0.00 sec)

mysql>
 select @@innodb_fast_shutdown;
+------------------------+
| @@innodb_fast_shutdown |
+------------------------+
| 0 |
+------------------------+
1 row in set (0.00 sec)

mysql>
 shutdown;
Query OK, 0 rows affected (0.04 sec)
2)解压安装包,原版本使用二进制的方式安装,故修改路径软链接即可使用替换数据库软件的目的
[root@mgrmaster my3306]# tar -xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
[root@mgrmaster my3306]# unlink mysql
[root@mgrmaster my3306]# ln -s mysql-5.7.37-linux-glibc2.12-x86_64 mysql
3)启动数据库并登录验证
[root@mgrmaster my3306]# ./mysql/bin/mysqld_safe --defaults-file=/home/my3306/my.cnf &

[root@mgrmaster my3306]# mysql -uroot -p -S /home/my3306/run/mysql.sock
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 4
Server version: 5.7.37-log MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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 h for help. Type c to clear the current input statement.
4)升级数据字典
[root@mgrmaster my3306]# ./mysql/bin/mysql_upgrade -uroot -p123456
mysql_upgrade: [Warning] Using a password on the command line interface can be insecure.
Checking if update is needed.
Running queries to upgrade MySQL server.
Checking system database.
mysql.columns_priv OK
mysql.db OK
mysql.engine_cost OK
mysql.event OK
mysql.func OK
mysql.general_log OK
mysql.gtid_executed OK
mysql.help_category OK
mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.innodb_index_stats OK
mysql.innodb_table_stats OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.server_cost OK
mysql.servers OK
mysql.slave_master_info OK
mysql.slave_relay_log_info OK
mysql.slave_worker_info OK
mysql.slow_log OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
mysql.time_zone_name OK
mysql.time_zone_transition OK
mysql.time_zone_transition_type OK
mysql.user OK
The sys schema is already up to date (version 1.5.1).
Checking databases.
huayu.a                                            OK
huayu.t1 OK
huayu.t2 OK
percona.checksums OK
sys.sys_config OK
test.checksums OK
Upgrade process completed successfully.
Checking if update is needed.
5)重启数据库
[root@mgrmaster my3306]# ./mysql/bin/mysqladmin -uroot -p123456 shutdown
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
2022-06-30T03:07:13.300940Z mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended
[root@mgrmaster my3306]# ./mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &
6)登录数据库检查,主备已经自动创建连接
mysql> show slave status G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.XX.131
Master_User: repl
Master_Port: 3306
Connect_Retry: 10
Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos: 194
Relay_Log_File: mgrmaster-relay-bin.000011
Relay_Log_Pos: 367
Relay_Master_Log_File: mysql-bin.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
检查正常同步,没有报错。
Seconds_Behind_Master: 0
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates

2.3.2 primary同理升级

mysql> show slave status G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.XX.130
Master_User: repl
Master_Port: 3306
Connect_Retry: 10
Master_Log_File: mysql-bin.000042
Read_Master_Log_Pos: 194
Relay_Log_File: mgrslave1-relay-bin.000010
Relay_Log_Pos: 407
Relay_Master_Log_File: mysql-bin.000042
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
检查同步以及延迟均正常:
Seconds_Behind_Master: 0
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates

在主库启动#systemctl start keepalived。


回退方案

若在升级过程中,遇到报错:

首先检查error日志对错误进行排查。如果问题无法解决,则进行版本回退。

回退方法:
如果启动失败,重新以原来的软件版本启动。
  • 清理redo log文件

#rm -f /home/my3306/data/ ib_logfile{0,1,2,3}
  • 清理link,启动旧版本

#unlink mysql
# ln –s /opt/mysql-5.7.29-linux-glibc2.12-x86_64 mysql
  #mysqld_safe --defaults-file=/home/my3306/my.cnf &



本文作者:吴 昊(上海新炬中北团队)

本文来源:“IT那活儿”公众号

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/129123.html

相关文章

  • MySQL高可用方案测试

    MySQL高可用方案测试 img{ display:block; margin:0 auto !important; width:100%; } body{ width:75%; margin...

    IT那活儿 评论0 收藏2496
  • 搭载超高性能RSSD云盘的快杰云数据库UDB重磅上线

    摘要:关于快杰云主机的性能表现,已在阿里云腾讯云华为云云主机对比测试报告中详细测试对比过,其对数据库的支持能力尤为突出。快杰经过此次架构和硬件升级,无论是对比自建,还是友商同等配置下的,其高性能和高性价比都是企业部署高性能数据库的优秀选择。2020年4月中旬,UCloud云数据库产品线发布了MySQL版本的快杰UDB,作为UDB产品架构升级后的最新一代云数据库,快杰UDB采用了业内主流的计算存储分...

    Pluser 评论0 收藏0

发表评论

0条评论

IT那活儿

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<