MongoDB Compilation Installation

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

Installing MongoDB
1. Download

Latest: Https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.6.4.tgz

wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.8.tgz

mkdir Usr/local/mongodb

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 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 auto-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 the ability to assign roles and users, but there is no flaw  
Root This is super Administrator  
ReadWrite has read and write permission  

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

Use admin//Switch to admin database

db.createuser ( 

User: "root",  
pwd: "llh2018",  
Roles:[{role: "Root", DB: " Admin "}] 

);

db.createuser ( 

User: "Mongoroot",  
pwd: "llh2018",  
Roles:[{role: " Useradminanydatabase ", DB:" admin "}] 

);  
verify where to go to the DB where the user is registered:  
Db.auth (" Mongoroot "," testMongoDB2016 ")  
You can then use this Mongoroot account to create a database management account:  
Db.createuser ({User:" Llh ", pwd: "llh2018", roles:[{"role": "ReadWrite", "db": "Admin"}]})

Exit Mongod service first

use admin 
Db.auth ("root", "testMongoDB2016")  
Db.shutdownserver ()  
and open mongod without authentication  
use admin 
Db.dropuser ("Lelaohui")  
Db.system.version.update ({"_id": "Authschema"},{$ set:{"CurrentVersion": 3})  
Db.createuser ({User: "Lelaohui", pwd: "123456", roles:[{"role": "ReadWrite", "db ":" Admin "}]})  
to start MongoDB again as authentication

needs to be executed 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 Compilation Installation

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.