MongoDB status failed after editing mongo.conf (code-exited, status=2) - mongodb

I'm trying to connect remotely to my Google Cloud Server with Robo 3T to connect too MongoDB v4.0.11 just so I can see the data from windows.
I am running Ubuntu 18.04LTS Minimal. To enable remote connections to MongoDB I have first created both an administrative and root user in my admin database.
My problem is once I add authorization: "enabled" to security: in /etc/mongod.conf and restart MongoDB, I get the following status when running $:systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2019-08-06 16:43:51 BST; 1min 20s ago
Docs: https://docs.mongodb.org/manual
Process: 6517 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=2)
Main PID: 6517 (code=exited, status=2)
Aug 06 16:43:51 instance-1 systemd[1]: Started MongoDB Database Server.
Aug 06 16:43:51 instance-1 mongod[6517]: Unrecognized option: processManagement.authorization
Aug 06 16:43:51 instance-1 mongod[6517]: try '/usr/bin/mongod --help' for more information
Aug 06 16:43:51 instance-1 systemd[1]: mongod.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Aug 06 16:43:51 instance-1 systemd[1]: mongod.service: Failed with result 'exit-code'.
Example of /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
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
#security:
authorization: "enabled"
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:
It appears there is an invalid argument in /etc/mongod.conf but from what I have read online I can't see the problem.

wrong:
#security:
authorization: "enabled"
correct:
security:
authorization: enabled

For the 4.x release it appears you need to modify the existing security section you have listed
#security:
authorization: "enabled"
And replace it with security.authorization: enabled or
security:
authorization: "enabled"
You should then be able to reload and test authentication is working as expected.
If you dig into the docs you will find the relevant section here.
security.authorization
Type: string
Default: disabled
Enable or disable Role-Based Access Control (RBAC) to govern each user’s access to database resources and operations.
Set this option to one of the following:
Value Description
enabled A user can access only the database resources and actions for which they have been granted privileges.
disabled A user can access any database and perform any action.

In my case the problem was that I used a tab to indent the authorization: enabled line. When I replaced the tab with 2 spaces it worked.

Related

Can't open PID file /var/run/mongodb/mongod.pid (yet?) after start: Too many levels of symbolic links MongoDB Centos 7

