MongoDB installation (compare all points)

Source: Internet
Author: User
Tags auth mongodb download mongodb server mongo shell

Go: https://www.cnblogs.com/pfnie/articles/6759105.html. Create a MongoDB installation path

Create a folder in/usr/local/MongoDB

mkdir MongoDB

Second, upload files to the/usr/local/source directory on Linux

1. I first download MongoDB download the corresponding version in MongoDB download path.

2. Upload the installation package to the Linux machine via the FTP tool.

Third, unzip the file

1. Go to the/usr/local/source directory:

Cd/usr/local/source

2. Run the following command: TAR-ZXVF mongodb-linux-i686-3.2.13-rc0.gz-c/usr/local/mongodb

2. Renaming

Iv. Creating a configuration file

1. Create a database folder

Cd/usr/local/mongodb/mongodbserver

mkdir data

2. Create a log folder

Cd/usr/local/mongodb/mongodbserver

mkdir Log

3. Create a configuration folder and configuration file

3.1 Creating a configuration folder etc

Cd/usr/local/mongodb/mongodbserver

mkdir etc

3.2 Creating a configuration file mongodb.conf

Cd/usr/local/mongodb/mongodbserver/etc

Vim mongodb.conf

dbpath=/usr/local/mongodb/mongodbserver/datalogpath=/usr/local/mongodb/mongodbserver/logs/mongodb.logport= 27017fork=true
Journal=falsestorageengine=mmapv1
V. Start MongoDB

1. MongoDB installed after the first entry is not required password, and no user, through the shell command can directly enter, CD to the MongoDB directory under the Bin folder, execute the command./mongo, as shown below:

./mongod--config/usr/local/mongodb/mongodbserver/etc/mongodb.conf

After successful startup, visit http://npfdev1:27017/and you can see:

2, add Admin user (MongoDB no invincible user root, only can manage user's user useradminanydatabase)

Use the MONGO command to connect to the MongoDB server side:

> Use admin
Switched to DB admin
> Db.createuser ({User: "Pfnieadmin", pwd: "123456", roles: [{role: "Useradminanydatabase", DB: "Admin"}]});

After success, you will see:

Note: You can use Show users or db.system.users.find () to view an existing user after you have finished adding users.

3, after adding Admin user, close MongoDB, and use permission mode to open MongoDB again, here note do not use kill directly to kill the MongoDB process, (if so, please go to data/ DB directory to delete the Mongo.lock file), you can use Db.shutdownserver () to close it.

4. Use permission mode to start MongoDB

In the configuration file, add: Auth=true, and then start:

5, enter the MONGO shell, use the admin database and verify, if not verified, can not do any operation. > Use admin> db.auth ("Pfnieadmin", "123456") #认证, return 1 for Success six, add Mongod path to system path, easy to execute mongod command anywhere

1. In the/etc/profile file, add export path= $PATH:/usr/local/mongodb/mongodbserver/bin

2. Execute source/etc/profile to make system environment variables effective immediately

Seven, the MONGO path soft chain to the/usr/bin path, easy to execute MONGO command anywhere

1. Execution command: Ln-s/usr/local/mongodb/mongodbserver/bin/mongo/usr/bin/mongo

Viii. test whether it is convenient to execute MONGO commands anywhere

1. Go back to any path, execute the MONGO command, connect the Mongod service

2. Close Mongod Service, execute Db.shutdownserver ()

2017-04-20t18:32:26.865+0800 E QUERY [Thread1] Error:shutdownserver failed: {
"OK": 0,
"ErrMsg": "Not authorized in Admin to execute command {shutdown:1.0}",
"Code": 13
} :
[Email protected]/mongo/shell/utils.js:25:13
[Email protected]/mongo/shell/db.js:302:1
@ (Shell): 1:1

Workaround, execute the following statement to add permissions:

Db.updateuser ("Pfnieadmin",        {           roles: [                     {"Role": "Useradminanydatabase", "db": "Admin"},                     {"Role": " Dbowner "," db ":" Admin "},
{"Role": "Clusteradmin", "db": "admin"} ] } )

Then execute the db.shutdownserver ().

or execute the following command to close:

Killall Mongod

3. Start the Mongod service

Mongod--config/usr/local/mongodb/mongodbserver/etc/mongodb.conf

Nine, MongoDB set to system service and set boot boot

1. Through the simple operation above, we have the MongoDB configuration file configuration completed, then we will set up the system service MongoDB.
2. First add the MongoDB system service, the command is as follows: Vim/etc/rc.d/init.d/mongod
3. After opening the editor, we paste the following configuration in and then save

Start () {  /usr/local/mongodb/mongodbserver/bin/mongod  --config/usr/local/mongodb/mongodbserver/etc/ MONGODB.CONF}    Stop () {  /usr/local/mongodb/mongodbserver/bin/mongod--config/usr/local/mongodb/ mongodbserver/etc/mongodb.conf--shutdown  } case  "$" in    start)   start   ;    Stop)   stop   ;;    Restart)   stop   start   ;;    *)   Echo  $ "Usage: $ Start|stop|restart}"   exit 1  

4. After the save is complete, add the script execution permission, the command is as follows: chmod +x/etc/rc.d/init.d/mongod
5. Start Mongodb,service Mongod start as shown, the start is successful:

6. You can use the command service Mongod stop to close the MongoDB service.
7. Verify that MongoDB is started, enter the command lsof-i: 27017, the monitoring port is already in use, so the boot has been completed.

MongoDB installation (compare all points)

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.