MongoDB数据库启动失败

目录

问题

解决


问题

自己的云转码服务器用到了MongoDB数据库,使用docker部署的有些情况下,转码服务启动时会遇到数据库服务无法伴随启动的现象。

这个时候,就必须依赖自己手动启动数据库服务。

相关的报错信息如下:

0|www  | (node:248) [MONGODB DRIVER] Warning: Current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
0|www  | You have triggered an unhandledRejection, you may have forgotten to catch a Promise rejection:
0|www  | MongoNetworkError: failed to connect to server [127.0.0.1:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]
0|www  |     at Pool.<anonymous> (/root/boffmpeg/node_modules/mongoose/node_modules/mongodb/lib/core/topologies/server.js:438:11)
0|www  |     at emitOne (events.js:116:13)
0|www  |     at Pool.emit (events.js:211:7)
0|www  |     at createConnection (/root/boffmpeg/node_modules/mongoose/node_modules/mongodb/lib/core/connection/pool.js:562:14)
0|www  |     at connect (/root/boffmpeg/node_modules/mongoose/node_modules/mongodb/lib/core/connection/pool.js:995:11)
0|www  |     at makeConnection (/root/boffmpeg/node_modules/mongoose/node_modules/mongodb/lib/core/connection/connect.js:32:7)
0|www  |     at callback (/root/boffmpeg/node_modules/mongoose/node_modules/mongodb/lib/core/connection/connect.js:280:5)
0|www  |     at Socket.err (/root/boffmpeg/node_modules/mongoose/node_modules/mongodb/lib/core/connection/connect.js:310:7)
0|www  |     at Object.onceWrapper (events.js:315:30)
0|www  |     at emitOne (events.js:116:13)
0|www  |     at Socket.emit (events.js:211:7)
0|www  |     at emitErrorNT (internal/streams/destroy.js:73:8)
0|www  |     at _combinedTickCallback (internal/process/next_tick.js:139:11)
0|www  |     at process._tickCallback (internal/process/next_tick.js:181:9)

类似的报错:

 Failed to get D-Bus connection: Operation not permitted

解决

手动启动MongoDB数据库服务,需要找到该服务的可执行程序和相应的配置文件,然后使用-f参数执行如下命令:

/usr/bin/mongod -f /etc/mongod.conf 

出现successfully信息,表示启动成功。

比如:

[root@731ae35768eb boffmpeg]# /usr/bin/mongod -f /etc/mongod.conf
about to fork child process, waiting until server is ready for connections.
forked process: 3304
child process started successfully, parent exiting

但是,最直接的方式还是在运行容器的时候,指定特殊权限,具体命令可以参考:

docker run -itd --net=host --restart=always --name boffmpeg --privileged=true 0ba8f07ac61d /usr/sbin/init 

上一篇:qt因指针未初始化而引发的crash错误


下一篇:工厂方法模式实例