MongoDB not starting in Ubuntu 16.04 after turning on Authorization - mongodb

I was trying to add password to my mongodb but after changing authorization to enabled but mongodb doesn't start after that while trying with sudo service mongod start. I followed this tutorial to do the same. I even turned my firewall off. The result of sudo service mongod status is as follows:
● mongod.service - High-performance, schema-free document-oriented database
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2018-10-03 16:56:31 IST; 1s ago
Docs: https://docs.mongodb.org/manual
Process: 17641 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=2) Main PID: 17641 (code=exited, status=2)
Oct 03 16:56:31 dev-76 systemd[1]: Started High-performance, schema-free document-oriented database.
Oct 03 16:56:31 dev-76 systemd[1]: mongod.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Oct 03 16:56:31 dev-76 systemd[1]: mongod.service: Unit entered failed state.
Oct 03 16:56:31 dev-76 systemd[1]: mongod.service: Failed with result 'exit-code'.
ANd if i try to login then i get the following:
sam#dev-76:/etc$ mongo -u admin -p mongoadmin admin
MongoDB shell version v3.6.8
connecting to: mongodb://127.0.0.1:27017/admin
2018-10-03T17:06:09.418+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2018-10-03T17:06:09.418+0530 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:251:13
#(connect):1:6
exception: connect failed
UPDATE
My mongod.conf is as follows:
# 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:

I forgot to uncomment the line
#security:
authorization: enabled
After uncommenting the line it works,
security:
authorization: enabled
Also to use mongodb for persistence from my application i changed my uri like below,
mongodb://username:password#localhost:27017/mycollection?authSource=admin&authMechanism=SCRAM-SHA-1

Related

Mongod Active: Failed (code=exited, status=217/USER)

I am using ubuntu16.04 on VPS.
It has been migrated to another company's VPS and is in use.
nginix works fine and my node application works fine.
When the mongodb service is run as systemlctl stat
The following error code was shown and it became Active:Failed.
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2022-03-18 08:57:04 UTC; 3s ago
Docs: https://docs.mongodb.org/manual
Process: 3558 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=217/USER)
Main PID: 3558 (code=exited, status=217/USER)
Mar 18 08:57:04 user systemd[1]: Started MongoDB Database Server.
Mar 18 08:57:04 user systemd[1]: mongod.service: Main process exited, code=exited, status=217/USER
Mar 18 08:57:04 user systemd[1]: mongod.service: Unit entered failed state.
Mar 18 08:57:04 user systemd[1]: mongod.service: Failed with result 'exit-code'.
Below is my mongod.conf setting.
# 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:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:
In my system
mongod.conf Path
/etc/mongod.conf
mongodb DB path
/var/lib/mongodb
I'd appreciate it if you could let me know what I need to check.
The problem is probably with the account mongo is trying to launch with in your systemd mongod.service file. Check the user and group defined in the [Service] block are valid.

Error when configuring TLS/SSL for Mongodb

I have an existing MongoDB Instance on my server. I wanted to enable SSH for it. I edited the /etc/mongod.conf as follows and added the TLS Options
# 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:
# 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
tls:
mode: requireTLS
certificateKeyFile: /path/to/privatekey.pem
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
#security:
security:
authorization: enabled
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:
Whenever I try to restart MongoDB by running sudo service mongod restart I face the following error:
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2021-12-24 04:32:58 IST; 2s ago
Docs: https://docs.mongodb.org/manual
Process: 72902 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=1/FAILURE) Main PID: 72902 (code=exited,
status=1/FAILURE)
Dec 24 04:32:58 tcp-server-1 systemd[1]: Started MongoDB Database
Server. Dec 24 04:32:58 tcp-server-1 systemd[1]: mongod.service: Main
process exited, code=exited, status=1/FAILURE Dec 24 04:32:58
tcp-server-1 systemd[1]: mongod.service: Failed with result
'exit-code'.
But if I comment out the TLS Options, then its working fine. What am I doing wrong?

