› MySQL 5.5 Community Server
› MySQL 5.6 Community Server
› Percona Configuration Wizard
› XtraBackup 搭建主从复制
Great Sites on MySQL
› Percona
› MySQL Performance Blog
› Severalnines
推荐管理工具
› Sequel Pro
› phpMyAdmin
推荐书目
› MySQL Cookbook
MySQL 相关项目
› MariaDB
› Drizzle
参考文档
› http://mysql-python.sourceforge.net/MySQLdb.html
Famio
V2EX  ›  MySQL

centOS7 上 mysql 服务经常无故 dead,有 log,请各路大神会诊

  •  
  •   Famio · Oct 4, 2016 · 4901 views
    This topic created in 3678 days ago, the information mentioned may be changed or developed.
    查看 log 初步判断为服务自动终止,原因是内存溢出,我以前的主机是 1GB 的 ram ,以为是内存太小,升级到了 2GB ,结果还是这个问题,其实我觉得和内存大小没有太大关系,因为我用过万网的虚拟主机, 512MB 的都能跑的好好的,自从迁移到 ECS 上后就问题不断。请各位大神帮忙看下这个 log ,为何内存总是溢出,感谢!

    maridb log 如下:
    161003 3:45:07 [Warning] IP address '121.28.142.136' could not be resolved: Name or service not known
    161003 3:45:07 [Warning] IP address '121.28.142.138' could not be resolved: Name or service not known
    161003 3:45:08 [Warning] IP address '121.28.142.133' could not be resolved: Name or service not known
    161003 7:05:41 [Warning] IP address '69.165.72.94' could not be resolved: Name or service not known
    161003 11:37:43 [Warning] IP address '123.249.3.155' could not be resolved: Name or service not known
    161003 12:28:12 [Warning] IP address '121.199.70.200' could not be resolved: Name or service not known
    161004 0:10:16 [Warning] IP address '139.224.53.6' could not be resolved: Name or service not known
    161004 0:19:28 [Warning] IP address '124.173.113.45' could not be resolved: Name or service not known
    161004 00:38:31 mysqld_safe Number of processes running now: 0
    161004 00:38:31 mysqld_safe mysqld restarted
    161004 0:38:31 [Note] /usr/libexec/mysqld (mysqld 5.5.50-MariaDB) starting as process 27071 ...
    161004 0:38:31 [Warning] Changed limits: max_open_files: 1024 max_connections: 214 table_cache: 400
    161004 0:38:31 InnoDB: The InnoDB memory heap is disabled
    161004 0:38:31 InnoDB: Mutexes and rw_locks use GCC atomic builtins
    161004 0:38:31 InnoDB: Compressed tables use zlib 1.2.7
    161004 0:38:31 InnoDB: Using Linux native AIO
    161004 0:38:31 InnoDB: Initializing buffer pool, size = 128.0M
    InnoDB: mmap(137756672 bytes) failed; errno 12
    161004 0:38:31 InnoDB: Completed initialization of buffer pool
    161004 0:38:31 InnoDB: Fatal error: cannot allocate memory for the buffer pool
    161004 0:38:31 [ERROR] Plugin 'InnoDB' init function returned error.
    161004 0:38:31 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
    161004 0:38:31 [ERROR] mysqld: Out of memory (Needed 128917504 bytes)
    161004 0:38:31 [ERROR] mysqld: Out of memory (Needed 96681984 bytes)
    161004 0:38:31 [ERROR] mysqld: Out of memory (Needed 72499200 bytes)
    161004 0:38:33 [Note] Plugin 'FEEDBACK' is disabled.
    161004 0:38:33 [ERROR] Unknown/unsupported storage engine: InnoDB
    161004 0:38:33 [ERROR] Aborting

    161004 0:38:33 [Note] /usr/libexec/mysqld: Shutdown complete

    161004 00:38:33 mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended
    10 replies  •  2016-10-05 13:05:53 +08:00
    Famio
        1
    Famio  
    OP
       Oct 4, 2016
    忘记说明时间,从 10 月 4 日凌晨 0 点 38 分开始 down 的
    hjc4869
        2
    hjc4869  
       Oct 4, 2016
    内存不足,建议不要用 innodb 引擎,或者加配置
    charm
        3
    charm  
       Oct 4, 2016   ❤️ 1
    内存不足,可以尽量调低缓存池大小 innodb_buffer_pool
    参考:
    https://discuss.erpnext.com/t/mysql-mariadb-crashing-on-do-centos7-solved/3864/2
    msg7086
        4
    msg7086  
       Oct 4, 2016   ❤️ 1
    加上交换分区试试。我不知道你所说的万网的「虚拟主机」(应该是 VPS 吧?)是什么情况,不过 InnoDB 对内存虚拟空间的要求很大,如果你虚拟空间太小的话 MySQL 是没有办法正常启动的。
    eoo
        5
    eoo  
       Oct 4, 2016 via Android
    我都是禁用 innodb
    Felldeadbird
        6
    Felldeadbird  
       Oct 4, 2016 via iPhone   ❤️ 1
    把你 my.cnf 我贴出来,我估计你是没有做内存限制,导致 sql 查询时占用了大量的内存,同时其他操作需要内存时触发了 linux 的内存机制把他 kill 了
    Famio
        7
    Famio  
    OP
       Oct 4, 2016
    感谢各位回复,问题已经解决了:
    原来没用 swap 分区,新增了一个 swap 分区
    将 buffer 调整为 64MB
    目前看起来一切正常,确实是 sql 吃内存吃太多了
    msg7086
        8
    msg7086  
       Oct 4, 2016
    @Famio 进程有一个「使用内存」和一个「申请内存」。
    你平时看到的进程内存占用都是「使用内存」,但是触发 Kill 的却是「申请内存」。
    所以你会发现明明内存还有空余,却报内存不足。
    Linux 和 Windows 都是这样子的。 Windows 你可以看有个提交内存, Commit Charge ,这个就是「申请内存」。
    如果 Windows 下不开分页文件,那么申请内存就等于物理内存,这种情况下内存还没用满就会提前导致系统去杀进程了。
    Linux 有个内核参数可以控制 Over Commit ,有兴趣的话可以当做扩展阅读。
    https://www.kernel.org/doc/Documentation/vm/overcommit-accounting
    julyclyde
        9
    julyclyde  
       Oct 4, 2016
    @msg7086 申请如果还能活着失败,说明是被内核的 over commit 给限制的;如果是使用超限,进程根本不会有感知,直接就上天了,内核日志记录 oom-killer
    realpg
        10
    realpg  
       Oct 5, 2016
    @Famio
    在你的 MYSQL 配置文件里加一句
    performance_schema = OFF
    内存问题就解决了, 512M 内存也可以愉快的使用了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1340 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 19:21 · PVG 03:21 · LAX 12:21 · JFK 15:21
    ♥ Do have faith in what you're doing.