MongoDB被Linux杀死了。

15

我的mongoDB在几个小时没有被访问后,总是接收到一个KILL信号,我不知道原因。

我正在使用:
S.O: Ubuntu 16.04,512MB内存。
使用pm2运行node 7.5.0。
MongoDB版本为3.4.1

mongod状态:

mongod.service - High-performance, schema-free document-oriented database
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: failed (Result: signal) since Fri 2017-06-02 06:25:06 BRT; 9h ago
 Docs: https://docs.mongodb.org/manual
Process: 1334 ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf (code=killed, signal=KILL)
Main PID: 1334 (code=killed, signal=KILL)

May 29 19:12:16 admin systemd[1]: Started High-performance, schema-free document-oriented database.
Jun 02 06:25:06 admin systemd[1]: mongod.service: Main process exited, code=killed, status=9/KILL
Jun 02 06:25:06 admin systemd[1]: mongod.service: Unit entered failed state.
Jun 02 06:25:06 admin systemd[1]: mongod.service: Failed with result 'signal'.

Mongod.service:

[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
Documentation=https://docs.mongodb.org/manual

[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false

[Install]
WantedBy=multi-user.target

etc/mongod.conf:

storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true

systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

net:
  port: 27017
  bindIp: 127.0.0.1

processManagement:
  fork: false

journalctl:

Jun 01 22:32:02 admin pm2[23634]: [PM2] Spawning PM2 daemon with pm2_home=/home/administrator/.pm2
Jun 01 22:32:02 admin pm2[23634]: [PM2] PM2 Successfully daemonized
Jun 01 22:32:02 admin pm2[23634]: [PM2] Stopping PM2...
Jun 01 22:32:02 admin pm2[23634]: [PM2][WARN] No process found
Jun 01 22:32:02 admin pm2[23634]: [PM2] All processes have been stopped and deleted
Jun 01 22:32:02 admin pm2[23634]: [PM2] PM2 stopped
Jun 01 22:32:06 admin pm2[23649]: pm2 launched in no-daemon mode (you can add DEBUG="*" env variable to get more messages)
Jun 01 22:32:06 admin pm2[23649]: 2017-06-01 22:32:06: Launching in no daemon mode
Jun 01 22:32:06 admin pm2[23649]: 2017-06-01 22:32:06: [PM2] Resurrecting
Jun 01 22:32:06 admin pm2[23649]: 2017-06-01 22:32:06: [PM2] Restoring processes located in /home/administrator/.pm2/dump.pm2
Jun 01 22:32:06 admin pm2[23649]: 2017-06-01 22:32:06: [Watch] Start watching 0
Jun 01 22:32:06 admin pm2[23649]: 2017-06-01 22:32:06: Starting execution sequence in -fork mode- for app name:MY_NODE id:1
Jun 01 22:32:06 admin pm2[23649]: 2017-06-01 22:32:06: App name:MY_NODE id:1 online
Jun 01 22:32:06 admin pm2[23649]: 2017-06-01 22:32:06: [PM2] Process /home/servers/nodejs/server_MY_NODE/server.js restored
Jun 01 22:32:07 admin pm2[23649]: 2017-06-01 22:32:07: ┌─────────────┬────┬──────┬───────┬────────┬─────────┬────────┬─────┬───────────┬──────────┐
Jun 01 22:32:07 admin pm2[23649]: 2017-06-01 22:32:07: │ App name    │ id │ mode │ pid   │ status │ restart │ uptime │ cpu │ mem       │ watching │
Jun 01 22:32:07 admin pm2[23649]: 2017-06-01 22:32:07: ├─────────────┼────┼──────┼───────┼────────┼─────────┼────────┼─────┼───────────┼──────────┤
Jun 01 22:32:07 admin pm2[23649]: 2017-06-01 22:32:07: │   MY_NODE   │ 1  │ fork │ 23665 │ online │ 0       │ 0s     │ 24% │ 23.9 MB   │ disabled │
Jun 01 22:32:07 admin pm2[23649]: 2017-06-01 22:32:07: └─────────────┴────┴──────┴───────┴────────┴─────────┴────────┴─────┴───────────┴──────────┘
Jun 01 22:32:07 admin pm2[23649]: 2017-06-01 22:32:07:  Use `pm2 show <id|name>` to get more details about an app
Jun 01 22:32:07 admin pm2[23649]: 2017-06-01 22:32:07: [--no-daemon] Continue to stream logs
Jun 01 22:32:07 admin pm2[23649]: 2017-06-01 22:32:07: [--no-daemon] Exit on target PM2 exit pid=23649
Jun 01 22:32:07 admin pm2[23649]: 2017-06-01 22:32:07: [STREAMING] Now streaming realtime logs for [all] processes
Jun 01 22:32:07 admin pm2[23649]: 22:32:07 1|MY_NODE | WARNING: NODE_APP_INSTANCE value of '0' did not match any instance config file names.
Jun 01 22:32:07 admin pm2[23649]: 22:32:07 1|MY_NODE | WARNING: See https://github.com/lorenwest/node-config/wiki/Strict-Mode
Jun 01 22:32:09 admin pm2[23649]: 22:32:09 1|MY_NODE | Express Server in 10555
Jun 01 22:32:09 admin pm2[23649]: 22:32:09 1|MY_NODE | Database! connected in mongodb://localhost/MY_MONGO
Jun 02 06:25:05 admin pm2[23649]: 2017-06-02 06:25:05: App [MY_NODE] with id [1] and pid [23665], exited with code [0] via signal [SIGKILL]
Jun 02 06:25:05 admin pm2[23649]: 2017-06-02 06:25:05: Starting execution sequence in -fork mode- for app name:MY_NODE id:1
Jun 02 06:25:05 admin pm2[23649]: 06:25:05 PM2        | App [MY_NODE] with id [1] and pid [23665], exited with code [0] via signal [SIGKILL]
Jun 02 06:25:05 admin pm2[23649]: 06:25:05 PM2        | Starting execution sequence in -fork mode- for app name:MY_NODE id:1
Jun 02 06:25:05 admin pm2[23649]: 2017-06-02 06:25:05: App name:MY_NODE id:1 online
Jun 02 06:25:05 admin pm2[23649]: 06:25:05 PM2        | App name:MY_NODE id:1 online
Jun 02 06:25:06 admin pm2[23649]: 06:25:06 1|MY_NODE | WARNING: NODE_APP_INSTANCE value of '0' did not match any instance config file names.
Jun 02 06:25:06 admin pm2[23649]: 06:25:06 1|MY_NODE | WARNING: See https://github.com/lorenwest/node-config/wiki/Strict-Mode
Jun 02 06:25:08 admin pm2[23649]: 06:25:08 1|MY_NODE | Express Server in 10555
Jun 02 06:25:08 admin pm2[23649]: 06:25:08 1|MY_NODE | Database! disconnected from mongodb://localhost/MY_MONGO
Jun 02 06:25:08 admin pm2[23649]: 06:25:08 1|MY_NODE | Database! Error in connection mongodb://localhost/MY_MONGO

谁能帮我,我会非常感激

谢谢


1
你的机器RAM使用情况如何?是否有可用的交换空间?可能mongod进程的内存泄漏是否导致OOM事件/被oom-killer终止?free命令的输出是什么?也许会遇到这个问题:链接 - Matt Clark
2
服务器可用空间为250MB,交换空间未激活。 - Armando
3
如果您没有进行任何交换空间的分配,那么我强烈认为您的物理内存已经不足,进程可能被oom-killer杀死。 - Matt Clark
2
@MattClark,这是我执行命令“dmesg”并显示消息的内容:“Killed process 1334 (mongod) total-vm:760892kB, anon-rss:30944kB, file-rss:11812kB” - Armando
2
增加交换空间解决了我的问题。 - fillobotto
检查了dmesg 内存不足:杀死进程16279(mongod)得分14或牺牲子进程 已杀死进程16279(mongod),总虚拟内存:4245156kB,匿名rss:629216kB,文件rss:0kB服务器有32GB RAM,几乎全部空闲,16GB交换空间 - 全部空闲。 - ulikus
1个回答

7
根据Mongo-DB文档,Ulimit可以影响Mongo服务。我通过运行以下命令 ulimit -a 来确认这是问题所在,并解决了同样的问题。
如果-n标志小于64,000,则必须更改它:sudo ulimit -n 64000 然后重启mongo: sudo systemctl restart mongod 并确保现在正在运行: systemctl status mongod

您还应该能够在*.service*文件本身中设置限制。现在,如果您通过官方安装脚本安装了MongoDB,则这些限制应该已经设置好了。 - Aros
尝试过了,但在Ubuntu 20.04上对我没起作用。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接