I've installed mongodb on centos 7, but I can't start the service with systemctl.
Running mongod starts successfully.
I've followed all the instructions from here: https://mongoing.com/docs/tutorial/install-mongodb-on-red-hat.html
systemctl status mongod returns this:
* mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/mongod.service.d
`-override.conf
Active: failed (Result: timeout) since Sun 2020-05-03 14:58:02 CEST; 4min 27s ago
Docs: https://docs.mongodb.org/manual
Process: 528 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=0/SUCCESS)
Process: 525 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 522 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 519 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)
May 03 14:56:32 zakazise systemd[1]: Starting MongoDB Database Server...
May 03 14:56:32 zakazise mongod[528]: about to fork child process, waiting until server is ready for connections.
May 03 14:56:32 zakazise mongod[528]: forked process: 530
May 03 14:56:34 zakazise systemd[1]: Can't open PID file /var/run/mongodb/mongod.pid (yet?) after start: Too many levels of symbolic links
May 03 14:58:02 zakazise systemd[1]: mongod.service start operation timed out. Terminating.
May 03 14:58:02 zakazise systemd[1]: Failed to start MongoDB Database Server.
May 03 14:58:02 zakazise systemd[1]: Unit mongod.service entered failed state.
May 03 14:58:02 zakazise systemd[1]: mongod.service failed.
There is a line in /var/log/mongodb/mongod.log , that I think might be important:
2020-05-03T14:58:02.210+0200 I CONTROL [signalProcessingThread] got signal 15 (Terminated), will terminate after current cmd ends
/etc/mongod.conf:
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
# engine:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
timeZoneInfo: /usr/share/zoneinfo
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
/etc/systemd/system/multi-user.target.wants/mongod.service:
[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network.target
[Service]
User=mongod
Group=mongod
Environment="OPTIONS=-f /etc/mongod.conf"
EnvironmentFile=-/etc/sysconfig/mongod
ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb
ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb
ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb
ExecStart=/usr/bin/mongod $OPTIONS
PermissionsStartOnly=true
PIDFile=/var/run/mongodb/mongod.pid
Type=forking
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# locked memory
LimitMEMLOCK=infinity
# 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
I didn't change anything in mongod.conf and mongod.service. This is a fully fresh install.
Steps I've tried:
touch /var/run/mongodb/mongod.pid
chown mongod:mongod/var/run/mongodb/mongod.pid
I've checked every path with mongo in it, and they have the right
privileges. (mongod:mongod)
Checked that SELinux is disabled.
Allowed 27017 in ufw.
EDIT
/var/run/mongodb has every rwx.
I'm logged in as root
These two paths are different:
May 02 21:53:44 zakazise systemd[1]: Can't open PID file /var/run/mongodb/mongod.pid (yet?) after start: Too many levels of symbolic links
pidFilePath: /var/run/mongo/mongod.pid # location of pidfile

MongoDB Connection Refused, installation

I am new with mongoDB, I have just installed mongoDB following this doucumantation and when i try to run using mongo i get the following error
MongoDB shell version v4.2.3
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
2020-03-02T17:59:27.311+0530 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect#src/mongo/shell/mongo.js:341:17
#(connect):2:6
2020-03-02T17:59:27.313+0530 F - [main] exception: connect failed
2020-03-02T17:59:27.313+0530 E - [main] exiting with code 1
The status by running the command - systemctl status mongod is
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2020-03-02 17:32:55 IST; 30min ago
Docs: https://docs.mongodb.org/manual
Main PID: 16322 (code=exited, status=14)
Mar 02 17:32:55 hp-laptop-15-bs0xx systemd[1]: Started MongoDB Database Server.
Mar 02 17:32:55 hp-laptop-15-bs0xx systemd[1]: mongod.service: Main process exited, code=exite
Mar 02 17:32:55 hp-laptop-15-bs0xx systemd[1]: mongod.service: Failed with result 'exit-code'.
lines 1-9/9 (END)
`
logs from /etc/mongod.conf is
# Where and how to store data.
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
# 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
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
I also have started the database using systemctl start mongod
I also have uninstalled mongodb and reinstalled it again. I can't seem to figure out whats wrong.
In your config file the processManagement section should be like this:
# how the process runs
processManagement:
fork: true
pidFilePath: /var/run/mongodb/mongod.pid
timeZoneInfo: /usr/share/zoneinfo
Default for processManagement.fork = false, thus the service may not start.

Always get "Active: failed" on 'sudo systemctl status mongod' command

I followed this link to install MongoDB on my machine. Everything was fine and it worked.
Currently, when I run sudo systemctl status mongod, I get this error:
● 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 سه<U+200C>شنبه 2019-05-21 15:50:14 +0430; 25min ago
Docs: https://docs.mongodb.org/manual
Process: 5278 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=1/FAILURE)
Main PID: 5278 (code=exited, status=1/FAILURE)
مه 21 15:50:14 [my-username] systemd[1]: Started High-performance, schema-free document-oriented database.
مه 21 15:50:14 [my-username] systemd[1]: mongod.service: Main process exited, code=exited, status=1/FAILURE
مه 21 15:50:14 [my-username] systemd[1]: mongod.service: Unit entered failed state.
مه 21 15:50:14 [my-username] systemd[1]: mongod.service: Failed with result 'exit-code'.
This is what I have done after it was ok, that might have caused the problem:
I decided to add mongodb extension using pecl.
I was not able to make a new database, neither by MongodDB Compassm, nor by Sell.
I uninstalled it.
I installed it from the same link and ran the same commands, but when I wanted to install it again, after running sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
command, I got gpg: unchanged: 1 at the end, not gpg: imported: 1 (RSA: 1) which I got for the first time.
I even deleted and recreated my dbPath folder (/var/lib/mongodb) which seems that the problem is somehow associated with this parameter which is on /etc/mongod.conf.
When I run sudo systemctl status mongod, I still get Active: failed.
What should I do to run MongoDB properly again and make its status Active: Running?
Update: This is my /etc/mongod.conf file:
# 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:
authorization: "enabled"
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:
I solved the problem by uninstalling MongoDB and installing a specific version of MongoDB, not the latest version, using this link. This might not be the actual solution but works for now.

