我有一个基于 PHP 的 Web 应用程序,它使用 MySQL 作为 DBMS。每隔几分钟(特别是当 Web 应用程序的用户数量超过 15 人时),MySQL 就会关闭。以下是一次关闭时的日志条目。我该如何防止这种情况发生?
2018-02-13T07:03:39.487586Z 0 [ERROR] Can't create thread to handle new connection(errno= 11)
2018-02-13T07:03:41.741213Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2018-02-13T07:03:41.749821Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
2018-02-13T07:03:42.145655Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-02-13T07:03:42.148517Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.21-0ubuntu0.16.04.1) starting as process 2877 ...
2018-02-13T07:03:42.207520Z 0 [Note] InnoDB: PUNCH HOLE support available
2018-02-13T07:03:42.207540Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-02-13T07:03:42.207545Z 0 [Note] InnoDB: Uses event mutexes
2018-02-13T07:03:42.207548Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2018-02-13T07:03:42.207552Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.8
2018-02-13T07:03:42.207556Z 0 [Note] InnoDB: Using Linux native AIO
2018-02-13T07:03:42.210157Z 0 [Note] InnoDB: Number of pools: 1
2018-02-13T07:03:42.213440Z 0 [Note] InnoDB: Using CPU crc32 instructions
2018-02-13T07:03:42.215241Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2018-02-13T07:03:42.216012Z 0 [ERROR] InnoDB: mmap(137428992 bytes) failed; errno 12
2018-02-13T07:03:42.216026Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
2018-02-13T07:03:42.216031Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2018-02-13T07:03:42.216036Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2018-02-13T07:03:42.216040Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2018-02-13T07:03:42.216045Z 0 [ERROR] Failed to initialize builtin plugins.
2018-02-13T07:03:42.216048Z 0 [ERROR] Aborting
2018-02-13T07:03:42.216058Z 0 [Note] Binlog end
2018-02-13T07:03:42.217964Z 0 [Note] /usr/sbin/mysqld: Shutdown complete
答案1
Linux 对可打开的文件数量有限制。摘要和补救措施可在此处找到:增加最大打开文件数