我在Azure VPS上运行Ubuntu 15。我安装了MongoDB并且运行良好。然后,我停止了mongod
服务,我更改了mongod.conf
中的数据库路径和日志路径,指向我在附加磁盘上创建的目录:
# Where and how to store data.
storage:
dbPath: /datadrive/lib/mongodb
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /datadrive/log/mongodb/mongod.log
我重新启动了整个VPS,以确保新更改生效。现在当我输入mongo
时,我收到以下错误:
2016-02-05T14:49:41.004+0000 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2016-02-05T14:49:41.018+0000 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:224:14
@(connect):1:6
如果我撤消更改并使用原始的log
和lib
位置,则可以正常运行。我该怎么做才能确保使用新的位置?
修改
保留旧的日志位置并尝试上述步骤后,我在日志中得到以下内容:
2016-02-05T15:19:47.049+0000 I CONTROL [main] ***** SERVER RESTARTED *****
2016-02-05T15:19:47.146+0000 I CONTROL [initandlisten] MongoDB starting : pid=1158 port=27017 dbpath=/datadrive/lib/mongodb 64-bit host=CLIENTPROJECTS
2016-02-05T15:19:47.146+0000 I CONTROL [initandlisten] db version v3.2.1
2016-02-05T15:19:47.146+0000 I CONTROL [initandlisten] git version: a14d55980c2cdc565d4704a7e3ad37e4e535c1b2
2016-02-05T15:19:47.146+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2d 9 Jul 2015
2016-02-05T15:19:47.146+0000 I CONTROL [initandlisten] allocator: tcmalloc
2016-02-05T15:19:47.146+0000 I CONTROL [initandlisten] modules: none
2016-02-05T15:19:47.146+0000 I CONTROL [initandlisten] build environment:
2016-02-05T15:19:47.146+0000 I CONTROL [initandlisten] distmod: ubuntu1404
2016-02-05T15:19:47.146+0000 I CONTROL [initandlisten] distarch: x86_64
2016-02-05T15:19:47.146+0000 I CONTROL [initandlisten] target_arch: x86_64
2016-02-05T15:19:47.146+0000 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, storage: { dbPath: "/datadrive/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2016-02-05T15:19:47.693+0000 I STORAGE [initandlisten] exception in initAndListen: 98 Unable to create/open lock file: /datadrive/lib/mongodb/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
2016-02-05T15:19:47.693+0000 I CONTROL [initandlisten] dbexit: rc: 100
答案 0 :(得分:1)
首先,您可以检查mongod是否已启动:/datadrive/log/mongodb/mongod.log
,然后检查日志ps aux | grep mongod
中的内容。
修改强>
停止所有mongod实例(rm /datadrive/lib/mongodb/mongod.lock
应该不显示任何内容),删除锁定文件/datadrive/lib/mongodb/
,然后重新启动该服务。
<强> EDIT2:强>
配置/datadrive/log/mongodb/
和mongodb:mongodb
中的目录应该存在并且属于mongodb用户。默认情况下,它是/etc/init.d/mongodb
,并在DAEMONUSER
中定义为{{1}}。