关于mongodb服务自动停止问题

昨天发现系统宕机了,查了下原因是mongodb服务停了,看了下日志:
2017-10-18T18:09:59.181+0800 I CONTROL  [signalProcessingThread] got signal 1 (Hangup), will terminate after current cmd ends
2017-10-18T18:09:59.181+0800 I FTDC     [signalProcessingThread] Shutting down full-time diagnostic data capture
2017-10-18T18:09:59.225+0800 I CONTROL  [signalProcessingThread] now exiting
2017-10-18T18:09:59.226+0800 I NETWORK  [signalProcessingThread] shutdown: going to close listening sockets...
2017-10-18T18:09:59.226+0800 I NETWORK  [signalProcessingThread] closing listening socket: 6
2017-10-18T18:09:59.226+0800 I NETWORK  [signalProcessingThread] closing listening socket: 7
2017-10-18T18:09:59.226+0800 I NETWORK  [signalProcessingThread] removing socket file: /tmp/mongodb-27017.sock
2017-10-18T18:09:59.226+0800 I NETWORK  [signalProcessingThread] shutdown: going to flush diaglog...
2017-10-18T18:09:59.226+0800 I NETWORK  [signalProcessingThread] shutdown: going to close sockets...
2017-10-18T18:09:59.226+0800 I STORAGE  [signalProcessingThread] WiredTigerKVEngine shutting down
2017-10-18T18:09:59.226+0800 I NETWORK  [conn14] end connection 127.0.0.1:37191 (3 connections now open)
2017-10-18T18:09:59.227+0800 I NETWORK  [conn13] end connection 127.0.0.1:37190 (3 connections now open)
2017-10-18T18:09:59.227+0800 I NETWORK  [conn12] end connection 127.0.0.1:37189 (3 connections now open)
2017-10-18T18:09:59.227+0800 I NETWORK  [conn11] end connection 127.0.0.1:37188 (3 connections now open)
2017-10-18T18:09:59.258+0800 I STORAGE  [signalProcessingThread] shutdown: removing fs lock...
2017-10-18T18:09:59.258+0800 I CONTROL  [signalProcessingThread] dbexit:  rc: 0

重新起mongodb的服务(命令:nohup /home/mongodb-linux-x86_64-rhel62-3.2.3/bin/mongod -dbpath /home/mongodb &),系统又重新正常运行了。关闭Xshell之后系统又宕了。

查了下资料,原因是直接关闭Xshell窗口之后,linux认为是异常退出,这个shell进程会收到SIGNUP信号,然后给它所有的子进程发送SIGHUP信号。

但是在mongodb启动命令中加-fork参数,会自动将其挂到init进程(pid为1)下启动,如果不加的话ppid(父进程id)就是当前的shell进程,所以加上–fork问题就可以解决了。
1.启动命令:/home/mongodb-linux-x86_64-rhel62-3.2.3/bin/mongod --dbpath /home/mongodb --logpath=/home/mongodb/rs2.1.log --fork
(命令参考:./mongod -dbpath=/usr/local/mongodb/data -logpath=/usr/local/mongodb/mongodb.log -logappend -port=27017 -fork)

2.通过配置文件启动.mongodb.conf

dbpath=/usr/local/mongodb/data
logpath=/usr/local/mongodb/mongodb.log
port=27017
bind_ip=0.0.0.0 //开启远程访问,注意做好权限配置
logappend=true 
fork=true

./mongod --config /usr/local/mongodb/etc/mongodb.conf

参考:http://blog.csdn.net/shawyeok/article/details/46486683

你可能感兴趣的:(关于mongodb服务自动停止问题)