Comments on How to Install and Configure MongoDB on CentOS 7

MongoDB is a NoSQL database that provides high performance, high availability, and automatic scaling. In this tutorial, I will guide you to install and configure MongoDB 3.2 (stable) on a CentOS 7 server. We will add and configure the administrator user for MongoDB and configure the authentication for MongoDB services.

9 Comment(s)

Add comment

Please register in our forum first to comment.

Comments

By: Tom

Thanks, whoever you are!  Everything worked exactly as indicated on this web page.  This is probably the first time I have run through CentOS 7 product install instructions where every single command worked exactly as shown, with no trouble at all.

By: aorosar

Changing the limit values in limits.conf didn't work for me, I had to change it in the init script:

I had to add this line and then restart the service:

LimitNPROC=32000

 

By: Longuè

very nice thanks !! It's working as expected

By: suresh kumar

Superb article. thanks a lot

By: suyash

A document should have commands that can give more exact output. Like

netstat -plntu could have changed by netstat -plntu | grep 27017 for better output.

By: sanjeev patro

Thanks for sharing this valueble information. I want you to add one more step after before dbcreateusers

1> service stop mongodb

2> mongod --config /etc/mongod.conf# mongod --config /etc/mongod.confabout to fork child process, waiting until server is ready for connections.forked process: 31134child process started successfully, parent exiting

 

3> then execute mongo

#mongoMongoDB shell version: 3.2.22connecting to: testServer has startup warnings:2019-11-27T04:23:52.747+0000 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.2019-11-27T04:23:52.747+0000 I CONTROL  [initandlisten]2019-11-27T04:23:52.748+0000 I CONTROL  [initandlisten]2019-11-27T04:23:52.748+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.2019-11-27T04:23:52.748+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'2019-11-27T04:23:52.748+0000 I CONTROL  [initandlisten]2019-11-27T04:23:52.748+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.2019-11-27T04:23:52.748+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'2019-11-27T04:23:52.748+0000 I CONTROL  [initandlisten]> db.createUser(...   {...     user: "admin",...     pwd: "admin123",...     roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]...   }... )Successfully added user: {        "user" : "admin",        "roles" : [                {                        "role" : "userAdminAnyDatabase",                        "db" : "admin"                }        ]}> show users{        "_id" : "test.admin",        "user" : "admin",        "db" : "test",        "roles" : [                {                        "role" : "userAdminAnyDatabase",                        "db" : "admin"                }        ]}

The reason why i recommend this tep is if we try to execute "db.createUser" immdiately after installing mongodb and starting the service I faced this issue

2019-11-27T02:05:09.927+0000 E QUERY    [thread1] Error: couldn't add user: not authorized on admin to execute command { createUser: "admin", pwd: "xxx", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ], digestPassword: false, writeConcern: { w: "majority", wtimeout: 60000.0 } } :_getErrorWithCode@src/mongo/shell/utils.js:25:13DB.prototype.createUser@src/mongo/shell/db.js:1267:15@(shell):1:1

 

By: kunal

i have installed mongodb on server,it was running successfully,but form last few days after typing mongo on server,not able to connect and error is

connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb

2020-03-11T10:10:41.529+0330 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

By: igpf

yeah... force once a how-to that works line for line.  thank you. very nice.

By: Oguzhan

Hi man,

Thanks for great tutorial!