安装MongoDB,尝试配置成服务后,启动一直不成功
# systemctl start mongod # systemctl status mongod ● mongod.service - High-performance, schema-free document-oriented database Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled) Active: inactive (dead) since 五 2021-10-29 18:14:10 CST; 4s ago Docs: https://docs.mongodb.org/manual Process: 3921 ExecStart=/usr/local/mongodb/bin/mongod $OPTIONS (code=exited, status=0/SUCCESS) Main PID: 3921 (code=exited, status=0/SUCCESS) 10月 29 18:14:09 abce systemd[1]: Started High-performance, schema-free document-oriented database. 10月 29 18:14:09 abce mongod[3921]: about to fork child process, waiting until server is ready for connections. 10月 29 18:14:09 abce mongod[3921]: forked process: 3925 10月 29 18:14:10 abce mongod[3921]: child process started successfully, parent exiting
启动的时候,进程会自动被kill掉。
看看mongodb的日志可以看到,会自动发送kill信号
{"t":{"$date":"2021-10-29T18:14:10.140+08:00"},"s":"I", "c":"CONTROL", "id":23377, "ctx":"SignalHandler","msg":"Received signal","attr":{"signal":15,"error":"Terminated"}} {"t":{"$date":"2021-10-29T18:14:10.140+08:00"},"s":"I", "c":"CONTROL", "id":23378, "ctx":"SignalHandler","msg":"Signal was sent by kill(2)","attr":{"pid":1,"uid":0}} {"t":{"$date":"2021-10-29T18:14:10.140+08:00"},"s":"I", "c":"CONTROL", "id":23381, "ctx":"SignalHandler","msg":"will terminate after current cmd ends"}
原因和解决方法:
在/usr/lib/systemd/system/mongod.service文件中添加
PIDFile=mongod.pid(实际pid文件名和路径)