1. Download the mongodb installation package mongodb-linux-x86_64-rhel70-4.2.7.tgz

2. Decompress the mongodb package

The tar ZXVF mongo - Linux - x86_64 - rhel70-4.2.7. TGZCopy the code

3. Rename the decompressed package to mongodb and move it to /usr/local. The current mongodb path is /usr/local/mongodb/bin

Chmod -r 777 bin Chmod -r 777 bin chmod -r 777 binCopy the code

4. Add a mongodb. Conf configuration file to /usr/local/mongodb

/usr/local/mongodb/mongodb.confCopy the code

Add a new data folder to /usr/local/mongodb

/usr/local/mongodb/data
Copy the code

Add a db folder and logs folder to /usr/local/mongodb/data

/usr/local/mongodb/data/db
/usr/local/mongodb/data/logs
Copy the code

7, in/usr/local/mongo/data/logs under increased a directing a new log file

/usr/local/mongodb/data/logs/mongodb.log
Copy the code

8. Edit the mongodb

# port
port = 27017
# Data directory
dbpath = /usr/local/mongodb/data/db
# log directory
logpath = /usr/local/mongodb/data/logs/mongodb.log
# Set up background run
fork = true
Log output mode
logappend = true
# enable authentication
#auth = true
User all IP accessBind_ip = 0.0.0.0Copy the code

9. Start the mongodb service and run the /usr/local/mongodb/bin command

./mongod --config /usr/local/mongodb/mongodb.conf
Copy the code

10. At this point, mongodb is started

Netstat ano | grep 27017 (just configure port)Copy the code

/usr/local/mongodb/bin /mongo

>use admin
>db.createUser({user:"admin".pwd:"admin@123",roles:[{role:"root",db:"admin"}]})
>show users
# verify user
>db.auth('admin'.'admin@123') Output 1 represents successList all databases
>show dbs
Copy the code