MongoDB impossible to connect when start as a service

I did install mongodb(3.2.18) on my ubuntu server ( 16.04 ) named automationTaskV3 . It work when i'm working on my server, but when i try to connect from my computer it failed only when mongodb is start as a service.
For example if i start mongod this way :
sudo mongod
it will work i can access my dbs
But if i do :
sudo service mongod start
it will be impossible for me to connect from my computer.
Otherwise the mongod service status seems ok :
sudo service mongod status
● mongod.service - High-performance, schema-free document-oriented database
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2017-11-30 17:34:46 UTC; 8min ago
Docs: https://docs.mongodb.org/manual
Main PID: 17712 (mongod)
CGroup: /system.slice/mongod.service
└─17712 /usr/bin/mongod --quiet --auth --config /etc/mongod.conf
Nov 30 17:34:46 automationTaskV3 systemd[1]: Started High-performance, schema-free document-oriented database.
Nov 30 17:38:09 automationTaskV3 systemd[1]: Started High-performance, schema-free document-oriented database.
Nov 30 17:39:29 automationTaskV3 systemd[1]: Started High-performance, schema-free document-oriented database.
For the moment i'm trying to access without credentials.
Here my mongod.service file :
[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 --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
and here my mongod.conf file
# 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:
Is it possible that's a user right problem ? It seems strange as i follow the steps from thoses tutorials :
https://www.linode.com/docs/databases/mongodb/install-mongodb-on-ubuntu-16-04
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
As I said in the comment that its the IP binding issue. So you can even try this solution.
You can access the 27017 port of your remote machine by using ssh tunnelling as it is most the easiest way and it's also a secure way.
ssh -L 27017:localhost:27017 username#remoteaddress.com
This command says forward 27017 port of your local machine to address localhost:27017 of your remote machine.
You will be prompted for the password (of remote machine) if you don't have ssh keys set up. Now you might get prompt for ssh of your remote machine don't close it unless you want to close port forwarding, open a new tab of your terminal or Robomongo you can now connect to localhost:27017. So it's like MongoDB is installed on your local machine but actually, it is serving from the remote machine using ssh.
To know more about ssh tunneling read here : https://www.ssh.com/ssh/tunneling

Can't start MongoDB on CentOS7

I have a CentOS 7 empty VM.
> hostnamectl
...
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.18.26-guest-4-4751b4a-x86_64
Architecture: x86_64
I've installed MongoDB.
> mongod --version
db version v3.0.11
git version: 48f8b49dc30cc2485c6c1f3db31b723258fcbf39
The config file:
> cat /etc/mongod.conf
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /mongo/logs #/var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /mongo/data # (default) /var/lib/mongo
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
When I try to start I get this error:
> service mongod start
Starting mongod (via systemctl): Job for mongod.service failed. See 'systemctl status mongod.service' and 'journalctl -xn' for details
and:
> journalctl -xn
-- Subject: Unit mongod.service has begun with start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mongod.service has begun starting up.
avril 02 14:03:06 keystone runuser[30886]: pam_unix(runuser:session): session opened for user mongod by (uid=0)
avril 02 14:03:06 keystone runuser[30886]: pam_unix(runuser:session): session closed for user mongod
avril 02 14:03:06 keystone mongod[30879]: Starting mongod: [FAILED]
avril 02 14:03:06 keystone systemd[1]: mongod.service: control process exited, code=exited status=1
avril 02 14:03:06 keystone systemd[1]: Failed to start SYSV: Mongo is a scalable, document-oriented database..
-- Subject: Unit mongod.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mongod.service has failed.
--
-- The result is failed.
avril 02 14:03:06 keystone systemd[1]: Unit mongod.service entered failed state.
Has anyone encountered the issue "Failed to start SYSV"?
Any help or hint is welcome.
Thanks, Paul
The root issue is selinux permissions, which is enabled by default in CentOS 7. This can be fixed by disabling selinux or adding the correct context to the mongo database path:
chcon -R -t mongod_var_lib_t /var/lib/mongod