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