zabbixがエラーを吐いて、起動しなくなった。
ZabbixにWebアクセスすると、以下のようなメッセージが出ている。
どうやら、mysqldが止まっている模様
Dtabase error connectiong to database [Can’t connect to local MySQL server though ‘var/lib/mysql/mysql.sock'(2)]

/etc/init.d/mysqld status で確認すると
mysqldは停止していますがサブシテムがロックされています
と表示されている・・・・
どうやらmysqldが正常な手順ではなく、異常終了してしまった状態のようだ。
サーバ自身を再起動してもだめなので、もう少しし並べて見ると、
Mysqlのログに、いやなメッセージが・・・・
tail -30 /var/log/mysqld.log
InnoDB: Page number (if stored to page already) 40416,
InnoDB: space id (if created with >= MySQL-4.1.1 and stored already) 0
InnoDB: Page may be an index page where index id is 0 440
InnoDB: (index "history_uint_1" of table "zabbix"."history_uint")
InnoDB: Database page corruption on disk or a failed
InnoDB: file read of page 40416.
InnoDB: You may have to recover from a backup.
InnoDB: It is also possible that your operating
InnoDB: system has corrupted its own file cache
InnoDB: and rebooting your computer removes the
InnoDB: error.
InnoDB: If the corrupt page is an index page
InnoDB: you can also try to fix the corruption
InnoDB: by dumping, dropping, and reimporting
InnoDB: the corrupt table. You can use CHECK
InnoDB: TABLE to scan your table for corruption.
InnoDB: See also http://dev.mysql.com/doc/refman/5.1/en/forcing-innodb-recovery.html
InnoDB: about forcing recovery.
InnoDB: Ending processing because of a corrupt database page.
どうやらテーブルのインデックスが壊れているようなメッセージを発見。
でももう少しあがいてみる。
/etc/my.cnfを開いて以下の行を[mysqld]に追加(リカバリモードでの起動を指示)
innodb_force_recovery = 1
で、rebootコマンドで再起動してみた。
reboot
dbが起動したことを確認
/etc/init.d/mysqld status
[root@zabbix2 ~]# /etc/init.d/mysqld status
mysqld (pid 1433) を実行中...
とりあえず、Mysqlの起動はしている模様。
この状態でZabbixにWebアクセスすると、
とりあえず起動はするが、あちこちにUpdateに失敗した旨がされている・・・・
たぶんリカバリモードで起動しているので、DatabaseがReadOnlyモードになっているせいでしょう。

この状態でDB全体をチェックしてみる
mysqlcheck -c zabbix -u zabbix -p
[root@zabbix2 ~]# mysqlcheck -c zabbix -u zabbix -p
Enter password:
zabbix.acknowledges OK
zabbix.actions OK
zabbix.alerts OK
zabbix.application_template OK
zabbix.applications OK
zabbix.auditlog OK
zabbix.auditlog_details OK
zabbix.autoreg_host OK
zabbix.conditions OK
zabbix.config OK
zabbix.dbversion OK
zabbix.dchecks OK
zabbix.dhosts OK
zabbix.drules OK
zabbix.dservices OK
zabbix.escalations OK
zabbix.events OK
zabbix.expressions OK
zabbix.functions OK
zabbix.globalmacro OK
zabbix.globalvars OK
zabbix.graph_discovery OK
zabbix.graph_theme OK
zabbix.graphs OK
zabbix.graphs_items OK
zabbix.group_discovery OK
zabbix.group_prototype OK
zabbix.groups OK
zabbix.history OK
zabbix.history_log OK
zabbix.history_str OK
zabbix.history_str_sync OK
zabbix.history_sync OK
zabbix.history_text OK
zabbix.history_uint
error : Corrupt
zabbix.history_uint_sync OK
zabbix.host_discovery OK
zabbix.host_inventory OK
zabbix.hostmacro OK
zabbix.hosts OK
zabbix.hosts_groups OK
zabbix.hosts_templates OK
zabbix.housekeeper OK
zabbix.httpstep OK
zabbix.httpstepitem OK
zabbix.httptest OK
zabbix.httptestitem OK
zabbix.icon_map OK
zabbix.icon_mapping OK
zabbix.ids OK
zabbix.images OK
zabbix.interface OK
zabbix.interface_discovery OK
zabbix.item_discovery OK
zabbix.items OK
zabbix.items_applications OK
zabbix.maintenances OK
zabbix.maintenances_groups OK
zabbix.maintenances_hosts OK
zabbix.maintenances_windows OK
zabbix.mappings OK
zabbix.media OK
zabbix.media_type OK
zabbix.node_cksum OK
zabbix.nodes OK
zabbix.opcommand OK
zabbix.opcommand_grp OK
zabbix.opcommand_hst OK
zabbix.opconditions OK
zabbix.operations OK
zabbix.opgroup OK
zabbix.opmessage OK
zabbix.opmessage_grp OK
zabbix.opmessage_usr OK
zabbix.optemplate OK
zabbix.profiles OK
zabbix.proxy_autoreg_host OK
zabbix.proxy_dhistory OK
zabbix.proxy_history OK
zabbix.regexps OK
zabbix.rights OK
zabbix.screens OK
zabbix.screens_items OK
zabbix.scripts OK
zabbix.service_alarms OK
zabbix.services OK
zabbix.services_links OK
zabbix.services_times OK
zabbix.sessions OK
zabbix.slides OK
zabbix.slideshows OK
zabbix.sysmap_element_url OK
zabbix.sysmap_url OK
zabbix.sysmaps OK
zabbix.sysmaps_elements OK
zabbix.sysmaps_link_triggers OK
zabbix.sysmaps_links OK
zabbix.timeperiods OK
zabbix.trends OK
zabbix.trends_uint OK
zabbix.trigger_depends OK
zabbix.trigger_discovery OK
zabbix.triggers OK
zabbix.user_history OK
zabbix.users OK
zabbix.users_groups OK
zabbix.usrgrp OK
zabbix.valuemaps OK
やはりzabbix.history_uintが壊れていると出ている。
一応、修復しようとして見ましたが
mysqlcheck -r zabbix history_uint -u zabbix -p
[root@zabbix2 ~]# mysqlcheck -r zabbix history_uint -u zabbix -p
Enter password:
zabbix.history_uint
note : The storage engine for the table doesn't support repair
[root@zabbix2 ~]#
InnoDBなのでできないみたい。
なので、mysqlコマンドからコマンドを実行して更なる調査を実施
まずは、mysqlコマンドを起動
mysql -u zabbix -D zabbix -p
[root@zabbix2 ~]# mysql -u zabbix -D zabbix -p
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 16885
Server version: 5.1.67 Source distribution
Copyright (c) 2000, 2012, 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.
テーブルの状態を再度確認してみると
check table history_uint;
mysql> check table history_uint;
+---------------------+-------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+---------------------+-------+----------+----------+
| zabbix.history_uint | check | error | Corrupt |
+---------------------+-------+----------+----------+
1 row in set (3 hours 7 min 17.94 sec)
mysql>
状況はいっしょですね。
ついでに該当テーブルのインデックスの状況を確認して見ます。
show index from history_uint;
mysql> show index from history_uint;
+--------------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+--------------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| history_uint | 1 | history_uint_1 | 1 | itemid | A | 18 | NULL | NULL | | BTREE | |
| history_uint | 1 | history_uint_1 | 2 | clock | A | 151210951 | NULL | NULL | | BTREE | |
+--------------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
2 rows in set (1.35 sec)
ここから復旧してみます。
まずは該当テーブルのバックアップを取得します。
単純に出力してもよいのだけども、ダンプファイルが巨大になりすぎるので圧縮して出力させます。
mysqldump zabbix history_uint | gzip > history_uint_bk.sql.gz
[root@zabbix2 ~]# mysqldump zabbix history_uint | gzip > history_uint_bk.sql.gz
[root@zabbix2 ~]# ls -al history*
合計 1638736
-rw-r--r-- 1 root root 1646218128 11月 15 18:33 2015 history_uint_bk.sql.gz
[root@zabbix2 ~]#
ダンプ出力が完了したら、壊れたテーブルを削除します。
drop table history_uint;
[root@zabbix2 ~]# mysql -u zabbix -D zabbix -p
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 34325
Server version: 5.1.67 Source distribution
Copyright (c) 2000, 2012, 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.
mysql> drop table history_uint;
Query OK, 0 rows affected (1.26 sec)
mysql> quit
Bye
リカバリモードから通常モードで復帰させてmysqldを起動します。
vi /etc/my.cnf
で以下を変更(コメント化)
#innodb_force_recovery=1
[root@zabbix2 ~]# service mysqld stop
mysqld を停止中: [ OK ]
[root@zabbix2 ~]# service mysqld start
mysqld を起動中: [ OK ]
正常に起動したことを確認したら、先ほど取ったダンプからリストアします。
zcat history_uint_bk.sql.gz | mysql -u zabbix -D zabbix -p
[root@zabbix2 ~]# zcat history_uint_bk.sql.gz | mysql -u zabbix -D zabbix -p
Enter password:
[root@zabbix2 ~]#
リストアが終わったら、壊れたテーブルが正常に戻っているかを確認します。
select count(*) from history_uint;
show index from history_uint;
[root@zabbix2 ~]# mysql -u zabbix -D zabbix -p
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2585
Server version: 5.1.67 Source distribution
Copyright (c) 2000, 2012, 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.
mysql> select count(*) from history_uint;
+-----------+
| count(*) |
+-----------+
| 147589069 |
+-----------+
1 row in set (7 min 51.62 sec)
mysql> show index from history_uint;
+--------------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+--------------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| history_uint | 1 | history_uint_1 | 1 | itemid | A | 18 | NULL | NULL | | BTREE | |
| history_uint | 1 | history_uint_1 | 2 | clock | A | 147589525 | NULL | NULL | | BTREE | |
+--------------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
2 rows in set (0.23 sec)
mysql>
ちゃんとインデックスも戻っていますね
サーバを再起動して、Zabbixが使用できるか確認します。

ちゃんと起動しました。
これでなんとか修復できましたが、なぜ壊れたのかは謎。
取り合えず、もう少しmysqldのチューニングが必要なのかもしれない。
とりあえずZabbix仮想マシンの割り当てメモリを512MBから1GBに増やして、innodb_buffer_pool_sizeを128MB -> 256MBに変更して様子見中。
/etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
character-set-server=utf8
innodb_buffer_pool_size=256M
innodb_log_file_size=32M
innodb_log_files_in_group=2
innodb_flush_method=O_DIRECT
#innodb_force_recovery=1
Zabbixサーバのメモリを2GBとか4GBぐらい割り当てるんだったら、こんな設定例みつけたので故実参考にします。
http://www.zabbix.jp/node/72
http://kometchtech.blog.fc2.com/blog-entry-1290.html
今回の参考URL
http://dev.mysql.com/doc/refman/5.1/en/forcing-innodb-recovery.html
http://cimacoppi.exblog.jp/13146947
http://qiita.com/pugiemonn/items/8a6b322654aa65e2966b
http://www.dbonline.jp/mysql/table/index10.html
http://d.hatena.ne.jp/jitsu102/20120106/1325799325
http://mysql.javarou.com/dat/000389.html
http://www.ah-2.com/2014/06/12/mysq_innodb_database_page_corruption.html
http://kb.odin.com/jp/6586
https://dev.mysql.com/doc/refman/5.6/ja/rebuilding-tables.html
MySQL の壊れたテーブルを修復
http://www.dbonline.jp/mysql/table/index4.html
http://qiita.com/sue738/items/5c8ca15d5d91088e32bf
http://blog.layer8.sh/ja/2011/12/23/mysql%E3%82%92%E9%AB%98%E9%80%9F%E5%8C%96%E3%81%97%E3%81%9F%E3%81%84%E3%81%A8%E3%81%8D%E3%81%AE%E3%83%81%E3%83%A5%E3%83%BC%E3%83%8B%E3%83%B3%E3%82%B0/
http://www.zabbix.jp/node/72
http://kometchtech.blog.fc2.com/blog-entry-1290.html
Zabbixの蓄積系データを初期化するhttp://qiita.com/rui5885/items/e9bd3eefa625a288bb48
全データを削除する
http://mysql.deikou.com/pages/000067.html
http://phpspot.net/php/pgmysqldump%E3%81%A7%E3%83%90%E3%83%83%E3%82%AF%E3%82%A2%E3%83%83%E3%83%97%EF%BC%86%E5%BE%A9%E5%85%83.html
http://www.risewill.co.jp/blog/archives/1111
Views: 45