amegonの雑なブログ

日常的なものから技術的なものまでメモの雑記

Zabbix サーバーの DB を別に構築したサーバーに移行する手順のまとめ

実現したいこと

  • CentOS 7 環境で稼働している Zabbix の監視データ(監視設定、監視データともに)を Miracle Linux で稼働している Zabbix に移行したい。

きっかけ

自宅で利用している Zabbix サーバーは稼働 OS が CentOS 7 でありサポートが終了してしばらく経過している。 このままだと何かあったときに面倒なので、サポート中の OS で稼働している Zabbix に移行したいと思った。

移行段取り

  • 移行先の OS を MIRACLE LINUX で構築し、Zabbix もインストールしておく
  • 移行元 Zabbix で DB のダンプを実行してダンプファイルを作成
  • 移行先 Zabbix でダンプファイルをインポート

結果

  • OS の種類は違えど Zabbix サーバーのバージョンは LTS のマイナーバージョンまでは合わせていたためか難しいことはなかった。
  • MariaDB のバージョンが移行元(10.1.48)と移行先(10.10.3)で異なっていたが、こちらも問題は発生しなかった。

環境

Zabbix データベース移行手順

データ移行元 Zabbix での作業

データベースのバックアップ作成(dump)

以下のコマンドを実行して dump を作成する。

mysqldump -u zabbix -p zabbix > mysqldump_zabbix_`date +"%Y%m%d"`.sql

データ移行先 Zabbix での作業

データ移行元 Zabbix で作成したバックアップをローカルに保存しておく

今回は root ユーザーで実行していたので、/root の配下にバックアップを置いた。

[root@ml86 ~]# ls -la /root/mysqldump_zabbix_20230510.sql
-rw-r--r-- 1 root root 483217015  5月  9 18:51 /root/mysqldump_zabbix_20230510.sql
[root@ml86 ~]#

データベースの移行(リストア)

以下の手順で実施。

  • Zabbix サーバーの停止
  • MaridDB から zabbix データベースの削除
  • MaridDB の停止
  • MaridDB のログファイルの削除
  • MaridDB の起動
  • MaridDB に zabbix データベースを再作成
  • MaridDB の zabbix ユーザーに zabbix データベースへのアクセス権を追加
  • バックアップファイルからデータベースのリストア
  • Zabbix サーバーの再起動

以下、コマンド実行順序

systemctl stop zabbix-server
mysql -e"drop database zabbix;"
systemctl stop mysql
rm /var/lib/mysql/ib_logfile0
rm /var/lib/mysql/ibdata*
systemctl start mysql
mysql -e"create database zabbix character set utf8 collate utf8_bin;"
mysql -e"grant all privileges on zabbix.* to zabbix@localhost;"
mysql zabbix < /root/mysqldump_zabbix_20230510.sql
systemctl start zabbix-server

Zabbix の稼働状態を確認

zabbix_server.log

  1995:20230509:193112.958 Starting Zabbix Server. Zabbix 5.0.32 (revision 44d6302efbd).
  1995:20230509:193112.958 ****** Enabled features ******
  1995:20230509:193112.958 SNMP monitoring:           YES
  1995:20230509:193112.958 IPMI monitoring:           YES
  1995:20230509:193112.958 Web monitoring:            YES
  1995:20230509:193112.958 VMware monitoring:         YES
  1995:20230509:193112.958 SMTP authentication:       YES
  1995:20230509:193112.959 ODBC:                      YES
  1995:20230509:193112.959 SSH support:               YES
  1995:20230509:193112.959 IPv6 support:              YES
  1995:20230509:193112.959 TLS support:               YES
  1995:20230509:193112.959 ******************************
  1995:20230509:193112.959 using configuration file: /etc/zabbix/zabbix_server.conf
  1995:20230509:193112.963 current database version (mandatory/optional): 05000000/05000005
  1995:20230509:193112.963 required mandatory version: 05000000
  1995:20230509:193112.963 optional patches were found
  1995:20230509:193112.963 starting automatic database upgrade
  1995:20230509:193113.010 completed 50% of database upgrade
  1995:20230509:193113.013 completed 100% of database upgrade
  1995:20230509:193113.013 database upgrade fully completed
  1995:20230509:193113.021 server #0 started [main process]
  1996:20230509:193113.022 server #1 started [configuration syncer #1]
  1998:20230509:193113.432 server #3 started [alerter #1]
  1999:20230509:193113.434 server #4 started [alerter #2]
  1997:20230509:193113.435 server #2 started [alert manager #1]
  2000:20230509:193113.436 server #5 started [alerter #3]
  2001:20230509:193113.438 server #6 started [preprocessing manager #1]
  2002:20230509:193113.440 server #7 started [preprocessing worker #1]
  2003:20230509:193113.443 server #8 started [preprocessing worker #2]
  2005:20230509:193113.444 server #10 started [lld manager #1]
  2004:20230509:193113.446 server #9 started [preprocessing worker #3]
  2006:20230509:193113.446 server #11 started [lld worker #1]
  2007:20230509:193113.447 server #12 started [lld worker #2]
  2008:20230509:193113.450 server #13 started [housekeeper #1]
  2009:20230509:193113.452 server #14 started [timer #1]
  2010:20230509:193113.453 server #15 started [http poller #1]
  2011:20230509:193113.454 server #16 started [discoverer #1]
  2013:20230509:193113.459 server #17 started [history syncer #1]
  2016:20230509:193113.461 server #19 started [history syncer #3]
  2015:20230509:193113.463 server #18 started [history syncer #2]
  2022:20230509:193113.469 server #21 started [escalator #1]
  2021:20230509:193113.472 server #20 started [history syncer #4]
  2023:20230509:193113.477 server #22 started [proxy poller #1]
  2025:20230509:193113.480 server #23 started [self-monitoring #1]
  2027:20230509:193113.482 server #24 started [task manager #1]
  2028:20230509:193113.483 server #25 started [poller #1]
  2029:20230509:193113.485 server #26 started [poller #2]
  2034:20230509:193113.487 server #29 started [poller #5]
  2033:20230509:193113.489 server #28 started [poller #4]
  2032:20230509:193113.491 server #27 started [poller #3]
  2038:20230509:193113.493 server #30 started [unreachable poller #1]
  2039:20230509:193113.494 server #31 started [trapper #1]
  2040:20230509:193113.496 server #32 started [trapper #2]
  2044:20230509:193113.501 server #33 started [trapper #3]
  2047:20230509:193113.503 server #34 started [trapper #4]
  2048:20230509:193113.504 server #35 started [trapper #5]
  2049:20230509:193113.505 server #36 started [icmp pinger #1]
  2052:20230509:193113.506 server #37 started [alert syncer #1]

起動できた。 ただ、起動後に監視できないホストがいる旨のログが記録されていた。 これは移行元の Zabbix と移行後の Zabbix のサーバーの IP アドレスが異なっているから。 最終的には移行後の Zabbix サーバーの IP アドレスを移行元の IP アドレスにあわせる予定なので、今は気にしないことにする。

ブラウザ

ダッシュボードの図。 トリガーで Zabbix Server のバージョンが変わった旨も検知できているので、良いのではないでしょうか。