你好,我的服务器上的 mongo db 出了问题。Mongo db 在几天内崩溃了。我添加了一个 shell 脚本,用于在崩溃时重新启动服务器上的 mongod 服务,但我想知道我应该怎么做才能确保它根本不会崩溃。
此外,mongodb.log
文件中"/var/log/mongodb"
没有显示崩溃的原因。它仅显示连接正在关闭和结束。
我在这里从日志文件中添加了几行:
2017-06-06T06:49:52.305+0000 I NETWORK [initandlisten] connection accepted from 127.0.0.1:35871 #279 (11 connections now open)
2017-06-06T06:50:39.846+0000 I NETWORK [conn278] end connection 127.0.0.1:35869 (10 connections now open)
2017-06-06T06:51:03.870+0000 I NETWORK [conn264] end connection 127.0.0.1:35819 (9 connections now open)
2017-06-06T06:51:05.048+0000 I NETWORK [initandlisten] connection accepted from 127.0.0.1:35875 #280 (10 connections now open)
2017-06-06T06:51:32.902+0000 I NETWORK [conn276] end connection 127.0.0.1:35865 (9 connections now open)
2017-06-06T06:52:13.954+0000 I NETWORK [conn266] end connection 127.0.0.1:35826 (8 connections now open)
2017-06-06T06:52:20.958+0000 I NETWORK [conn221] end connection 127.0.0.1:35457 (7 connections now open)
2017-06-06T06:52:22.432+0000 I NETWORK [initandlisten] connection accepted from 127.0.0.1:35882 #281 (8 connections now open)
2017-06-06T06:52:39.052+0000 I NETWORK [initandlisten] connection accepted from 127.0.0.1:35883 #282 (9 connections now open)
2017-06-06T06:52:44.981+0000 I NETWORK [conn268] end connection 127.0.0.1:35829 (8 connections now open)
2017-06-06T06:52:46.619+0000 I NETWORK [initandlisten] connection accepted from 127.0.0.1:35885 #283 (9 connections now open)
2017-06-06T06:53:03.509+0000 I NETWORK [initandlisten] connection accepted from 127.0.0.1:35886 #284 (10 connections now open)
2017-06-06T06:53:04.399+0000 I NETWORK [initandlisten] connection accepted from 127.0.0.1:35887 #285 (11 connections now open)
2017-06-06T06:53:06.160+0000 I NETWORK [initandlisten] connection accepted from 127.0.0.1:35888 #286 (12 connections now open)
2017-06-06T06:54:25.183+0000 I NETWORK [initandlisten] connection accepted from 127.0.0.1:35889 #287 (13 connections now open)
2017-06-06T06:54:55.284+0000 I NETWORK [initandlisten] connection accepted from 127.0.0.1:35890 #288 (14 connections now open)
2017-06-06T06:55:27.122+0000 I NETWORK [conn279] end connection 127.0.0.1:35871 (13 connections now open)
2017-06-06T06:55:28.117+0000 I NETWORK [conn269] end connection 127.0.0.1:35832 (12 connections now open)
2017-06-06T06:57:09.066+0000 I NETWORK [initandlisten] connection accepted from 127.0.0.1:35894 #289 (13 connections now open)
2017-06-06T06:57:09.092+0000 I NETWORK [initandlisten] connection accepted from 127.0.0.1:35895 #290 (14 connections now open)
2017-06-06T06:57:17.206+0000 I NETWORK [conn287] end connection 127.0.0.1:35889 (13 connections now open)
2017-06-06T06:57:24.214+0000 I NETWORK [conn281] end connection 127.0.0.1:35882 (12 connections now open)
2017-06-06T06:58:59.404+0000 I NETWORK [initandlisten] connection accepted from 127.0.0.1:35898 #291 (13 connections now open)
2017-06-06T06:59:17.301+0000 I NETWORK [conn277] end connection 127.0.0.1:35866 (12 connections now open)
2017-06-06T06:59:46.326+0000 I NETWORK [conn288] end connection 127.0.0.1:35890 (11 connections now open)
2017-06-06T06:59:49.328+0000 I NETWORK [conn274] end connection 127.0.0.1:35860 (10 connections now open)
2017-06-06T07:00:03.342+0000 I NETWORK [conn290] end connection 127.0.0.1:35895 (9 connections now open)
2017-06-06T07:05:46.650+0000 I NETWORK [conn275] end connection 127.0.0.1:35863 (8 connections now open)
2017-06-06T13:15:43.047+0000 I NETWORK [initandlisten] connection accepted from 127.0.0.1:35995 #292 (9 connections now open)
2017-06-06T13:25:08.760+0000 I NETWORK [conn292] end connection 127.0.0.1:35995 (8 connections now open)
2017-06-07T04:07:48.262+0000 I NETWORK [conn285] end connection 127.0.0.1:35887 (7 connections now open)
2017-06-07T06:00:43.026+0000 I NETWORK [initandlisten] connection accepted from 127.0.0.1:36231 #293 (8 connections now open)
2017-06-07T06:10:21.038+0000 I NETWORK [initandlisten] connection accepted from 127.0.0.1:36236 #294 (9 connections now open)
2017-06-07T06:12:08.906+0000 I NETWORK [conn293] end connection 127.0.0.1:36231 (8 connections now open)
2017-06-07T06:13:03.738+0000 I NETWORK [initandlisten] connection accepted from 127.0.0.1:36238 #295 (9 connections now open)
2017-06-07T06:13:13.005+0000 I NETWORK [initandlisten] connection accepted from 127.0.0.1:36239 #296 (10 connections now open)
2017-06-07T06:14:10.995+0000 I NETWORK [conn294] end connection 127.0.0.1:36236 (9 connections now open)
2017-06-07T06:15:02.038+0000 I NETWORK [conn291] end connection 127.0.0.1:35898 (8 connections now open)
2017-06-07T06:15:16.486+0000 I NETWORK [initandlisten] connection accepted from 127.0.0.1:36244 #297 (9 connections now open)
2017-06-07T06:15:26.680+0000 I NETWORK [initandlisten] connection accepted from 127.0.0.1:36245 #298 (10 connections now open)
2017-06-07T06:16:43.118+0000 I NETWORK [conn282] end connection 127.0.0.1:35883 (9 connections now open)
2017-06-07T06:17:07.667+0000 I NETWORK [initandlisten] connection accepted from 127.0.0.1:36248 #299 (10 connections now open)
2017-06-07T06:17:19.869+0000 I CONTROL [main] ***** SERVER RESTARTED *****
2017-06-07T06:17:19.919+0000 I CONTROL [initandlisten] MongoDB starting : pid=26429 port=27017 dbpath=/var/lib/mongodb 64-bit host=ip-172-31-28-133
2017-06-07T06:17:19.919+0000 I CONTROL [initandlisten] db version v3.2.6
2017-06-07T06:17:19.919+0000 I CONTROL [initandlisten] git version: 05552b562c7a0b3143a729aaa0838e558dc49b25
2017-06-07T06:17:19.919+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014
2017-06-07T06:17:19.919+0000 I CONTROL [initandlisten] allocator: tcmalloc
2017-06-07T06:17:19.919+0000 I CONTROL [initandlisten] modules: none
2017-06-07T06:17:19.919+0000 I CONTROL [initandlisten] build environment:
2017-06-07T06:17:19.919+0000 I CONTROL [initandlisten] distmod: ubuntu1404
2017-06-07T06:17:19.919+0000 I CONTROL [initandlisten] distarch: x86_64
2017-06-07T06:17:19.919+0000 I CONTROL [initandlisten] target_arch: x86_64
2017-06-07T06:17:19.919+0000 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2017-06-07T06:17:19.963+0000 I - [initandlisten] Detected data files in /var/lib/mongodb created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2017-06-07T06:17:19.963+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=1G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2017-06-07T06:17:20.514+0000 I CONTROL [initandlisten]
2017-06-07T06:17:20.514+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2017-06-07T06:17:20.514+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2017-06-07T06:17:20.515+0000 I CONTROL [initandlisten]
2017-06-07T06:17:20.515+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2017-06-07T06:17:20.515+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2017-06-07T06:17:20.515+0000 I CONTROL [initandlisten]
2017-06-07T06:17:20.553+0000 I NETWORK [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2017-06-07T06:17:20.554+0000 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/var/lib/mongodb/diagnostic.data'
我注意到服务重启时会提供信息。但我无法找出崩溃背后的问题。
我怀疑是内存问题,因为谷歌搜索显示内存错误。但日志文件中没有记录这些错误。
我t2.micro
在 AWS EC2 上有一个实例,其中运行着 mongo 脚本。如何防止 mongo 崩溃?
答案1
如果出现问题,MongoDB 会打印一条错误消息,或者至少表明它正在关闭。如果这些消息不存在,则意味着该进程被服务器上的其他东西硬终止。我建议检查您的系统日志,看看操作系统是否出于某种原因决定终止该进程。
即使 MongoDB 重新启动,匿名内存仍然非常高。这表明内存问题不是由 MongoDB 引起的,而是由其他原因引起的。请参考此链接 https://jira.mongodb.org/browse/SERVER-22000
建议仅为 MongoDB 保留服务器,并且每个服务器只分配一个 mongod 进程。