zoukankan      html  css  js  c++  java
  • (转)625某电商网站数据库宕机故障解决实录(上,下)

    625某电商网站数据库特大故障解决实录(上)
    原文:http://blog.51cto.com/oldboy/1431172
    这是一次,惊心动魄的企业级电商网站数据库在线故障解决实录,故障解决的过程遇到了很多问题,思想的碰撞,解决方案的决策,及实际操作的问题困扰,老男孩尽量原汁原味的描述恢复的全部过程及思想思维过程!老男孩教育版权所有,本内容禁止商业用途。

    目录:
    625某电商网站数据库特大故障解决实录... 1
    1接到电商客户报警... 1
    1.1与客户初步沟通... 1
    1.2深入沟通确定故障恢复方案... 2
    1.3开始故障恢复准备... 4
    1.4开始进行故障恢复*****. 6
    1.5数据库故障恢复后扫尾工作... 15

    1接到电商客户报警

    1.1与客户初步沟通

    昨日接到某电商网站客户电话,说搞秒杀赠送活动,数据库遇到问题了,结果启动起不来了。
    1
    2
    [root@etiantian etc]# /etc/init.d/mysqld start
    Starting MySQL. ERROR! The server quit without updating PID file (/var/run/mysqld/mysqld.pid).
    提示:此部分客户给的是截图,是后期老男孩根据SSH日志整理而来。
    由于时间紧急,本能的提示客户看看/var/run/mysqld/mysqld.pid存在否,如果存在,删除再启动,客户说没有这个PID文件,提示用户用mysqld_safe --user=mysql &启动看看,结果可以启动成功done,但是,端口服务依然起不来。让客户查下mysql启动日志,报错如下:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    [root@etiantian etc]# cat /var/log/mysqld.log
    140624 18:51:58 mysqld_safe Starting mysqld daemon with databases from /data/mysql/
    140624 18:51:58 InnoDB: The InnoDB memory heap is disabled
    140624 18:51:58 InnoDB: Mutexes and rw_locks use GCC atomic builtins
    140624 18:51:58 InnoDB: Compressed tables use zlib 1.2.3
    140624 18:51:58 InnoDB: Initializing buffer pool, size = 768.0M
    140624 18:51:58 InnoDB: Completed initialization of buffer pool
    InnoDB: Error: auto-extending data file ./ibdata1 is of a different size
    InnoDB: 2176 pages (rounded down to MB) than specified in the .cnf file:
    InnoDB: initial 65536 pages, max 0 (relevant if non-zero) pages!
    140624 18:51:58 InnoDB: Could not open or create data files.
    140624 18:51:58 InnoDB: If you tried to add new data files, and it failed here,
    140624 18:51:58 InnoDB: you should now edit innodb_data_file_path in my.cnf back
    140624 18:51:58 InnoDB: to what it was, and remove the new ibdata files InnoDB created
    140624 18:51:58 InnoDB: in this failed attempt. InnoDB only wrote those files full of
    140624 18:51:58 InnoDB: zeros, but did not yet use them in any way. But be careful: do not
    140624 18:51:58 InnoDB: remove old data files which contain your precious data!
    140624 18:51:58 [ERROR] Plugin 'InnoDB' init function returned error.
    140624 18:51:58 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
    140624 18:51:58 [ERROR] Unknown/unsupported storage engine: InnoDB
    140624 18:51:58 [ERROR] Aborting

    140624 18:51:58 [Note] /install/mysql/bin/mysqld: Shutdown complete

    140624 18:51:58 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
    提示:此部分客户给的是截图,是后期老男孩根据SSH日志整理而来。
    红色部分为错误。
    InnoDB: Error: auto-extending data file ./ibdata1 is of a different size140624 18:51:58 [ERROR] Plugin 'InnoDB' init function returned error.
    140624 18:51:58 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
    140624 18:51:58 [ERROR] Unknown/unsupported storage engine: InnoDB
    140624 18:51:58 [ERROR] Aborting
    根据客户的信息和自身的经验基本定位了客户有可能强制终止了进程或者改变了数据文件!
    于是,询问客户故障前和故障后,都做了啥操作,得到的回答如下:
    1
    2
    3
    4
    5
    6
    XXXX 18:53:41
    数据库之前停止响应,killall之前已经没办法做restart重启了
    XXXX 18:53:32
    我觉得有问题,然后killall掉了,然后就起不来了,别的没做。
    根据日志以及客户的描述,基本上断定是强制关闭服务导致innodb表空间或文件异常。
    至此问题原因及故障现象已经确定。
    1.2深入沟通确定故障恢复方案

    由于客户比较着急,人很紧张,且恢复网站提供服务迫在眉睫,老板就在旁边紧盯着客户。。,压力比较大,因此,客户要求老男孩项目团队远程连接介入,代为操作解决。
    和客户确认了责任和风险后!
    立即连接服务器,着手进行了一系列的抢救措施,没有结果。抢救措施有:
    1、杀掉服务重启。2.调整my.cnf相关参数发现某些参数比较大,特别innodb_buffer,调整后依然无法启动。3.调整innodby recover参数。
    由于此前就知道客户是近期刚上线的一个电商网站业务。
    因此和客户沟通。询问客户是否有全量备份及增量备份?得到的回答是客户做了全量备份了。增量没做任何处理。
    问完了客户,我们自己登陆服务器检查客户提供的信息看看是否都是正确的。
    由于时间极其紧迫,客户比较慌张,很多内容自己无法一下说清楚,和老男孩团队又不在一个城市。
    于是我们直接登录服务器,根据常规判断及历史记录(history命令行及/root/.mysql_history文件)找到数据库的配置文件/etc/my.cnf,进而找到了数据库安装路径/install/mysql,数据文件路径/data/mysql。binlog的路径/data/mysql,db备份路径/home/xx/。
    此时急需要确定的是两件事:第一个就是binlog是否完整,第二个就是全备是否有效。于是根据客户描述以及我们自己登陆服务器查看,结果如下。
    第一个binlog数据内容:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    <span style="font-size:16px;"><span style="font-family:'宋体';font-size:16px;">[root@etiantianmysql]# ll
    total118576
    -rw-rw----1 mysql mysql 356515840 Jun 24 18:33 ibdata1
    -rw-rw----1 mysql mysql 5242880 Jun 24 18:33ib_logfile0
    -rw-rw----1 mysql mysql 5242880 Jun 24 18:33ib_logfile1
    drwx------2 mysql mysql 4096 Jun 18 16:39 mysql
    ......
    -rw-rw----1 mysql mysql 126 May 21 10:24mysql-bin.000012
    -rw-rw---- 1 mysql mysql 1356022 May 21 10:35 mysql-bin.000013
    -rw-rw---- 1 mysql mysql 14935771 Jun 18 16:35mysql-bin.000014
    -rw-rw---- 1 mysql mysql 56588034 Jun 24 18:33mysql-bin.000015
    -rw-rw----1 mysql mysql 285 Jun 18 16:39mysql-bin.index
    drwx------2 mysql mysql 4096 May 20 21:22performance_schema
    drwx------2 mysql mysql 20480 May 21 10:28eshop_ett
    drwx------2 mysql mysql 12288 Jun 18 13:53eshop_ett100
    drwx------2 mysql mysql 4096 May 20 21:13 test</span></span>
    根据上述结果,确定binlog内容是正常的。
    开始查看数据库的全备是不是OK的。
    1
    2
    [root@etiantian backup]# ll /home/xxx/eshop_ett100.0624.sql
    -rw-r--r-- 1 root root 55769500 Jun 24 02:21 /home/xxx/eshop_ett100.0624.sql
    结论:全备也是OK的。而且,根据binlog日志的时间以及全备的时间看,数据是对应的。
    实际调查完毕后,和客户进行沟通恢复方案:
    1、如果继续修复数据文件可能时间会比较长,暂时还没头绪。因此,询问客户是不是尽快恢复数据库服务非常重要?得到的答复:“是”。
    由于客户非常着急恢复网站业务(活动广告早都打出去了),也就是立刻提供服务非常重要,但是作为一个DBA来讲,数据也是同样重要的。
    于是老男孩和客户紧急沟通,给出了一个解决方案:由于当时事情紧急,内容简化,原话如下:
    根据你们业务刚上线不久,数据量不是很大,比较好的故障解决方案,就是重建数据库,然后导入备份及增量!我预计整个恢复时间大约10-30分钟左右,数据基本可以做到0损失。也就是说数据不会丢失,最快10分钟可提供服务。
    客户对这个方案的回复是:“很满意”,立刻爽快的答应了我们的数据库故障解决方案。原文如下:
    1
    2
    3
    4
    xxx 19:10:09
    你说的我都同意
    老男孩 19:10:15
    那我开整了
    1.3开始故障恢复准备

    1、关闭web服务
    目的:关闭web的考虑是,防止数据库启动后恢复前用户写入脏数据。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    [root@etiantian data]# ps -ef|grep httpd
    root 28697 1 0 19:15 ? 00:00:00 /install/httpd//bin/httpd -k start
    www 28699 28697 1 19:15 ? 00:00:02 /install/httpd//bin/httpd -k start
    www 28702 28697 0 19:15 ? 00:00:00 /install/httpd//bin/httpd -k start
    www 28703 28697 0 19:15 ? 00:00:00 /install/httpd//bin/httpd -k start
    www 28704 28697 0 19:15 ? 00:00:00 /install/httpd//bin/httpd -k start
    www 28707 28697 0 19:15 ? 00:00:00 /install/httpd//bin/httpd -k start
    www 28709 28697 0 19:15 ? 00:00:00 /install/httpd//bin/httpd -k start
    www 28711 28697 0 19:15 ? 00:00:00 /install/httpd//bin/httpd -k start
    www 28712 28697 0 19:15 ? 00:00:00 /install/httpd//bin/httpd -k start
    www 28713 28697 0 19:15 ? 00:00:00 /install/httpd//bin/httpd -k start
    www 28714 28697 0 19:15 ? 00:00:00 /install/httpd//bin/httpd -k start
    www 28715 28697 0 19:15 ? 00:00:00 /install/httpd//bin/httpd -k start
    www 28716 28697 0 19:15 ? 00:00:00 /install/httpd//bin/httpd -k start
    www 28720 28697 0 19:15 ? 00:00:00 /install/httpd//bin/httpd -k start

    root 28850 26341 0 19:17 pts/5 00:00:00 grep httpd
    [root@etiantian data]# /etc/init.d/httpd stop
    [root@etiantian data]# ps -ef|grep httpd
    root 28855 26341 0 19:17 pts/5 00:00:00 grep httpd
    [root@etiantian data]# ps -ef|grep httpd
    root 28857 26341 0 19:17 pts/5 00:00:00 grep httpd
    [root@etiantian data]# ps -ef|grep httpd
    root 28877 26341 0 19:18 pts/5 00:00:00 grep httpd
    [root@etiantian data]# lsof -i :80
    2、备份当前正在跑得所有线上数据库数据
    目的:不能对客户的数据进行二次破坏数据
    1
    2
    3
    4
    5
    6
    [root@etiantian mysql]# cd ../
    [root@etiantian data]# tar zcvf /server/backup/mysql.tar.gz ./mysql/
    [root@etiantian data]# cp -ap mysql /server/backup/
    [root@etiantian data]# du -sh /server/backup/*
    1230M /server/backup/mysql
    150M /server/backup/mysql.tar.gz
    3、确认全备数据是正常的。手动检查查看
    目的:验证备份的数据确实是OK的,否则后果不堪设想。
    1
    2
    3
    4
    [root@etiantian data]# ll /data/eshop_ett100.0624.sql
    -rw-r--r-- 1 root root 55769500 Jun 24 19:04 /data/eshop_ett100.0624.sql
    [root@etiantian data]# less /data/eshop_ett100.0624.sql
    -- MySQL dump 10.13 Distrib 5.5.33, for Linux (x86_64)
    4、搜集db增量日志
    彻底杀掉mysql服务
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    [root@etiantian data]# killall mysqld
    mysqld: no process killed
    [root@etiantian data]# killall mysqld
    mysqld: no process killed
    [root@etiantian data]# mv mysql /opt/
    [root@etiantian opt]# cd mysql/
    [root@etiantian mysql]# ll
    total 118576
    -rw-r----- 1 mysql mysql 0 Jun 24 18:53 AY1405201820416899ebZ.err
    -rw-rw---- 1 mysql mysql 35651584 Jun 24 18:33 ibdata1
    -rw-rw---- 1 mysql mysql 5242880 Jun 24 18:33 ib_logfile0
    -rw-rw---- 1 mysql mysql 5242880 Jun 24 18:33 ib_logfile1
    drwx------ 2 mysql mysql 4096 Jun 18 16:39 mysql
    ......
    -rw-rw---- 1 mysql mysql 126 May 21 10:24 mysql-bin.000012
    -rw-rw---- 1 mysql mysql 1356022 May 21 10:35 mysql-bin.000013
    -rw-rw---- 1 mysql mysql 14935771 Jun 18 16:35 mysql-bin.000014
    -rw-rw---- 1 mysql mysql 56588034 Jun 24 18:33 mysql-bin.000015
    -rw-rw---- 1 mysql mysql 285 Jun 18 16:39 mysql-bin.index
    drwx------ 2 mysql mysql 4096 May 20 21:22 performance_schema
    drwx------ 2 mysql mysql 24576 May 21 10:28 eshop_ett
    drwx------ 2 mysql mysql 12288 Jun 18 13:53 eshop_ett100
    drwx------ 2 mysql mysql 4096 May 20 21:13 test
    拷贝增量日志,防止被二次破坏。等待恢复。
    1
    [root@etiantian mysql]# cp mysql-bin.000014 mysql-bin.000015 /server/backup/
    至此全部故障修复的全部准备工作完毕。
    欲知后事如何,请看下集。

    1.4开始进行故障恢复*****

    1、重新初始化建库
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    [root@etiantian data]# mkdir mysql
    [root@etiantian data]# chown -R mysql.mysql mysql
    [root@etiantian data]# /install/mysql/scripts/mysql_install_db--basedir=/install/mysql/ --datadir=/data/mysql/ --user=mysql
    Installing MySQL system tables...
    OK
    Filling help tables...
    OK
    To start mysqld at boot time you have to copy
    support-files/mysql.server to the right place for your system

    PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
    To do so, start the server, then issue the following commands:

    /install/mysql//bin/mysqladmin -u root password 'new-password'
    /install/mysql//bin/mysqladmin -u root -h etiantian.cn password'new-password'


    Alternatively you can run:
    /install/mysql//bin/mysql_secure_installation

    which will also give you the option of removing the test
    databases and anonymous user created by default. This is
    strongly recommended for production servers.

    See the manual for more instructions.

    You can start the MySQL daemon with:
    cd /install/mysql/ ; /install/mysql//bin/mysqld_safe &
    You can test the MySQL daemon with mysql-test-run.pl
    cd /install/mysql//mysql-test ; perl mysql-test-run.pl

    Please report any problems with the /install/mysql//scripts/mysqlbugscript!
    2、启动数据库测试登录
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    [root@etiantian data]# /etc/init.d/mysqld start
    Starting MySQL.......................... SUCCESS!
    [root@etiantian data]# mysql
    mysql:Collation'utf8-general_ci' is not a compiled collation and is not specifiedin the '/install/mysql/share/charsets/Index.xml' file
    Welcome to the MySQL monitor. Commands end with ; or g.
    Your MySQL connection id is 1
    Server version: 5.5.33-log Source distribution

    Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rightsreserved.

    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 inputstatement.

    mysql> quit
    -> Ctrl-C -- exit!
    Aborted
    提示:可以登录但是报了一个错误。Collation'utf8-general_ci' is not a compiled collation
    字符集校对规则没有编译进去。奇怪了。由于着急这块当时没有询问客户,浪费了一点时间。只询问了客户数据库备份的命令,因为涉及到建库问题:
    老男孩 19:07:07

    你当时的备份命令

    XX 19:07:10

    XX 19:07:12

    稍等

    XX 19:07:40

    mysqldump -u root -ptest110oldboyeshop_ett100 >eshop_ett100.0624.sql

    XX 19:08:49

    是的

    老男孩 19:09:29

    以后加 -B

    老男孩 19:09:43

    mysql库的用户你知道吧。

    XX 19:09:46

    哦,就是这个选项是吗

    XX 19:09:48

    知道

    老男孩 19:09:51

    就是web用户连接的用户及密码

    XX 19:10:00

    etiantian,test110oldboy

    老男孩 19:18:18

    由于你备份没有加-B,所以需要建库,整个命令及字符集呢

    XX 19:18:28

    utf-8

    XX 19:18:34

    没任何别的东西

    XX 19:19:18

    create database eshop_ett100 utf8

    老男孩 19:19:44

    你这是完整命令么

    XX 19:20:18

    不是,那个utf-8是这个db的默认字符集,没其他任何选项

    XX 19:20:22

    完整的等下我找找

    老男孩 19:21:35

    我写好了,create database eshop_ett100 CHARACTER SET utf8 COLLATE utf8_general_ci;

    XX 19:21:43

    create database test2 DEFAULT CHARACTER SET utf8

    询问完毕

    下面是老男孩操作的过程,查看建库字符集
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    [root@etiantian data]# cat /root/.mysql_history |grep create
    create40database40eshop_ett10040DEFAULT40CHARACTER40SET40utf840COLLATE40utf8_general_ci;确定建库的命令。
    [root@etiantian data]# mysql
    mysql: Collation 'utf8-general_ci' is not a compiled collation andis not specified in the '/install/mysql/share/charsets/Index.xml' file
    Welcome to the MySQL monitor. Commands end with ; or g.
    Your MySQL connection id is 2
    Server version: 5.5.33-log Source distribution

    Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rightsreserved.

    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 inputstatement.

    mysql> create database eshop_ett100 CHARACTER SET utf8 COLLATE utf8_general_ci;
    Query OK, 1 row affected (0.00 sec)

    mysql> quit
    Bye
    3、开始正式尝试恢复故障数据库。
    1
    2
    3
    [root@etiantian data]# mysql eshop_ett100 </home/xxx/eshop_ett100.0624.sql
    mysql: Collation 'utf8-general_ci' is not acompiled collation and is not specified in the'/install/mysql/share/charsets/Index.xml' file
    ERROR 1030 (HY000) at line 46: Got error -1from storage engine
    我晕,报错!看来这个字符集校对规则必须重编了。于是询问客户:
    老男孩 19:22:16

    mysql: Collation 'utf8-general_ci' is not a compiled collation andis not specified in the '/install/mysql/share/charsets/Index.xml' file

    XX 19:22:19

    utf8_general_ci这个东西我编译myhsql的时候写错了,写成utf8-general_ci

    XX 19:23:15

    下划线写成中线了

    XX 19:23:23

    我重编安装下,你觉得好不好

    老男孩 19:24:28

    确实提示不支持

    XX 19:24:43

    应该是下划线

    老男孩 19:24:55

    你重编吧

    XX 19:24:56

    utf8_general_ci

    老男孩 19:25:01

    我等你

    老男孩 19:25:18

    也可以免编译

    老男孩 19:25:52

    mysql-5.5.32-linux2.6-x86_64.tar.gz 没下载地址上传太慢

    老男孩 19:26:00

    你还是重新编译吧

    XX 19:26:07

    马上重编好了

    老男孩 19:26:09

    删掉安装目录我都备好了

    XX 19:26:26

    好,/data需要不需要删除

    老男孩 19:29:22

    都删掉

    老男孩 19:29:28

    安装目录都删掉

    老男孩 19:29:32

    配置文件不要动

    XX 19:29:45

    装好了

    老男孩 19:29:47

    到了make install即可

    XX 19:29:51

    配置文件没动,我cp了一下

    XX 19:29:55

    好了

    老男孩 19:30:28

    OK

    4、数据库重新编译后,老男孩开始进行二次故障恢复。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    [root@etiantian data]# pwd
    /data
    [root@etiantian data]# rm -fr mysql
    [root@etiantian data]# mkdir mysql
    [root@etiantian data]# chown -R mysql.mysql <==这是着急的杰作,连目标都没加,偶也紧张啊。
    chown: missing operand after `mysql.mysql'
    Try `chown --help' for more information.
    [root@etiantian data]# chown -R mysql.mysql mysql
    [root@etiantian data]# /install/mysql/scripts/mysql_install_db--basedir=/install/mysql/ --datadir=/data/mysql/ --user=mysql
    Installing MySQL system tables...
    OK
    Filling help tables...
    OK

    To start mysqld at boot time you have to copy
    support-files/mysql.server to the right place for your system

    PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
    To do so, start the server, then issue the following commands:

    /install/mysql//bin/mysqladmin -u root password 'new-password'
    /install/mysql//bin/mysqladmin -u root -h etiantian.cn password'new-password'

    Alternatively you can run:
    /install/mysql//bin/mysql_secure_installation

    which will also give you the option of removing the test
    databases and anonymous user created by default. This is
    strongly recommended for production servers.

    See the manual for more instructions.

    You can start the MySQL daemon with:
    cd /install/mysql/ ; /install/mysql//bin/mysqld_safe &

    You can test the MySQL daemon with mysql-test-run.pl
    cd /install/mysql//mysql-test ; perl mysql-test-run.pl

    Please report any problems with the /install/mysql//scripts/mysqlbugscript!
    重新初始化完毕
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    [root@etiantian data]# /etc/init.d/mysqld start
    Starting MySQL......................... SUCCESS!
    [root@etiantian data]# mysql
    Welcome to the MySQL monitor. Commands end with ; or g.
    Your MySQL connection id is 1
    Server version: 5.5.33-log Source distribution

    Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rightsreserved.

    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 inputstatement.

    启动成功,并且数据库的登录也完全正常了。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    mysql> show databases;
    +--------------------+
    | Database |
    +--------------------+
    | information_schema |
    | mysql |
    | performance_schema |
    | test |
    +--------------------+
    4 rows in set (0.00 sec)
    建库
    1
    2
    3
    4
    5
    mysql> create database eshop_ett100 CHARACTER SET utf8 COLLATE utf8_general_ci;
    Query OK, 1 row affected (0.00 sec)

    mysql> quit
    Bye
    命令行数据全备恢复:
    1
    2
    [root@etiantian data]# mysql eshop_ett100</home/xxx/eshop_ett100.0624.sql
    ERROR 1030 (HY000) at line 46: Got error -1 from storage engine
    晕,报错。到这里,说实话,当时心里突然一凉,本来很自信的答应客户,100%可以恢复。现在全备有问题。。。。。。完蛋了。这是当时真心的想法。伙伴们勿笑。
    停顿了一下,马上冷静,下意识的看看数据库备份内容没发现异常。
    1
    2
    3
    [root@etiantian data]# less /home/xxx/eshop_ett100.0624.sql
    -- MySQL dump 10.13 Distrib5.5.33, for Linux (x86_64)
    ......
    停顿一下,下意识的感觉这个错误很熟悉,曾经遇到过。然后谷歌了下,找到了答案。解决过程如下:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    [root@etiantian data]# mysql eshop_ett100 </home/xxx/eshop_ett100.0624.sql
    ERROR 1030 (HY000) at line 46: Got error -1 from storage engine
    [root@etiantian data]# /etc/init.d/mysqld stop
    Shutting down MySQL. SUCCESS!
    [root@etiantian data]# vi /etc/my.cnf <==此处顺便调整相关其他参数
    innodb_force_recovery= 0 调整这个参数为0
    skip-external-locking
    key_buffer_size = 256M
    max_allowed_packet = 1M
    table_open_cache = 614
    sort_buffer_size = 1M
    read_buffer_size = 1M
    read_rnd_buffer_size = 4M
    myisam_sort_buffer_size = 64M
    thread_cache_size = 8
    query_cache_size= 16M
    query_cache_limit = 1M
    query_cache_min_res_unit = 2k
    # Try number of CPU's*2 for thread_concurrency
    thread_concurrency = 8
    ........
    "/etc/my.cnf" 159L, 4948C written
    重启服务
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    [root@etiantian data]# /etc/init.d/mysqld start
    Starting MySQL.
    . SUCCESS!
    [root@etiantian data]#
    [root@etiantian data]# mysql
    Welcome to the MySQL monitor. Commands end with ; or g.
    Your MySQL connection id is 1
    Server version: 5.5.33-log Source distribution

    Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rightsreserved.

    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 inputstatement.

    mysql> show databases;
    +--------------------+
    | Database |
    +--------------------+
    | information_schema |
    | mysql |
    | performance_schema |
    | eshop_ett100 |
    | test |
    +--------------------+
    5 rows in set (0.00 sec)
    5、为了防止数据问题,重新建库。
    1
    2
    3
    4
    5
    6
    7
    8
    mysql> drop database eshop_ett100;
    Query OK, 1 row affected (0.01 sec)

    mysql> create database eshop_ett100 CHARACTER SET utf8 COLLATE utf8_general_ci;
    Query OK, 1 row affected (0.00 sec)

    mysql> quit
    Bye
    最后一击。
    1
    [root@etiantian data]# mysql eshop_ett100 </home/xxx/eshop_ett100.0624.sql
    到此,全备恢复成功。心里终于舒坦了。亲们。。。


    接下来开始准备增量数据的恢复。
    1、检查备份好的用于恢复的增量文件
    1
    2
    3
    4
    5
    6
    7
    [root@etiantian data]# cd /server/backup/
    [root@etiantian backup]# ll
    total 84832
    drwxr-xr-x 7 mysql mysql 4096 Jun 24 19:09 mysql
    -rw-r----- 1 root root 14935771 Jun 24 19:27 mysql-bin.000014
    -rw-r----- 1 root root 56588034 Jun 24 19:27 mysql-bin.000015
    -rw-r--r-- 1 root root 15331635 Jun 24 19:06 mysql.tar.gz
    2、根据全备的时间点设置增量恢复条件(这里要看全备的时间点)
    1
    2
    3
    4
    5
    6
    7
    8
    [root@etiantian backup]# mysqlbinlog mysql-bin.000014mysql-bin.000015 --start-datetime='2014-06-24 02:23:00' >bin.sql
    mysqlbinlog: unknown variable 'default-character-set=utf8'
    [root@etiantian backup]# which mysqlbinlog
    /install/mysql/bin/mysqlbinlog
    [root@etiantian backup]# /install/mysql/bin/mysqlbinlogmysql-bin.000014 mysql-bin.000015 --start-datetime='2014-06-24 02:23:00'>bin.sql
    /install/mysql/bin/mysqlbinlog: unknown variable'default-character-set=utf8'
    [root@etiantian backup]# /install/mysql/bin/mysqlbinlogmysql-bin.000014 mysql-bin.000015 --start-datetime='2014-06-24 02:23:00'>bin.sql
    /install/mysql/bin/mysqlbinlog: unknown variable'default-character-set=utf8'
    我晕,又报错,定了定神一看,你X,这个错误瞒不了我,老男孩给学生讲课常遇到。
    添加--no-defaults参数开始增量恢复。
    1
    2
    3
    [root@etiantian backup]# /install/mysql/bin/mysqlbinlog --no-defaultsmysql-bin.000014 mysql-bin.000015 --start-datetime='2014-06-24 02:23:00'>bin.sql
    [root@etiantian backup]# less bin.sql
    [root@etiantian backup]# mysql eshop_ett100 < bin.sql
    到此,增量恢复完毕,即数据库故障问题全部恢复完成。

    1.5数据库故障恢复后扫尾工作

    1、登录数据库查看
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    [root@etiantian backup]# mysql
    Welcome to the MySQL monitor. Commands end with ; or g.
    Your MySQL connection id is 4
    Server version: 5.5.33-log Source distribution

    Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rightsreserved.

    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 inputstatement.

    mysql> showdatabases; 看到了多紧张了吧。
    ERROR 1064 (42000): You have an error in your SQL syntax; check themanual that corresponds to your MySQL server version for the right syntax touse near 'showdatabases' at line 1
    mysql> show databases;
    +--------------------+
    | Database |
    +--------------------+
    | information_schema |
    | mysql |
    | performance_schema |
    | eshop_ett100 |
    | test |
    +--------------------+
    5 rows in set (0.00 sec)

    mysql> use eshop_ett100
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A

    Database changed
    mysql> show tables;
    +-----------------------------+
    | Tables_in_eshop_ett100 |
    +-----------------------------+
    | eshop_ett_activity |
    ......
    | eshop_ett_web |
    | eshop_ett_web_code |
    +-----------------------------+
    185 rows in set (0.00 sec)
    所有的表都存在。退出,对恢复完毕的数据库做全备,这块非常关键,不要让恢复过程付诸东流。
    1
    2
    3
    mysql> quit
    Bye
    [root@etiantian backup]# mysql -B –F eshop_ett100|gzip>new.sql.gz
    <==我晕忙中出错,恢复命令开始都搞错了,结果,处于等待状态,回车也不结束。
    正确恢复命令如下:
    1
    [root@etiantian backup]# mysqldump -B -F eshop_ett100|gzip>new.sql.gz
    2、通知客户,先改web端口,开启web服务内部测试看看
    目的:该端口目的是不让用户访问,内部先看下是否恢复正常。与客户回报原话:
    老男孩 19:41:53

    亲,恢复完毕了。

    老男孩 19:42:00

    先别起WEB

    老男孩 19:42:04

    你等进去

    老男孩 19:42:15

    等进去设置下连接账号吧

    XX 19:42:17

    老男孩 19:42:28

    root没密码

    XX 19:42:44

    老男孩 19:43:39

    需要我帮忙你就提供用户和密码

    XX 19:43:41

    客户端进不去mysql

    XX 19:43:51

    哦,没密码

    XX 19:43:57

    etiantian,test110oldboy

    XX 19:44:14

    权限是本机增删查改eshop_ett

    老男孩 19:45:28

    grant select,insert,update,delete on eshop_ett100.* to'etiantian'@'localhost' identified by 'test110oldboy'

    XX 19:45:39

    yes

    老男孩 19:46:30

    WEB目录在哪

    XX 19:46:36

    /www

    老男孩 19:46:37

    我们改个端口起来

    XX 19:46:44

    XX 19:46:47

    用多少端口

    XX 19:46:51

    我在web里面改

    老男孩 19:46:53

    9000

    3、测试web服务,居然403,有连续调整了web目录许可,以及首页文件,最后成功打开网站,经过客户仔细测试。
    提示:在老男孩恢复期间,还有客户公司的2个人,添乱,一直在改东西。所以导致了web也403。
    老男孩 19:47:05

    你改吧就是不让用户登录

    老男孩 19:47:10

    我们看下数据是否正常

    老男孩 19:47:21

    一切OK了 就可以改回端口用了

    XX 19:47:30

    XX 19:47:40

    你说的是httpd的端口是吗

    老男孩 19:47:49

    对的

    老男孩 19:47:59

    数据库密码改了?

    XX 19:47:59

    我以为mysql的端口

    XX 19:48:19

    好了

    XX 19:48:21

    改了

    XX 19:48:23

    全是那个密码

    老男孩 19:48:33

    哪个

    XX 19:48:35

    今天在网上暴露了,回头我得改密码

    XX 19:48:40

    test110oldboy

    XX 19:48:46

    root,etiantian都这个

    XX 19:48:56

    我现在起web?

    老男孩 19:50:04

    改过的HTTP的端口 就重启吧

    XX 19:50:29

    老男孩 19:51:05

    登录web检查点

    1、看看乱码不。

    2、看看用户注册记录量, 够不够,是不是连续的,订单对不对 包括白天有没有

    XX 19:51:42

    XX 19:53:10

    说的没权限访问根目录,我看看

    老男孩 19:54:24

    提示呢

    XX 19:54:36

    [Tue Jun 24 19:53:57 2014] [error] [client 110.75.102.99] Directoryindex forbidden by Options directive: /www/

    XX 19:54:38

    httpd

    XX 19:54:43

    没事这个,我能搞定

    老男孩 19:56:16

    还是80 了?

    XX 19:56:31

    XX 19:56:39

    有领导来了要看,擦

    老男孩 19:57:00

    不行目录给我 403 我来帮你

    老男孩 19:57:21

    站点目录 http配置路径告诉我

    XX 19:57:36

    httpd安装目录 /install/httpd

    XX 19:57:43

    其余全是默认

    XX 19:59:32

    你等下,我大约知道什么问题了

    老男孩 20:00:00

    首页文件是哪个

    老男孩 20:00:03

    赶紧告诉我

    XX 20:00:17

    改掉了,等下,我替换回来看看

    老男孩 20:00:36

    我改好好了

    老男孩 20:00:41

    你别乱改了。

    老男孩 20:00:45

    直接打开网站就行了

    老男孩 20:00:54

    测试好了以后你再弄

    老男孩 20:00:59

    我这个打开了

    老男孩 20:01:04

    你登录检查数据库吧

    XX 20:01:07

    好了

    老男孩 20:01:14

    之前你们都改错了

    XX 20:01:16

    我从别的主机上拿了个文件来了

    老男孩 20:01:23

    站点目录和许可的不一致还没首页文件

    XX 20:01:44

    有个人改了这个东西

    XX 20:01:46

    是的

    老男孩 20:01:56

    赶紧检查数据库吧

    XX 20:02:01

    我们经理一直在旁边看着,太撑面子了

    XX 20:02:02

    哈哈

    老男孩 20:02:15

    赶紧检查 没事 我就下了,下课了,我还没吃饭呢,有朋友等着呢。

    老男孩 20:02:20

    必须支持你们啊。

    老男孩 20:02:26

    不支持你们支持谁

    老男孩 20:02:45

    整个恢复过程应该是数据无损失

    XX 20:02:54

    哈哈,太感谢了

    老男孩 20:04:05

    刚才我写了个备份脚本 被删了。

    老男孩 20:04:23

    改天你让运维都搞好写个优化文档 回头我给你审核下。

    XX 20:04:33

    我只删了install/mysql

    老男孩 20:04:34

    备份容灾措施

    XX 20:04:42

    等下,我看看你说的有个文件许可

    老男孩 20:05:11

    看看都正常了不

    XX 20:05:27

    都正常了

    老男孩 20:05:34

    ll /server/backup/

    老男孩 20:05:40

    恢复之后的全备目录

    老男孩 20:05:45

    你们赶紧全备吧

    XX 20:05:58

    全备就还是我那个命令对吧

    老男孩 20:07:05

    !#/bin/sh

    bakpath=/server/scripts

    [ ! -d $bakpath ] &&mkdir $bakpath

    mysqldump -uroot -ptest110oldboy -B eshop_ett100|gzip>$bakpath/eshop_ett100_$(date +%F).sql.gz

    mysqldump -uroot -ptest110oldboy -B mysql --events |gzip>$bakpath/mysql_$(date +%F).sql.gz

    老男孩 20:07:20

    一定要加-B 不然恢复麻烦

    XX 20:08:16

    我把全备就放在那个/server/backup/下面就行了是吧

    XX 20:08:44

    好,我按你这个备

    老男孩 20:08:51

    mysqldump -uroot -ptest110oldboy -B -F --single-transaction eshop_ett100|gzip>$bakpath/eshop_ett100_$(date +%F).sql.gz

    老男孩 20:09:01

    最后这个吧。

    XX 20:09:04

    老男孩 20:09:19

    备好写个定时任务,然后头几天检查报警看。

    老男孩 20:09:44

    增量直接本地rsync 推就可以

    老男孩 20:09:52

    老男孩 20:10:02

    注意目录是变量要定义

    老男孩 20:10:07

    我要下了

    老男孩 20:10:11

    还有事么?

    XX 20:10:11

    本地没其他虚拟机,其他的都在我内网,像我刚拽index文件过去

    XX 20:10:14

    好的,你休息

    XX 20:10:24

    我写备份脚本+cron

    XX 20:10:26

    没事了

    XX 20:10:28

    太感谢了

    老男孩 20:10:59

    我下了。有事电话。

    XX 20:11:02

    好的

    XX 20:11:04

    你先下吧

    XX 20:11:09

    我慢慢研究会

    XX 20:11:10

    呵呵

    老男孩 20:11:12

    不注意规范

    XX 20:11:14

    水平如此噻

    老男孩 20:11:23

    恢复的过程有空我给你

    XX 20:11:23

    手还是太糙

    老男孩 20:11:26

    我都保留了

    XX 20:11:28

    好的

    老男孩 20:11:33

    你是开发大拿

    老男孩 20:11:43

    各有专攻

    XX 20:11:46

    哎,现在开发少了,主要靠这个

    XX 20:11:57

    你抓紧时间休息吧

    老男孩 20:12:02

    好 88

    XX 20:12:06

    上一天课也累了

    XX 20:12:08

    好,88哦

    老男孩 20:12:56

    另外以后不要killall杀库,我估计你是参数给大了,特别是innodb buffer。停库时间较长是正常的,多等,另外要做好主从复制,为恢复争取时间。

    后记:整个恢复过程持续了将近1个小时。比计划解决时间多出了半小时,看来很多时间还是始料不及的,特别是作为第三方公司,老男孩对客户的业务不了解也是故障恢复进度慢的一个原因,好多要和客户沟通交流的,另外,不在一个城市,靠QQ聊天解决问题,效率确实还是低了一些,幸好客户的配合还是不错。

    解决问题容易,写故障报告难,能主动写报告给客户更难,老男孩做到了。
    1、ssh事先配好记录LOG,便于事后总结。
    2、服务于客户,要尽可能超越客户的期待。
    老男孩和大家一起努力。。。谢谢大家观看。
    LINUX技术交流群 246054962 208160987(标明51CTO)

  • 相关阅读:
    Nginx中如何配置中文域名?
    VS2012找不到EF框架实体模型的解决方法
    来自一位家长的电话
    孩子大了真是不好管了
    springboot项目不加端口号也可以访问项目的方法
    分享几个上机案例题
    今晚在学校值班……
    3班的第二次模拟面试
    Sword 09
    Sword 06
  • 原文地址:https://www.cnblogs.com/liujiacai/p/8125061.html
Copyright © 2011-2022 走看看