mysql+zabbix升级方案(上)

目前项目案例中,企业内部使用zabbix版本为3.4,考虑到新版zabbix更新了较多具有可用性的功能,但同时期望保留原始环境下自定义脚本监控项部分,且保留原有采集数据及配置信息等,决定采用原架构基础上升级的方案进行更新

1. 方案背景

方案中原先server及数据库架构如下所示:

7Ds8NZb9638dbb22b7d81.png

server上搭建web服务及zabbix_server服务,使用pcs进行高可用配置

mysql数据库则使用主备方式搭配keepalived服务生成VIP会外提供服务

以下方案中,主zabbix_server服务器简称为“主机”,备zabbix_server服务器简称为“备机”,主mysql库简称为“主库”,备mysql库简称为“备库”。


2. 方案概述

本方案大致从以下步骤出发,实现zabbix跨版本保留原数据的方式升级:

关闭备机pcsd服务——关闭备库keepalived服务,停止备库slave同步——升级备库到mysql8版本——升级备机到zabbix6.0版本——使备机的zabbix_serverDB指向备库,实现备库zabbix库自检升级——启用备机pcsd服务——关闭主机pcsd服务——升级主机到zabbix6.0版本——启用备库keepalived——关闭主库同keepalived,同时修改主备机zabbix_serverDB指向VIP——升级主库到mysql8版本——全量备份备库数据到主库——配置主库为备库的slave启用同步

 

3. 方案实例环境说明

方案编写环境IP如下:

server192.168.164.222

server192.168.164.223

serverVIP192.168.164.225

mysql192.168.164.220

mysql192.168.164.221

DBVIP192.168.164.224

 

操作系统环境:CentOS7

原环境mysql版本:yum方式安装mysql-5.7.22

原环境zabbix版本:yum方式安装zabbix_server 3.4.15

原环境php版本: yum方式安装php 5.4.16


4. 方案实施手册

4.1     关闭备机pcsd服务

# service pcsd stop

 

[root@server-2 ~]# service pcsd status

Redirecting to /bin/systemctl status pcsd.service

pcsd.service - PCS GUI and remote configuration interface

   Loaded: loaded (/usr/lib/systemd/system/pcsd.service; enabled; vendor preset: disabled)

   Active: active (running) since Wed 2022-11-02 01:02:37 CST; 19min ago

     Docs: man:pcsd(8)

           man:pcs(8)

 Main PID: 3080 (pcsd)

   CGroup: /system.slice/pcsd.service

           └─3080 /usr/bin/ruby /usr/lib/pcsd/pcsd

 

Nov 02 01:02:37 server-2 systemd[1]: Starting PCS GUI and remote configuration interface...

Nov 02 01:02:37 server-2 systemd[1]: Started PCS GUI and remote configuration interface.

Hint: Some lines were ellipsized, use -l to show in full.

[root@server-2 ~]# service pcsd stop

Redirecting to /bin/systemctl stop pcsd.service

[root@server-2 ~]#

 

4.2     关闭备库keepalived服务,停止备库slave同步

# service keepalived stop

# mysql -uroot -pp@ssw0rd -e "stop slave"

# mysql -uroot -pp@ssw0rd -e "show slave status\G"

 

[root@db-2 keepalived]# service keepalived status

Redirecting to /bin/systemctl status keepalived.service

keepalived.service - LVS and VRRP High Availability Monitor

   Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)

   Active: active (running) since Wed 2022-11-02 00:55:10 CST; 27min ago

  Process: 3440 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)

 Main PID: 3441 (keepalived)

   CGroup: /system.slice/keepalived.service

           ├─3441 /usr/sbin/keepalived -D

           ├─3442 /usr/sbin/keepalived -D

           └─3443 /usr/sbin/keepalived -D

 

Nov 02 00:55:10 db-2 Keepalived_vrrp[3443]: Registering Kernel netlink command...l

Nov 02 00:55:10 db-2 Keepalived_vrrp[3443]: Registering gratuitous ARP shared ...l

Nov 02 00:55:10 db-2 Keepalived_vrrp[3443]: Opening file '/etc/keepalived/keep....

