MongoDB Series One: CentOS7.2 under Installation mongoDB3.2.8

Source: Internet
Author: User
Tags auth mongodb version account security

Recently in the Daoteng MongoDB, the installation configuration of the relevant commands to paste out
1. Download
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.8.tgz

2. Decompression
Tar zxvf mongodb-linux-x86_64-rhel70-3.2.8.tgz
MV mongodb-linux-x86_64-rhel70-3.2.8/usr/local/
MV mongodb-linux-x86_64-rhel70-3.2.8 MongoDB
CD mongodb/

mkdir DB
mkdir logs
CD bin/
3. Edit the configuration file:
Vim mongodb.conf
Enter the following:
dbpath=/usr/local/mongodb/db
Logpath=/usr/local/mongodb/logs/mongodb.log
bind_ip=0.0.0.0
port=27017
Fork=true
Nohttpinterface=true

4. Create a new account:
Groupadd MongoDB
Useradd mongodb-g MongoDB
Cd.. /.. /
Chown-r Mongodb:mongodb MongoDB

5. Start:
/usr/local/mongodb/bin/mongod-f/usr/local/mongodb/bin/mongodb.conf

6. Set boot automatically start MongoDB
Vi/etc/rc.d/rc.local
/usr/local/mongodb/bin/mongod–config/usr/local/mongodb/bin/mongodb.conf

To enter MongoDB Shell mode:
/usr/local/mongodb/bin/mongo
To view a list of databases:
Show DBS
To view the current DB version:
Db.version ();

7. Increase Administrator Privileges:

Useradminanydatabase This role has permissions to assign roles and users, but there are no bugs to check
Root, this is super admin.
ReadWrite have read and write access
Read access

Enter Shell mode:
/usr/local/mongodb/bin/mongo

Use admin//Switch to admin database

Db.createuser (
{
User: "Root",
PWD: "testMongoDB2016",
Roles:[{role: "Root", DB: "admin"}]
}
);

Db.createuser (
{
User: "Mongoroot",
PWD: "testMongoDB2016",
Roles:[{role: "Useradminanydatabase", DB: "admin"}]
}
);
Verify where you are registering the user to which DB is certified:
Db.auth ("Mongoroot", "testMongoDB2016")
You can then use this Mongoroot account to create a database management account:
Db.createuser ({User: "hhq163", pwd: "test123456", roles:[{"role": "ReadWrite", "db": "Admin"}]})

However, it is found that the added account cannot log on at the client because the MongoDB version is wrong:
Exit Mongod Service First

Use admin
Db.auth ("root", "testMongoDB2016")
Db.shutdownserver ()
And then open Mongod in the absence of authentication
Use admin
Db.dropuser ("hhq163")
Db.system.version.update ({"_id": "Authschema"},{$set: {"CurrentVersion": 3}})
Db.createuser ({User: "hhq163", pwd: "test123456", roles:[{"role": "ReadWrite", "db": "Admin"}]})
Then start MongoDB in the form of authentication

If you need to create an account for a new db:
Need to execute under the shell:
Use TestDB
Db.createuser ({User: "hhq163", pwd: "test123456", roles:[{"role": "ReadWrite", "db": "TestDB"}]})

Vim/usr/local/mongodb/bin/mongodb.conf
Add the following line at the end of the file:
Auth=true

8. Close the database server:
Use admin
Db.shutdownserver ()

If the account security certification, you must first certification:
Use admin
Db.auth ("root", "testMongoDB2016")
Db.shutdownserver ()

MongoDB Series One: CentOS7.2 under Installation mongoDB3.2.8

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.