问题描述:

早晨接到 Zabbix 报警,提示 Host: 10.10.1.2, MySQL 主从同步失败。

登录服务器查看具体情况。

shell > mysql

mysql> show slave status\G

Slave I/O thread : YES
Slave SQL thread : NO Slave SQL: Error 'Unknown storage engine 'InnoDB'' on query. Default database: 'baeng_tv'. Query: 'UPDATE std_tv_card SET uid='', devicetoken='60000AM1500D16972129_569C' WHERE id=''', Error_code: Slave: Unknown storage engine 'InnoDB' Error_code:

# 这是 show slave status\G 看到的一些状态信息,说不支持 InnoDB 引擎。这不开玩笑呢么,又不是第一次跑。

shell > vim /data/mysql_data/hostname.err

Version: '5.5.28-log'  socket: '/tmp/mysql.sock'  port:   Source distribution
:: mysqld_safe Number of processes running now:
:: mysqld_safe mysqld restarted :: InnoDB: The InnoDB memory heap is disabled
:: InnoDB: Mutexes and rw_locks use GCC atomic builtins
:: InnoDB: Compressed tables use zlib 1.2.
:: InnoDB: Initializing buffer pool, size = .0G
InnoDB: mmap( bytes) failed; errno
:: InnoDB: Completed initialization of buffer pool :: InnoDB: Fatal error: cannot allocate memory for the buffer pool
:: [ERROR] Plugin 'InnoDB' init function returned error.
:: [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed. :: [Note] Server hostname (bind-address): '0.0.0.0'; port:
:: [Note] - '0.0.0.0' resolves to '0.0.0.0';
:: [Note] Server socket created on IP: '0.0.0.0'. :: [Note] Slave SQL thread initialized, starting replication in log 'mysql-bin.003702' at position , relay log './hostname-relay-bin.010674' position:
:: [Note] Slave I/O thread: connected to master 'repl@10.10.1.8:3306',replication started in log 'mysql-bin.003702' at position
:: [Note] Event Scheduler: Loaded events
:: [Note] /usr/local/mysql-5.5/bin/mysqld: ready for connections.
Version: '5.5.28-log' socket: '/tmp/mysql.sock' port: Source distribution :: [ERROR] Slave SQL: Error 'Unknown storage engine 'InnoDB'' on query. Default database: 'baeng_tv'. Query: 'UPDATE std_tv_card SET uid='', devicetoken='60000AM1500D16972129_569C' WHERE id=''', Error_code:
:: [Warning] Slave: Unknown storage engine 'InnoDB' Error_code:
:: [ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE START". We stopped at log 'mysql-bin.003702' position

# mysql.err

InnoDB: Initializing buffer pool, size = .0G

# 初始化缓存池,大小为 1G

InnoDB: Fatal error: cannot allocate memory for the buffer pool

# 无法为 InnoDB 缓存池分配内存

Plugin 'InnoDB' init function returned error.

# InnoDB 插件 init 函数返回错误

Plugin 'InnoDB' registration as a STORAGE ENGINE failed.

# InnoDB 插件存储引擎注册失败

# 接着就是初始化 Slave SQL thread 启动同步,I/O 线程连接 master。
# 最后提示,Slave SQL 错误,未知的存储引擎,查询语句 'UPDATE 失败'。

解决方法:

shell > free -m

# 当时空闲内存只有 936M,而初始化的缓存池为 1G。

# 看到这里,应该知道故障是由系统内存不足造成的,该机器内存为 24G。上面就跑了一个 MySQL Slave 跟一些任务计划。

# 说到任务计划,这是一些查询数据,然后写入 ElasticSearch 生成索引的一些 PHP 脚本。

shell > ps aux | grep php | wc -l

# 好家伙!!!

# 任务计划是每 5、10、15 分,分别执行不同的 PHP 脚本。执行完、下次循环。
# 也就是如果没有执行完,等到下一个时间点就会重新启动一个 PHP 脚本... 所以占用了大量系统内存。

shell > ps aux | grep -v grep | grep php | awk '{print $2}' | xargs -i kill {}

# 先将这些阻塞的进程全部杀死

shell > free -m
total used free shared buffers cached
Mem:
-/+ buffers/cache:
Swap:

# 内存释放了

shell > /etc/init.d/mysql.server restart

shell > mysql

mysql> show slave status\G

             Slave_IO_Running: Yes
Slave_SQL_Running: Yes Seconds_Behind_Master:

# 主从同步正常,延迟就让它自己补上吧,过一会就好了。

# 故障消除
# 接下来让故障不再出现

shell > vim script/yiic_index.sh
#!/bin/bash logfile='/root/script/logs/yiic.log'
filepath='/data/git-webroot/yiic index' line=`ps aux | grep -v grep | grep 'yiic index' | wc -l` if [ $line -eq ]:then
/usr/local/php/bin/php $filepath >/dev/null &
else
echo `date "+%F %T"` $filepath >> $logfile
exit
fi # End shell > crontab -e */ * * * * /root/script/logs/yiic_index.sh

# 这样就控制住了 PHP 进程的数量。

# 但是,这样写脚本会出现僵尸进程。
# 先执行 sh 脚本,然后将 php 进程放入后台,退出 sh 脚本,这样 sh 就是 PHP 的父进程了,所以产生僵尸。
# 但这是可控的,如果 PHP 执行时间过长,下次 crond 调用 sh 时,是不执行 PHP 的。
# 生成的僵尸进程也不必担心,当 PHP 执行完毕后,僵尸自动死亡。

shell > crontab -e

*/ * * * * timeout  /usr/local/php/bin/php /data/git-webroot/yiic index >/dev/null

# 也可以这样来控制 PHP 进程执行时间,随你选咯

MySQL Innodb 神秘消失的更多相关文章

  1. MySQL InnoDB 群集–在Windows上设置InnoDB群集

    InnoDB集群最需要的功能之一是Windows支持,我们现在已将其作为InnoDB Cluster 5.7.17预览版 2的一部分提供.此博客文章将向您展示如何在MS Windows 10上运行In ...

  2. Mysql InnoDB 共享表空间和独立表空间

    前言:学习mysql的时候总是习惯性的和oracle数据库进行比较.在学习mysql InnoDB的存储结构的时候也免不了跟oracle进行比较.Oracle的数据存储有表空间.段.区.块.数据文件: ...

  3. MYSQL INNODB PAGE一督

    MYSQL INNODB PAGE一督

  4. MySQL InnoDB表--BTree基本数据结构

    MySQL InnoDB表是索引组织表这一点应该是每一个学习MySQL的人都会首先学到的知识,这代表这表中的数据是按照主键顺序存储,也就是说BTree的叶子节点存储了所有该行的数据. 我最开始是搞Or ...

  5. MySQL Innodb数据库性能实践——热点数据性能

    摘要: 对于大部分的应用来说,都存在热点数据的访问,即:某些数据在一定时间内的访问频率要远远高于其它数据. 常见的热点数据有“最新的新闻”.“最热门的新闻”.“下载量最大”的电影等. 为了了解MySQ ...

  6. Mysql InnoDB行锁实现方式(转)

    Mysql InnoDB行锁实现方式 InnoDB行锁是通过给索引上的索引项加锁来实现的,这一点MySQL与Oracle不同,后者是通过在数据块中对相应数据行加锁来实现的.InnoDB这种行锁实现特点 ...

  7. Mysql InnoDB行锁实现方式

    Mysql InnoDB行锁实现方式 InnoDB行锁是通过给索引上的索引项加锁来实现的,这一点MySQL与Oracle不同,后者是通过在数据块中对相应数据行加锁来实现的.InnoDB这种行锁实现特点 ...

  8. mysql innoDB 挂了的临时解决方案

    Mysql InnoDB: Error: checksum mismatch by Mattias Hemmingsson on December 23, 2013 in Linux • 6 Comm ...

  9. WDCP安装常用组件(memcache、mysqli、PDO_MYSQL、mysql innodb、libmcrypt、php zip)的方法

    为有更好的性能,也为更简洁的系统,一些不是常用或不是基本的功能,都将做为可选的安装组件需要用到的就安装 注意:如果安装时遇到 ./configure: Permission denied提示,很有可能 ...

随机推荐

  1. sync-settings(vscode)

    vscode插件以及设置 sync-download e45c6db33cd91d661e0cc545efb6817c

  2. BZOJ1098 POI2007 办公楼biu 【链表+bfs】

    Description FGD开办了一家电话公司.他雇用了N个职员,给了每个职员一部手机.每个职员的手机里都存储有一些同事的电话号码.由于FGD的公司规模不断扩大,旧的办公楼已经显得十分狭窄,FGD决 ...

  3. BZOJ4540 Hnoi2016 序列 【莫队+RMQ+单调栈预处理】*

    BZOJ4540 Hnoi2016 序列 Description 给定长度为n的序列:a1,a2,-,an,记为a[1:n].类似地,a[l:r](1≤l≤r≤N)是指序列:al,al+1,-,ar- ...

  4. 理解 C# 项目 csproj 文件格式的本质和编译流程

    写了这么多个 C# 项目,是否对项目文件 csproj 有一些了解呢?Visual Studio 是怎么让 csproj 中的内容正确显示出来的呢?更深入的,我能够自己扩展 csproj 的功能吗? ...

  5. WPF中Grid实现网格,表格样式通用类(转)

    /// <summary> /// 给Grid添加边框线 /// </summary> /// <param name="grid"></ ...

  6. openresty && hashids&& redis 生成短链接

    1. 原理     a. 从redis 获取需要表示的短链接的id( redis incr)     b. hashids 编码 id     c. openresty  conteent_by_lu ...

  7. nginx 缓存处理

    核心指令   proxy_cache_path /data/nginx/cache/one levels=1:2 keys_zone=one:10m max_size=10g; proxy_cache ...

  8. 研究ecmall一些流程、结构笔记 (转)

    index.phpECMall::startup() //ecmall.php object //所有类的基础类 ecmall.phpBaseApp //控制器基础类 app.base.phpECBa ...

  9. CentOS yum源设定使用方法的整理(转)

    CentOS yum更新了很多版本更新,我本人认为CentOS yum很好使的文件系统,在此向大家推荐CentOS应该是做为服务器的linux的佼佼者.CentOS采用的二进制包是rpm,不过包的依赖 ...

  10. oracle 的一些基础查询

    select status,T.* from user_indexes Twhere table_name='T_ADMIN_DEALER' --查询表是否有了索引  select username, ...