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.
Related
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.
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.
A few days ago I decided to use mongodb for a project. but I still don't make it work.
If I'm try to start mongodb with the following command:
sudo mongod --config=/etc/mongod.conf
This is the result:
about to fork child process, waiting until server is ready for connections.
forked process: 4539
child process started successfully, parent exiting
this is my mongod.conf:
# mongod.conf
systemLog:
path: "/var/log/mongodb/mongod.log"
destination: file
timeStampFormat: iso8601-utc
logAppend: true
logRotate: reopen
net:
bindIp: 127.0.0.1
port: 27017
wireObjectCheck: true
serviceExecutor: adaptive
storage:
dbPath: "/home/juny/nodeBox/data/db"
processManagement:
fork: true
pidFilePath: "/run/mongod.pid"
security:
authorization: enabled
operationProfiling:
mode: slowOp
If I try to start mongod as service, the terminal display this:
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2019-05-27 14:22:31 AST; 8s ago
Docs: https://docs.mongodb.org/manual
Process: 4861 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=1/FAILURE)
Main PID: 4861 (code=exited, status=1/FAILURE)
May 27 14:22:31 LAPTOP-CJFC94N systemd[1]: Started MongoDB Database Server.
May 27 14:22:31 mongod[4861]: about to fork child process, waiting until server is ready for connections.
May 27 14:22:31 mongod[4861]: forked process: 4863
May 27 14:22:31 systemd[1]: mongod.service: Main process exited, code=exited, status=1/FAILURE
May 27 14:22:31 systemd[1]: mongod.service: Unit entered failed state.
May 27 14:22:31 systemd[1]: mongod.service: Failed with result 'exit-code'.
And finally, this is a few lines on my log file:
2019-05-27T18:14:16.257Z I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
2019-05-27T18:14:16.437Z I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2019-05-27T18:14:16.437Z I CONTROL [initandlisten]
2019-05-27T18:14:16.437Z I CONTROL [initandlisten]
2019-05-27T18:14:16.437Z I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2019-05-27T18:14:16.437Z I CONTROL [initandlisten] ** We suggest setting it to 'never'
2019-05-27T18:14:16.437Z I CONTROL [initandlisten]
2019-05-27T18:14:16.530Z I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/home/juny/nodeBox/data/db/diagnostic.data'
2019-05-27T18:14:16.531Z I EXECUTOR [initandlisten] No thread count configured for executor. Using number of cores / 2: 2
2019-05-27T18:14:16.531Z I EXECUTOR [worker-1] Started new database worker thread 1
2019-05-27T18:14:16.531Z I EXECUTOR [worker-2] Started new database worker thread 2
2019-05-27T18:14:16.531Z I NETWORK [initandlisten] waiting for connections on port 27017
2019-05-27T18:28:02.535Z I NETWORK [listener] connection accepted from 127.0.0.1:48610 #1 (1 connection now open)
2019-05-27T18:28:02.535Z I NETWORK [conn1] Error receiving request from client: ProtocolError: Client sent an HTTP request over a native MongoDB connection. Ending connection from 127.0.0.1:48610 (connection id: 1)
2019-05-27T18:28:02.535Z I NETWORK [worker-2] end connection 127.0.0.1:48610 (0 connections now open)
2019-05-27T18:28:02.585Z I NETWORK [listener] connection accepted from 127.0.0.1:48612 #2 (1 connection now open)
2019-05-27T18:28:02.585Z I NETWORK [conn2] Error receiving request from client: ProtocolError: Client sent an HTTP request over a native MongoDB connection. Ending connection from 127.0.0.1:48612 (connection id: 2)
2019-05-27T18:28:02.585Z I NETWORK [worker-1] end connection 127.0.0.1:48612 (0 connections now open)
Ok Ok, it works if I type the following command: mongo
I have installed with the help of following link: https://www.digitalocean.com/community/tutorials/how-to-install-mongodb-on-ubuntu-16-04
It was working fine by default. But when I change data directory in /etc/mongod.conf
#From
dbPath: /var/lib/mongodb
#To
dbPath: /media/user/'Mounted Volume'/mongodb_data
I am unable to start MongoDB. Following is the error message
$mongo
MongoDB shell version: 3.2.11
connecting to: test
2017-01-06T00:57:01.472+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2017-01-06T00:57:01.472+0530 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:229:14
#(connect):1:6
exception: connect failed
Following is the status
$ sudo systemctl status mongodb
mongodb.service - High-performance, schema-free document-oriented database
Loaded: loaded (/etc/systemd/system/mongodb.service; enabled; vendor preset:
Active: failed (Result: exit-code) since Fri 2017-01-06 00:56:40 IST; 7s ago
Process: 5735 ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf (cod
Main PID: 5735 (code=exited, status=100)
Jan 06 00:56:40 GL552VW systemd[1]: Started High-performance, schema-free docume
Jan 06 00:56:40 GL552VW systemd[1]: mongodb.service: Main process exited, code=e
Jan 06 00:56:40 GL552VW systemd[1]: mongodb.service: Unit entered failed state.
Jan 06 00:56:40 GL552VW systemd[1]: mongodb.service: Failed with result 'exit-co
I am new to MongoDB. Maybe I am missing something very simple.
From the MongoDB config file documentation page
The Linux package init scripts included in the official MongoDB packages depend on specific values for systemLog.path, storage.dbpath, and processManagement.fork. If you modify these settings in the default configuration file, mongod may not start.
So if you modify these properties in the configuration file, you most probably have to write a new init script.
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