Nov 02 00:55:10 db-2 Keepalived_vrrp[3443]: VRRP_Instance(VI_1) removing proto....

Nov 02 00:55:10 db-2 Keepalived_vrrp[3443]: Using LinkWatch kernel netlink ref....

Nov 02 00:55:10 db-2 Keepalived_vrrp[3443]: VRRP_Instance(VI_1) Entering BACKU...E

Nov 02 00:55:10 db-2 Keepalived_vrrp[3443]: VRRP sockpool: [ifindex(2), proto(...]

Nov 02 00:55:10 db-2 Keepalived_healthcheckers[3442]: IPVS (cmd 1154, errno 2):...

Nov 02 00:55:10 db-2 Keepalived_healthcheckers[3442]: IPVS (cmd 1159, errno 2):...

Nov 02 00:55:10 db-2 Keepalived_healthcheckers[3442]: Activating healthchecker ...

Hint: Some lines were ellipsized, use -l to show in full.

[root@db-2 keepalived]# service keepalived stop

Redirecting to /bin/systemctl stop keepalived.service

[root@db-2 keepalived]# mysql -uroot -pp@ssw0rd -e "stop slave"

mysql: [Warning] Using a password on the command line interface can be insecure.

[root@db-2 ~]# mysql -uroot -pp@ssw0rd -e "show slave status\G"

mysql: [Warning] Using a password on the command line interface can be insecure.

*************************** 1. row ***************************

               Slave_IO_State:

                  Master_Host: 192.168.164.220

                  Master_User: sync

                  Master_Port: 3306

                Connect_Retry: 60

              Master_Log_File: mysql-bin.000002

          Read_Master_Log_Pos: 4772275

               Relay_Log_File: db-2-relay-bin.000005

                Relay_Log_Pos: 4772488

        Relay_Master_Log_File: mysql-bin.000002

             Slave_IO_Running: No

            Slave_SQL_Running: No

              Replicate_Do_DB:

          Replicate_Ignore_DB:

           Replicate_Do_Table:

       Replicate_Ignore_Table:

      Replicate_Wild_Do_Table:

  Replicate_Wild_Ignore_Table:

                   Last_Errno: 0

                   Last_Error:

                 Skip_Counter: 0

          Exec_Master_Log_Pos: 4772275

              Relay_Log_Space: 4772860

              Until_Condition: None

               Until_Log_File:

                Until_Log_Pos: 0

           Master_SSL_Allowed: No

           Master_SSL_CA_File:

           Master_SSL_CA_Path:

              Master_SSL_Cert:

            Master_SSL_Cipher:

               Master_SSL_Key:

        Seconds_Behind_Master: NULL

Master_SSL_Verify_Server_Cert: No

                Last_IO_Errno: 0

                Last_IO_Error:

               Last_SQL_Errno: 0

               Last_SQL_Error:

  Replicate_Ignore_Server_Ids:

             Master_Server_Id: 1

                  Master_UUID: 6f810647-5a14-11ed-b8fc-000c2905e60a

             Master_Info_File: /var/lib/mysql/master.info

                    SQL_Delay: 0

          SQL_Remaining_Delay: NULL

      Slave_SQL_Running_State:

           Master_Retry_Count: 86400

                  Master_Bind:

      Last_IO_Error_Timestamp:

     Last_SQL_Error_Timestamp:

               Master_SSL_Crl:

           Master_SSL_Crlpath:

           Retrieved_Gtid_Set:

            Executed_Gtid_Set:

                Auto_Position: 0

         Replicate_Rewrite_DB:

                 Channel_Name:

           Master_TLS_Version:

[root@db-2 ~]#

4.3     升级备库到mysql8版本

4.3.1 原数据库数据备份

# service mysqld stop

# cp -rf /var/lib/mysql/ /data/mysql 

##进程或配置文件中查询到数据库存储路径进行备份

# cp /etc/keepalived/keepalived.conf /data/

##卸载当前版本mysql可能会有依赖卸载keepalived,提前备份配置文件,4.7章节会用到该配置文件

# yum remove mysql-c* -y

 

[[root@db-2 ~]# ps -ef | grep mysql

mysql      1135      1  0 08:34 ?        00:00:46 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

root       1817   1525  0 14:18 pts/0    00:00:00 grep --color=auto mysql

[root@db-2 ~]# grep data /etc/my.cnf

# Remove leading # and set to the amount of RAM for the most important data

# Remove leading # to turn on a very important data integrity option: logging

datadir=/var/lib/mysql

mysql: [Warning] Using a password on the command line interface can be insecure.

[root@db-2 ~]# service mysqld stop

Redirecting to /bin/systemctl stop mysqld.service

[root@db-2 ~]#

[root@db-2 mysql_packages]# cp -rf /var/lib/mysql/ /data/mysql

[root@db-2 mysql_packages]# cp /etc/keepalived/keepalived.conf /data/

[root@db-2 mysql_packages]# yum remove mysql-c* -y

Loaded plugins: fastestmirror

Resolving Dependencies

--> Running transaction check

---> Package mysql-community-client.x86_64 0:5.7.22-1.el7 will be erased

---> Package mysql-community-common.x86_64 0:5.7.22-1.el7 will be erased

---> Package mysql-community-devel.x86_64 0:5.7.22-1.el7 will be erased

---> Package mysql-community-embedded.x86_64 0:5.7.22-1.el7 will be erased

---> Package mysql-community-embedded-compat.x86_64 0:5.7.22-1.el7 will be erased

---> Package mysql-community-embedded-devel.x86_64 0:5.7.22-1.el7 will be erased

---> Package mysql-community-libs.x86_64 0:5.7.22-1.el7 will be erased

---> Package mysql-community-libs-compat.x86_64 0:5.7.22-1.el7 will be erased

--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 1:net-snmp-agent-libs-5.7.2-49.el7_9.2.x86_64

--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 1:net-snmp-agent-libs-5.7.2-49.el7_9.2.x86_64

---> Package mysql-community-minimal-debuginfo.x86_64 0:5.7.22-1.el7 will be erased

---> Package mysql-community-server.x86_64 0:5.7.22-1.el7 will be erased

---> Package mysql-community-test.x86_64 0:5.7.22-1.el7 will be erased

--> Running transaction check

 

….

 

Removed:

  mysql-community-client.x86_64 0:5.7.22-1.el7               mysql-community-common.x86_64 0:5.7.22-1.el7          

  mysql-community-devel.x86_64 0:5.7.22-1.el7                mysql-community-embedded.x86_64 0:5.7.22-1.el7        

  mysql-community-embedded-compat.x86_64 0:5.7.22-1.el7      mysql-community-embedded-devel.x86_64 0:5.7.22-1.el7  

  mysql-community-libs.x86_64 0:5.7.22-1.el7                 mysql-community-libs-compat.x86_64 0:5.7.22-1.el7     

  mysql-community-minimal-debuginfo.x86_64 0:5.7.22-1.el7    mysql-community-server.x86_64 0:5.7.22-1.el7          

  mysql-community-test.x86_64 0:5.7.22-1.el7               

 

Dependency Removed:

  keepalived.x86_64 0:1.3.5-19.el7                   net-snmp-agent-libs.x86_64 1:5.7.2-49.el7_9.2                 

 

Complete!

[root@db-2 mysql_packages]#

[root@db-2 mysql_packages]#


4.3.2 安装数据库mysql8.0

# mkdir mysql_8

# tar xf mysql-8.0.22-1.el7.x86_64.rpm-bundle.tar -C mysql_8/

# cd mysql_8/

# yum localinstall -y ./mysql-community-*rpm

# vim /etc/my.cnf

skip_slave_start  ##mysql增加此行后,不会自动启用slave同步,主库升级时不需要该参数

# service mysqld start

# ss -lnt

 

[root@db-2 ~]# mkdir mysql_8

[root@db-2 ~]# tar xf mysql-8.0.22-1.el7.x86_64.rpm-bundle.tar -C mysql_8/

[root@db-2 ~]# cd mysql_8/

[root@db-2 mysql_8]# yum localinstall -y ./mysql-community-*rpm

Loaded plugins: fastestmirror

Examining ./mysql-community-client-8.0.22-1.el7.x86_64.rpm: mysql-community-client-8.0.22-1.el7.x86_64

Marking ./mysql-community-client-8.0.22-1.el7.x86_64.rpm to be installed

Examining ./mysql-community-client-plugins-8.0.22-1.el7.x86_64.rpm: mysql-community-client-plugins-8.0.22-1.el7.x86_64

Marking ./mysql-community-client-plugins-8.0.22-1.el7.x86_64.rpm to be installed

Examining ./mysql-community-common-8.0.22-1.el7.x86_64.rpm: mysql-community-common-8.0.22-1.el7.x86_64

Marking ./mysql-community-common-8.0.22-1.el7.x86_64.rpm to be installed

Examining ./mysql-community-devel-8.0.22-1.el7.x86_64.rpm: mysql-community-devel-8.0.22-1.el7.x86_64

Marking ./mysql-community-devel-8.0.22-1.el7.x86_64.rpm to be installed

Examining ./mysql-community-embedded-compat-8.0.22-1.el7.x86_64.rpm: mysql-community-embedded-compat-8.0.22-1.el7.x86_64

Marking ./mysql-community-embedded-compat-8.0.22-1.el7.x86_64.rpm to be installed

Examining ./mysql-community-libs-8.0.22-1.el7.x86_64.rpm: mysql-community-libs-8.0.22-1.el7.x86_64

Marking ./mysql-community-libs-8.0.22-1.el7.x86_64.rpm to be installed

Examining ./mysql-community-libs-compat-8.0.22-1.el7.x86_64.rpm: mysql-community-libs-compat-8.0.22-1.el7.x86_64

Marking ./mysql-community-libs-compat-8.0.22-1.el7.x86_64.rpm to be installed

Examining ./mysql-community-server-8.0.22-1.el7.x86_64.rpm: mysql-community-server-8.0.22-1.el7.x86_64

Marking ./mysql-community-server-8.0.22-1.el7.x86_64.rpm to be installed

Examining ./mysql-community-test-8.0.22-1.el7.x86_64.rpm: mysql-community-test-8.0.22-1.el7.x86_64

Marking ./mysql-community-test-8.0.22-1.el7.x86_64.rpm to be installed

Resolving Dependencies

--> Running transaction check

---> Package mysql-community-client.x86_64 0:8.0.22-1.el7 will be installed

---> Package mysql-community-client-plugins.x86_64 0:8.0.22-1.el7 will be installed

---> Package mysql-community-common.x86_64 0:8.0.22-1.el7 will be installed

---> Package mysql-community-devel.x86_64 0:8.0.22-1.el7 will be installed

---> Package mysql-community-embedded-compat.x86_64 0:8.0.22-1.el7 will be installed

---> Package mysql-community-libs.x86_64 0:8.0.22-1.el7 will be installed

---> Package mysql-community-libs-compat.x86_64 0:8.0.22-1.el7 will be installed

---> Package mysql-community-server.x86_64 0:8.0.22-1.el7 will be installed

---> Package mysql-community-test.x86_64 0:8.0.22-1.el7 will be installed

--> Finished Dependency Resolution

 

Dependencies Resolved

 

===============================================================================================================

 Package                        Arch   Version      Repository                                            Size

===============================================================================================================

Installing:

 mysql-community-client         x86_64 8.0.22-1.el7 /mysql-community-client-8.0.22-1.el7.x86_64          230 M

 mysql-community-client-plugins x86_64 8.0.22-1.el7 /mysql-community-client-plugins-8.0.22-1.el7.x86_64  1.0 M

 mysql-community-common         x86_64 8.0.22-1.el7 /mysql-community-common-8.0.22-1.el7.x86_64          8.9 M

 mysql-community-devel          x86_64 8.0.22-1.el7 /mysql-community-devel-8.0.22-1.el7.x86_64            58 M

 mysql-community-embedded-compat

                                x86_64 8.0.22-1.el7 /mysql-community-embedded-compat-8.0.22-1.el7.x86_64  90 M

 mysql-community-libs           x86_64 8.0.22-1.el7 /mysql-community-libs-8.0.22-1.el7.x86_64             22 M

 mysql-community-libs-compat    x86_64 8.0.22-1.el7 /mysql-community-libs-compat-8.0.22-1.el7.x86_64     6.1 M

 mysql-community-server         x86_64 8.0.22-1.el7 /mysql-community-server-8.0.22-1.el7.x86_64          2.3 G

 mysql-community-test           x86_64 8.0.22-1.el7 /mysql-community-test-8.0.22-1.el7.x86_64            678 M

 

Transaction Summary

===============================================================================================================

Install  9 Packages

 

Total size: 3.4 G

Installed size: 3.4 G

Downloading packages:

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  Installing : mysql-community-common-8.0.22-1.el7.x86_64                                                  1/9

  Installing : mysql-community-client-plugins-8.0.22-1.el7.x86_64                                          2/9

  Installing : mysql-community-libs-8.0.22-1.el7.x86_64                                                    3/9

  Installing : mysql-community-client-8.0.22-1.el7.x86_64                                                  4/9

  Installing : mysql-community-server-8.0.22-1.el7.x86_64                                                  5/9

  Installing : mysql-community-test-8.0.22-1.el7.x86_64                                                    6/9

  Installing : mysql-community-devel-8.0.22-1.el7.x86_64                                                   7/9

  Installing : mysql-community-libs-compat-8.0.22-1.el7.x86_64                                             8/9

  Installing : mysql-community-embedded-compat-8.0.22-1.el7.x86_64                                         9/9

  Verifying  : mysql-community-libs-8.0.22-1.el7.x86_64                                                    1/9

  Verifying  : mysql-community-server-8.0.22-1.el7.x86_64                                                  2/9

  Verifying  : mysql-community-client-plugins-8.0.22-1.el7.x86_64                                          3/9

  Verifying  : mysql-community-common-8.0.22-1.el7.x86_64                                                  4/9

  Verifying  : mysql-community-embedded-compat-8.0.22-1.el7.x86_64                                         5/9

  Verifying  : mysql-community-devel-8.0.22-1.el7.x86_64                                                   6/9

  Verifying  : mysql-community-client-8.0.22-1.el7.x86_64                                                  7/9

  Verifying  : mysql-community-test-8.0.22-1.el7.x86_64                                                    8/9

  Verifying  : mysql-community-libs-compat-8.0.22-1.el7.x86_64                                             9/9

 

Installed:

  mysql-community-client.x86_64 0:8.0.22-1.el7           mysql-community-client-plugins.x86_64 0:8.0.22-1.el7

  mysql-community-common.x86_64 0:8.0.22-1.el7           mysql-community-devel.x86_64 0:8.0.22-1.el7         

  mysql-community-embedded-compat.x86_64 0:8.0.22-1.el7  mysql-community-libs.x86_64 0:8.0.22-1.el7          

  mysql-community-libs-compat.x86_64 0:8.0.22-1.el7      mysql-community-server.x86_64 0:8.0.22-1.el7        

  mysql-community-test.x86_64 0:8.0.22-1.el7           

 

Complete!

[root@db-2 mysql_8]# [root@db-2 mysql_packages]# vim /etc/my.cnf

[mysqld]

##新增内容:

skip_slave_start

 

[root@db-2 mysql_packages]# service mysqld start

Redirecting to /bin/systemctl start mysqld.service

[root@db-2 mysql_packages]#ss -lnt

State      Recv-Q Send-Q             Local Address:Port                            Peer Address:Port             

LISTEN     0      128                            *:22                                         *:*                 

LISTEN     0      70                          [::]:33060                                   [::]:*                 

LISTEN     0      128                         [::]:3306                                    [::]:*                 

LISTEN     0      128                         [::]:22                                      [::]:*    

[root@db-2 mysql_packages]#


相关问题

1 条评论

请先 登录 后评论
小黄人
小黄人

8 篇文章

作家榜 »

  1. 乐维君 397 文章
  2. YOHOHO 14 文章
  3. 机灵小和尚 13 文章
  4. 我是一只小菜鸡 12 文章
  5. 细雨闲花 11 文章
  6. 。。。 9 文章
  7. 御前侍卫张五哥 9 文章
  8. 小黄人 8 文章