Mongod Service exit code 2

My Problem
Hi there! When I tried to start and see status I've got an error.
skozurak#danny:~$ service mongod start
skozurak#danny:~$ service mongod status
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2020-07-14 17:54:33 CEST; 3s ago
Docs: https://docs.mongodb.org/manual
Process: 77503 ExecStart=/usr/bin/mongod --auth --config /etc/mongod.conf (code=exited, status=2)
Main PID: 77503 (code=exited, status=2)
Jul 14 17:54:33 danny systemd[1]: Started MongoDB Database Server.
Jul 14 17:54:33 danny mongod[77503]: Error parsing YAML config file: yaml-cpp: error at line 32, col>
Jul 14 17:54:33 danny mongod[77503]: try '/usr/bin/mongod --help' for more information
Jul 14 17:54:33 danny systemd[1]: mongod.service: Main process exited, code=exited, status=2/INVALID>
Jul 14 17:54:33 danny systemd[1]: mongod.service: Failed with result 'exit-code'.
lines 1-12/12 (END)
What I did
Tried to reinstall
Tried to install different versions
Then I added the service to be able to run on server startup.
skozurak#danny:~$ systemctl enable mongod.service
I think that problem is in the config file. But I do not know how to fix it there.
skozurak#danny:~$ sudo nano /etc/mongod.conf
# mongod.conf
# 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:
I just changed one line of config as I saw here
skozurak#danny:~$ sudo nano /lib/systemd/system/mongod.service
[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network.target
[Service]
User=mongodb
Group=mongodb
EnvironmentFile=-/etc/default/mongod
ExecStart=/usr/bin/mongod --auth --config /etc/mongod.conf #i changed this line
PIDFile=/var/run/mongodb/mongod.pid
# 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 mongod as specified in
# http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings
[Install]
WantedBy=multi-user.target
Your error lies here:
security:
authorization: enabled
You can't use any other indentation than exactly 2 spaces.

Failure with start mongod.service on Ubuntu

I try to start service with mongo and get an error:
* mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2019-04-12 12:55:29 MSK; 9s ago
Docs: https://docs.mongodb.org/manual
Process: 15162 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=1/FAILURE)
Main PID: 15162 (code=exited, status=1/FAILURE)
Apr 12 12:55:29 mx systemd[1]: Started MongoDB Database Server.
Apr 12 12:55:29 mx systemd[1]: mongod.service: Main process exited, code=exited, status=1/FAILURE
Apr 12 12:55:29 mx systemd[1]: mongod.service: Failed with result 'exit-code'.
If I start mongod by manual, all works good.
mongod.service:
[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
mongod.config:
# 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
I've set permissions for /var/lib/mongodb and /var/log/mongodb/mongod.log
chown mongodb:mongodb /var/lib/mongodb -R
chown mongodb:mongodb /var/log/mongodb/mongod.log -R
What's wrong? What should I do? Any ideas?
I've solved my porblem. The solution is very simple, but I had a lot of headace.
Free disk space. I have no anought free disk space in my server. Thats it!
I hope this will be helpfull for anybody...

Mongodb version 3.6.2 can't restart after authentication enabled

I have installed MongoDB 3.6.2 on a server with Ubuntu Server 16.04.
After installation all works fine. Now i need to enable auth on MongoDB and I have seen the guide and i have set my mongod.conf whit securety: authentication: enabled, this my 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
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
securety:
authorization: enabled
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:
Now, I'm trying to restart MongoDB with sudo systemtcl restart but when I run status command the MongoDB status is failed and receive this error:
mongod.service - High-performance, schema-free document-oriented database
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: e
Active: failed (Result: exit-code) since gio 2018-01-25 13:02:23 CET; 2s ago
Docs: https://docs.mongodb.org/manual
Process: 1409 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited
Main PID: 1409 (code=exited, status=2
If I comment the security mode the status comeback to active.
Use
security:
authorization: enabled
instead of
securety:
authorization: enabled