【问题标题】:MariaDB Out of memoryMariaDB 内存不足
【发布时间】:2018-11-20 19:29:03
【问题描述】:

我的数据库因内存不足错误而崩溃,每天约 1-2 次。上次崩溃发生在日志中的 17:30 和指标中的 19:30(不同时区)。

mariadb.log 中的错误:

181120 16:09:00 [Warning] IP address '185.156.177.144' could not be resolved: Name or service not known
181120 16:35:40 [Warning] IP address '58.221.58.248' could not be resolved: Name or service not known
181120 17:30:38 mysqld_safe Number of processes running now: 0
181120 17:30:38 mysqld_safe mysqld restarted
181120 17:30:41 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
181120 17:30:41 [Note] /usr/libexec/mysqld (mysqld 5.5.52-MariaDB) starting as process 16636 ...
181120 17:30:41 [Warning] Changed limits: max_open_files: 1024  max_connections: 70  table_cache: 472
181120 17:30:41 InnoDB: The InnoDB memory heap is disabled
181120 17:30:41 InnoDB: Mutexes and rw_locks use GCC atomic builtins
181120 17:30:41 InnoDB: Compressed tables use zlib 1.2.7
181120 17:30:41 InnoDB: Using Linux native AIO
181120 17:30:41 InnoDB: Initializing buffer pool, size = 150.0M
181120 17:30:42 InnoDB: Completed initialization of buffer pool
181120 17:30:42 InnoDB: highest supported file format is Barracuda.
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
181120 17:30:42  InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
181120 17:30:46  InnoDB: Waiting for the background threads to start
181120 17:30:47 Percona XtraDB (http://www.percona.com) 5.5.49-MariaDB-38.0 started; log sequence number 18741266161
181120 17:30:47 [Note] Plugin 'FEEDBACK' is disabled.
181120 17:30:48 [Note] Server socket created on IP: '0.0.0.0'.
181120 17:30:49 [Note] Event Scheduler: Loaded 0 events
181120 17:30:49 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.5.52-MariaDB'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MariaDB Server
181120 17:30:53 [ERROR] mysqld: Table './admin_wikis/wp_posts' is marked as crashed and should be repaired
181120 17:30:53 [Warning] Checking table:   './admin_wikis/wp_posts'
181120 17:31:58 mysqld_safe Number of processes running now: 0
181120 17:31:58 mysqld_safe mysqld restarted
181120 17:32:01 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
181120 17:32:01 [Note] /usr/libexec/mysqld (mysqld 5.5.52-MariaDB) starting as process 16899 ...
181120 17:32:01 [Warning] Changed limits: max_open_files: 1024  max_connections: 70  table_cache: 472
181120 17:32:01 InnoDB: The InnoDB memory heap is disabled
181120 17:32:01 InnoDB: Mutexes and rw_locks use GCC atomic builtins
181120 17:32:01 InnoDB: Compressed tables use zlib 1.2.7
181120 17:32:01 InnoDB: Using Linux native AIO
181120 17:32:01 InnoDB: Initializing buffer pool, size = 150.0M
InnoDB: mmap(161447936 bytes) failed; errno 12
181120 17:32:01 InnoDB: Completed initialization of buffer pool
181120 17:32:01 InnoDB: Fatal error: cannot allocate memory for the buffer pool
181120 17:32:01 [ERROR] Plugin 'InnoDB' init function returned error.
181120 17:32:01 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
181120 17:32:01 [ERROR] mysqld: Out of memory (Needed 128917504 bytes)
181120 17:32:01 [ERROR] mysqld: Out of memory (Needed 96681984 bytes)
181120 17:32:01 [ERROR] mysqld: Out of memory (Needed 72499200 bytes)
181120 17:32:01 [Note] Plugin 'FEEDBACK' is disabled.
181120 17:32:02 [ERROR] Unknown/unsupported storage engine: InnoDB
181120 17:32:02 [ERROR] Aborting

181120 17:32:02 [Note] /usr/libexec/mysqld: Shutdown complete

这次apache日志没有什么有趣的了。事件请求计数

$ sudo grep -r "GET \/" /etc/httpd/logs/domains/ |  cut -d' ' -f4 | sed 's/\[//;s/\]//;s/\"//' | cut -d':' -f1-2 | sort | uniq -c

459 19/Nov/2018:03
426 19/Nov/2018:04
239 19/Nov/2018:05
350 19/Nov/2018:06
381 19/Nov/2018:07
415 19/Nov/2018:08
778 19/Nov/2018:09
500 19/Nov/2018:10
450 19/Nov/2018:11
633 19/Nov/2018:12
458 19/Nov/2018:13
527 19/Nov/2018:14
713 19/Nov/2018:15
654 19/Nov/2018:16
573 19/Nov/2018:17
413 19/Nov/2018:18
471 19/Nov/2018:19
499 19/Nov/2018:20
661 19/Nov/2018:21
452 19/Nov/2018:22
773 19/Nov/2018:23
934 20/Nov/2018:00
295 20/Nov/2018:01
369 20/Nov/2018:02
441 20/Nov/2018:03
384 20/Nov/2018:04
927 20/Nov/2018:05
524 20/Nov/2018:06
972 20/Nov/2018:07
612 20/Nov/2018:08
609 20/Nov/2018:09
677 20/Nov/2018:10
753 20/Nov/2018:11
615 20/Nov/2018:12
717 20/Nov/2018:13
474 20/Nov/2018:14
973 20/Nov/2018:15
510 20/Nov/2018:16
534 20/Nov/2018:17
415 20/Nov/2018:18
 90 20/Nov/2018:19

我得到了一些指标:

崩溃前的进程:

崩溃时刻的进程:

内存和 CPU 使用率:

总内存 3.6G。有人有什么想法吗?

【问题讨论】:

    标签: mysql apache out-of-memory mariadb administration


    【解决方案1】:
    • httpd是最大的内存用户;减少它的设置,尤其是它愿意产生的“孩子”的数量。 (对于大多数小型安装来说,10 岁以下就足够了。)

    • max_connections: 70 table_cache: 472 -- 将每一个切成两半;这将有助于内存分配。

    • 下次 CPU 达到 100% 时,在 MySQL 中执行 SHOW FULL PROCESSLIST;。这可能会让你知道你有什么失控的查询。然后我们可以专注于它们。如果失败,打开慢日志;它会捕获其中一些。

    • 考虑迁移到 8GB 服务器。 (这是云服务器吗?)

    【讨论】:

    • 谢谢。今天会试试。但我认为“崩溃时刻的进程”的 CPU 和内存负载看起来很奇怪
    • “10岁以下就够了”哈哈哈哈!
    • @symcbean - 如果您需要超过 N 个(例如,10 个),那么线程将相互绊倒并堆积起来。当然,它们都将“运行”,但实际上它们大多会停滞不前,等待 CPU/swap/IO/MySQL/等。吞吐量将达到一些限制,延迟将达到顶峰。而且,你猜怎么着,你会得到这样的图表。
    • 您是否曾经在人多的商店里难以移动您的购物车?有些商店对此很明智(或者可能受到消防元帅的威胁),让你在门口等着,让人们逐渐进来。
    • stdlib.net/~colmmacc/Apachecon-EU2005/… (我个人运行过规格低得多的 LAMP 盒,可处理 500 多个并发连接)
    猜你喜欢
    • 1970-01-01
    • 2019-08-04
    • 2014-10-15
    • 2011-05-21
    • 1970-01-01
    • 2021-12-20
    • 2021-10-29
    • 1970-01-01
    • 2020-03-12
    相关资源
    最近更新 更多