Mongo服务启动或重启总是失败
Mongo service start or restart always fail
我已经安装了 mongodb,然后我创建了一个 mongo 服务:
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
[Service]
User=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
[Install]
WantedBy=multi-user.target
但是当我启动服务然后检查状态时,我总是得到这个错误:
● mongodb.service - High-performance, schema-free document-oriented database
Loaded: loaded (/etc/systemd/system/mongodb.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2017-04-24 13:08:55 UTC; 6min ago
Process: 1094 ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf (code=exited, status=48)
Main PID: 1094 (code=exited, status=48)
Apr 24 13:08:54 ip-172-31-37-163 systemd[1]: Started High-performance, schema-free document-oriented database.
Apr 24 13:08:55 ip-172-31-37-163 systemd[1]: mongodb.service: Main process exited, code=exited, status=48/n/a
Apr 24 13:08:55 ip-172-31-37-163 systemd[1]: mongodb.service: Unit entered failed state.
Apr 24 13:08:55 ip-172-31-37-163 systemd[1]: mongodb.service: Failed with result 'exit-code'.
问题出在配置文件中并正在更改
bindIp: 127.0.0.1, X.X.X.X
到
bindIp: [127.0.0.1, X.X.X.X]
解决了我的问题
在MongoDB 3.6 中,@Chlebta 提出的括号对我不起作用,返回错误:
mongod.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
我的错误是用逗号和空格分隔 IP 地址。地址之间只能有逗号:
bindIp: 127.0.0.1,X.X.X.X,Y.Y.Y.Y
我只是重新启动系统 (sudo reboot) 它对我有用。我不知道为什么。
尝试更改所有者权限
chown -R mongodb:mongodb /var/lib/mongodb
chown mongodb:mongodb /tmp/mongodb-27017.sock
更新 Ubuntu 20.04 和 MongoDB 服务器版本 4.4.2...
我的问题最终是我试图使用我机器的 public IP 地址。
一旦我指定了我的 private IP 地址,一切都开始工作了。 mongod 服务启动没有任何错误,我现在可以从远程机器连接到它。
在 Ubuntu 上,您可以使用以下命令获取您的私有 IP 地址:
hostname -I | awk '{print }'
这是我在 /etc/mongod.conf 中的内容(仅显示相关部分和部分私有 IP 地址):
net:
port: 27017
bindIp: 127.0.0.1, 172.##.##.##
security:
authorization: enabled
请注意,将两个 IP 地址括起来(如接受的答案)对我不起作用,并导致 mongod 状态代码为 2(实际上是 [= 中的语法错误37=] 文件)。此外,逗号后的 space 现在似乎可以使用,但不是必需的。
我已经安装了 mongodb,然后我创建了一个 mongo 服务:
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
[Service]
User=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
[Install]
WantedBy=multi-user.target
但是当我启动服务然后检查状态时,我总是得到这个错误:
● mongodb.service - High-performance, schema-free document-oriented database
Loaded: loaded (/etc/systemd/system/mongodb.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2017-04-24 13:08:55 UTC; 6min ago
Process: 1094 ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf (code=exited, status=48)
Main PID: 1094 (code=exited, status=48)
Apr 24 13:08:54 ip-172-31-37-163 systemd[1]: Started High-performance, schema-free document-oriented database.
Apr 24 13:08:55 ip-172-31-37-163 systemd[1]: mongodb.service: Main process exited, code=exited, status=48/n/a
Apr 24 13:08:55 ip-172-31-37-163 systemd[1]: mongodb.service: Unit entered failed state.
Apr 24 13:08:55 ip-172-31-37-163 systemd[1]: mongodb.service: Failed with result 'exit-code'.
问题出在配置文件中并正在更改
bindIp: 127.0.0.1, X.X.X.X
到
bindIp: [127.0.0.1, X.X.X.X]
解决了我的问题
在MongoDB 3.6 中,@Chlebta 提出的括号对我不起作用,返回错误:
mongod.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
我的错误是用逗号和空格分隔 IP 地址。地址之间只能有逗号:
bindIp: 127.0.0.1,X.X.X.X,Y.Y.Y.Y
我只是重新启动系统 (sudo reboot) 它对我有用。我不知道为什么。
尝试更改所有者权限
chown -R mongodb:mongodb /var/lib/mongodb
chown mongodb:mongodb /tmp/mongodb-27017.sock
更新 Ubuntu 20.04 和 MongoDB 服务器版本 4.4.2...
我的问题最终是我试图使用我机器的 public IP 地址。
一旦我指定了我的 private IP 地址,一切都开始工作了。 mongod 服务启动没有任何错误,我现在可以从远程机器连接到它。
在 Ubuntu 上,您可以使用以下命令获取您的私有 IP 地址:
hostname -I | awk '{print }'
这是我在 /etc/mongod.conf 中的内容(仅显示相关部分和部分私有 IP 地址):
net:
port: 27017
bindIp: 127.0.0.1, 172.##.##.##
security:
authorization: enabled
请注意,将两个 IP 地址括起来(如接受的答案)对我不起作用,并导致 mongod 状态代码为 2(实际上是 [= 中的语法错误37=] 文件)。此外,逗号后的 space 现在似乎可以使用,但不是必需的。