VPS 服务器 LAMP - 建立数据库连接时出错
Posted
技术标签:
【中文标题】VPS 服务器 LAMP - 建立数据库连接时出错【英文标题】:VPS Server LAMP - Error establishing database connection 【发布时间】:2017-02-09 04:55:33 【问题描述】:我在 LAMP 服务器上有 wordpress,然后经常停机。 错误消息是“建立数据库连接时出错”。我不知道为什么! db 的用户名和密码正确,如果我重新启动所有服务器,则一切正常。
VPS 有 2GB 的内存。 我在 1024M 和 wordpress 配置中升级 php.ini 中的 php 限制
我不明白为什么服务器总是崩溃,请帮助我! 这里是系统日志:
/usr/lib/php5/maxlifetime ] && [ -x /usr/lib/php5/sessionclean ] && [ -d /var/lib/php5 ] && /usr/lib/php5/sessionclean /var/lib/php5 $(/usr/lib/php5/maxlifetime))
Sep 29 11:29:02 vps142555 -- MARK --
Sep 29 11:32:01 vps142555 /USR/SBIN/CRON[6000]: (root) CMD (cd / && run-parts --report /etc/cron.hourly)
Sep 29 11:39:01 vps142555 /USR/SBIN/CRON[6004]: (root) CMD ( [ -x /usr/lib/php5/maxlifetime ] && [ -x /usr/lib/php5/sessionclean ] && [ -d /var/lib/php5 ] && /usr/lib/php5/sessionclean /var/lib/php5 $(/usr/lib/php5/maxlifetime))
Sep 29 11:59:33 vps142555 -- MARK --
Sep 29 12:09:01 vps142555 /USR/SBIN/CRON[6024]: (root) CMD ( [ -x /usr/lib/php5/maxlifetime ] && [ -x /usr/lib/php5/sessionclean ] && [ -d /var/lib/php5 ] && /usr/lib/php5/sessionclean /var/lib/php5 $(/usr/lib/php5/maxlifetime))
Sep 29 12:32:01 vps142555 /USR/SBIN/CRON[6048]: (root) CMD (cd / && run-parts --report /etc/cron.hourly)
Sep 29 12:37:06 vps142555 kernel: [2410889.511488] Out of memory in UB 142555: OOM killed process 1996 (mysqld) score 0 vm:488652kB, rss:67976kB, swap:39012kB
Sep 29 12:37:08 vps142555 kernel: [2410891.904013] Out of memory in UB 142555: OOM killed process 4997 (apache2) score 0 vm:238648kB, rss:47692kB, swap:2812kB
Sep 29 12:37:11 vps142555 mysqld_safe: Number of processes running now: 0
Sep 29 12:37:11 vps142555 mysqld_safe: mysqld restarted
Sep 29 12:37:13 vps142555 kernel: [2410895.275214] Out of memory in UB 142555: OOM killed process 5978 (apache2) score 0 vm:240468kB, rss:49756kB, swap:2460kB
Sep 29 12:37:14 vps142555 kernel: [2410896.933917] Out of memory in UB 142555: OOM killed process 5976 (apache2) score 0 vm:238232kB, rss:47720kB, swap:2672kB
Sep 29 12:37:13 vps142555 mysqld: 160929 12:37:13 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
Sep 29 12:37:14 vps142555 mysqld: 160929 12:37:14 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
Sep 29 12:37:14 vps142555 mysqld: 160929 12:37:14 [Note] Plugin 'FEDERATED' is disabled.
Sep 29 12:37:14 vps142555 mysqld: 160929 12:37:14 InnoDB: The InnoDB memory heap is disabled
Sep 29 12:37:14 vps142555 mysqld: 160929 12:37:14 InnoDB: Mutexes and rw_locks use GCC atomic builtins
Sep 29 12:37:14 vps142555 mysqld: 160929 12:37:14 InnoDB: Compressed tables use zlib 1.2.7
Sep 29 12:37:14 vps142555 mysqld: 160929 12:37:14 InnoDB: Using Linux native AIO
Sep 29 12:37:15 vps142555 kernel: [2410897.519920] Out of memory in UB 142555: OOM killed process 5941 (apache2) score 0 vm:236836kB, rss:30424kB, swap:17708kB
Sep 29 12:37:14 vps142555 mysqld: 160929 12:37:14 InnoDB: Initializing buffer pool, size = 128.0M
Sep 29 12:37:15 vps142555 kernel: [2410898.744883] Out of memory in UB 142555: OOM killed process 5955 (apache2) score 0 vm:232268kB, rss:23744kB, swap:22364kB
Sep 29 12:37:16 vps142555 kernel: [2410899.545623] Out of memory in UB 142555: OOM killed process 6061 (apache2) score 0 vm:230300kB, rss:38016kB, swap:6004kB
Sep 29 12:37:16 vps142555 mysqld: 160929 12:37:16 InnoDB: Completed initialization of buffer pool
Sep 29 12:37:17 vps142555 kernel: [2410900.015311] Out of memory in UB 142555: OOM killed process 6062 (apache2) score 0 vm:227740kB, rss:34284kB, swap:7128kB
Sep 29 12:37:17 vps142555 kernel: [2410900.690501] Out of memory in UB 142555: OOM killed process 5980 (apache2) score 0 vm:222252kB, rss:30612kB, swap:6816kB
Sep 29 12:37:17 vps142555 mysqld: 160929 12:37:17 InnoDB: highest supported file format is Barracuda.
Sep 29 12:37:17 vps142555 mysqld: InnoDB: Log scan progressed past the checkpoint lsn 2365452992
Sep 29 12:37:17 vps142555 mysqld: 160929 12:37:17 InnoDB: Database was not shut down normally!
Sep 29 12:37:17 vps142555 mysqld: InnoDB: Starting crash recovery.
Sep 29 12:37:17 vps142555 mysqld: InnoDB: Reading tablespace information from the .ibd files...
Sep 29 12:37:18 vps142555 mysqld: InnoDB: Restoring possible half-written data pages from the doublewrite
Sep 29 12:37:18 vps142555 mysqld: InnoDB: buffer...
Sep 29 12:37:18 vps142555 kernel: [2410901.336589] Out of memory in UB 142555: OOM killed process 5977 (apache2) score 0 vm:222000kB, rss:14816kB, swap:21748kB
Sep 29 12:37:18 vps142555 kernel: [2410901.723385] Out of memory in UB 142555: OOM killed process 6057 (apache2) score 0 vm:222544kB, rss:30148kB, swap:6068kB
Sep 29 12:37:18 vps142555 mysqld: InnoDB: Doing recovery: scanned up to log sequence number 2365502829
Sep 29 12:37:19 vps142555 kernel: [2410902.245687] Out of memory in UB 142555: OOM killed process 6071 (apache2) score 0 vm:223576kB, rss:34220kB, swap:3200kB
Sep 29 12:37:19 vps142555 kernel: [2410903.117311] Out of memory in UB 142555: OOM killed process 6335 (mysqld) score 0 vm:344240kB, rss:38588kB, swap:0kB
Sep 29 12:37:20 vps142555 kernel: [2410903.724624] Out of memory in UB 142555: OOM killed process 6077 (apache2) score 0 vm:223832kB, rss:29632kB, swap:7960kB
Sep 29 12:37:20 vps142555 kernel: [2410904.218604] Out of memory in UB 142555: OOM killed process 6064 (apache2) score 0 vm:222544kB, rss:23472kB, swap:12720kB
Sep 29 12:37:21 vps142555 kernel: [2410904.505518] OOM killer in rage, 1 tasks killed
Sep 29 12:37:21 vps142555 kernel: [2410904.505694] Out of memory in UB 142555: OOM killed process 6073 (apache2) score 0 vm:222544kB, rss:23692kB, swap:12588kB
Sep 29 12:37:21 vps142555 mysqld_safe: mysqld from pid file /var/run/mysqld/mysqld.pid ended
Sep 29 12:37:22 vps142555 kernel: [2410905.456095] OOM killer in rage, 2 tasks killed
Sep 29 12:37:22 vps142555 kernel: [2410905.456283] Out of memory in UB 142555: OOM killed process 6074 (apache2) score 0 vm:222544kB, rss:24760kB, swap:11536kB
Sep 29 12:37:23 vps142555 kernel: [2410906.469929] Out of memory in UB 142555: OOM killed process 6078 (apache2) score 0 vm:222544kB, rss:29304kB, swap:7268kB
Sep 29 12:37:23 vps142555 kernel: [2410906.972042] Out of memory in UB 142555: OOM killed process 6081 (apache2) score 0 vm:221256kB, rss:27988kB, swap:7444kB
Sep 29 12:37:24 vps142555 kernel: [2410907.732515] Out of memory in UB 142555: OOM killed process 6099 (apache2) score 0 vm:223576kB, rss:27932kB, swap:9608kB
Sep 29 12:37:26 vps142555 kernel: [2410909.311145] Out of memory in UB 142555: OOM killed process 6080 (apache2) score 0 vm:222588kB, rss:27872kB, swap:8680kB
Sep 29 12:37:27 vps142555 kernel: [2410910.762627] Out of memory in UB 142555: OOM killed process 6090 (apache2) score 0 vm:223832kB, rss:25812kB, swap:11936kB
Sep 29 12:37:29 vps142555 kernel: [2410912.842178] Out of memory in UB 142555: OOM killed process 6089 (apache2) score 0 vm:224084kB, rss:32840kB, swap:5748kB
Sep 29 12:37:30 vps142555 kernel: [2410913.865956] Out of memory in UB 142555: OOM killed process 6087 (apache2) score 0 vm:223832kB, rss:29124kB, swap:8940kB
【问题讨论】:
【参考方案1】:Sep 29 12:37:14 vps142555 mysqld: 160929 12:37:14 InnoDB: Initializing buffer pool, size = 128.0M
Sep 29 12:37:15 vps142555 kernel: [2410898.744883] Out of memory in UB 142555: OOM killed process 5955 (apache2) score 0 vm:232268kB, rss:23744kB, swap:22364kB
Sep 29 12:37:16 vps142555 kernel: [2410899.545623] Out of memory in UB 142555: OOM killed process 6061 (apache2) score 0 vm:230300kB, rss:38016kB, swap:6004kB
查看日志
内核已经杀死了 mysqld,因为它没有内存可以分配给 innodb 缓冲池。检查谁在吃内存。
因为内核已经停止了 mysql,所以才会出现连接问题。
【讨论】:
我该怎么做? 使用顶部或binarytides.com/linux-command-check-memory-usage s17.postimg.org/fkxgsbdxb/sas.jpg Look Top,一切正常。 Ram 没有进程 能不能拿到cron列表 "没有根的 crontab"【参考方案2】:php 版本中存在一个单一的错误,所有内容都内存不足。 我升级了一个php版本并解决了这个问题。 TKS
【讨论】:
以上是关于VPS 服务器 LAMP - 建立数据库连接时出错的主要内容,如果未能解决你的问题,请参考以下文章
如何修复在“localhost/wordpress”上建立数据库连接时出错
在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名
服务器环境搭建WordPress建立数据库连接时出错---问题---解决