我有一个ubuntu 16.04,我昨天用sudo aptitude install mongodb在上面安装了mongodb;它一开始就工作得很好。我决定向mongodb添加身份验证信息,因此我打开了一个会话,在shell中编写mongo,然后输入以下命令:
use admin
db.createUser({user:"admin", pwd:"admin123", roles:[{role:"root", db:"admin"}]})它说已经成功地添加了用户。我输入exit来设置配置,以便在启动服务时使用身份验证。我编辑了vim /lib/systemd/system/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 --auth
[Install]
WantedBy=multi-user.target在那之后,我在shell中输入了systemd daemon-reload,然后是service mongod restart;但是mongodb始终没有启动。当我试图使用命令mongo连接到mongo -u admin -p admin123 --authenticationDatabase admin时,它向我展示了:
mongo -u admin -p admin123 --authenticationDatabase admin
MongoDB shell version: 2.6.10
connecting to: test
2017-08-08T10:37:52.751+0430 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2017-08-08T10:37:52.751+0430 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed它说没有服务器正在运行(connect failed);另外,我不知道为什么在插入admin时它试图连接到test?!然而,命令systemctl status mongodb显示如下:
● mongodb.service - An object/document-oriented database
Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Mon 2017-08-07 16:02:30 IRDT; 18h ago
Docs: man:mongod(1)
Main PID: 11367 (code=exited, status=0/SUCCESS)
Aug 07 15:33:14 ZiZi systemd[1]: Started An object/document-oriented database.
Aug 07 16:02:30 ZiZi systemd[1]: Stopping An object/document-oriented database...
Aug 07 16:02:30 ZiZi systemd[1]: Stopped An object/document-oriented database.没有在文件/var/log/mongodb/mongodb.log中写入日志。
当我在shell中输入ExecStart时,我可以成功地启动mongo:
sudo /usr/bin/mongod --quiet --auth
2017-08-08T10:53:27.358+0430 [initandlisten] MongoDB starting : pid=29830 port=27017 dbpath=/data/db 64-bit host=ZiZi
2017-08-08T10:53:27.359+0430 [initandlisten] db version v2.6.10
2017-08-08T10:53:27.359+0430 [initandlisten] git version: nogitversion
2017-08-08T10:53:27.359+0430 [initandlisten] OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016
2017-08-08T10:53:27.359+0430 [initandlisten] build info: Linux lgw01-12 3.19.0-25-generic #26~14.04.1-Ubuntu SMP Fri Jul 24 21:16:20 UTC 2015 x86_64 BOOST_LIB_VERSION=1_58
2017-08-08T10:53:27.359+0430 [initandlisten] allocator: tcmalloc
2017-08-08T10:53:27.359+0430 [initandlisten] options: { security: { authorization: "enabled" }, systemLog: { quiet: true } }
2017-08-08T10:53:27.360+0430 [initandlisten] journal dir=/data/db/journal
2017-08-08T10:53:27.360+0430 [initandlisten] recover : no journal files present, no recovery needed
2017-08-08T10:53:27.431+0430 [initandlisten] waiting for connections on port 27017我已经使用描述了mongodb的说明重新安装了这里;现在它的最新版本是:
mongod --version
db version v3.4.7
git version: cf38c1b8a0a8dca4a11737581beafef4fe120bcd
OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016
allocator: tcmalloc
modules: none
build environment:
distmod: ubuntu1604
distarch: x86_64
target_arch: x86_64我再次添加了身份验证;我的/lib/systemd/system/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 --auth --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
# Recommended limits for for mongod as specified in
# http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings
[Install]
WantedBy=multi-user.target这是我的/etc/mongod.conf:
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1
#processManagement:
security:
auth: true
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:用户添加过程成功:
> use admin
switched to db admin
> db.createUser(
... {
... user: "myUserAdmin",
... pwd: "abc123",
... roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
... }
... )
Successfully added user: {
"user" : "myUserAdmin",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
]
}我已经重新加载了systemctl并重新启动了mongod服务,但是mongod服务仍然无法启动。我没有--quiet选项,但是/var/log/mongodb/mongod.log文件中没有日志。这是service mongod status返回的内容:
service mongod status
● mongod.service - High-performance, schema-free document-oriented database
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2017-08-09 16:12:42 IRDT; 1min 0s ago
Docs: https://docs.mongodb.org/manual
Process: 2030 ExecStart=/usr/bin/mongod --auth --config /etc/mongod.conf (code=exited, status=2)
Main PID: 2030 (code=exited, status=2)
Aug 09 16:12:42 ZiZi systemd[1]: Stopped High-performance, schema-free document-oriented database.
Aug 09 16:12:42 ZiZi systemd[1]: Started High-performance, schema-free document-oriented database.
Aug 09 16:12:42 ZiZi systemd[1]: mongod.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Aug 09 16:12:42 ZiZi systemd[1]: mongod.service: Unit entered failed state.
Aug 09 16:12:42 ZiZi systemd[1]: mongod.service: Failed with result 'exit-code'.这意味着我有一个我无法检测到的INVALIDARGUMENT。有什么帮助吗?
发布于 2017-08-08 08:00:53
单神没有开始的原因有很多,但是..。
首先,为什么mongodb.log没有任何行,原因是--quiet -parameter。我不会使用它,因为它使得很难认识到什么是问题的根源。因此,删除它,然后再试一次,这一次日志文件中应该有哪些行说明出了什么问题。
其次,至少在我的Ubuntu安装中,启动服务行是ExecStart=/usr/bin/mongod --config /etc/mongod.conf --这意味着所有配置都是在/etc/mongod.conf -file中完成的,这无论如何都是配置服务的最佳位置,因为更新期间不会覆盖该文件。
更改(在mongod.conf中),使auth:true to auth:enabled(请记住在授权-word之前保留这些空格字符)。
https://dba.stackexchange.com/questions/182919
复制相似问题