MongoDB installation, Master/Slave configuration, and Replica Set Configuration

Source: Internet
Author: User

I have been studying MongoDB for a while, read some books, and read a lot of information on the Internet. In fact, I copied and copied many of them, but they have not been verified by myself. I can post them to my blog, and then let me know what to do. At the very beginning, I was deeply affected by this, so it is not uncommon for people to follow these detours like me, I spent some time sorting out some of my practical operations and wrote this article.

The article is very simple, mainly about basic configuration. The key is to be careful when configuring the configuration. Here we do not talk about the principles. After all, the length is limited, so if you have any questions during the configuration process, you can contact me. I hope you can provide more support.

In addition, I am very busy at work, and it is not easy to write a post. I think it is useful to write a post. I would like to give a reply to express support, which also gives me some motivation.

I.MongodbInstallation

Environment:Linux 64bit

Version:2.0.1

Location:/Opt/mongodb

Installation steps:

Tar-zxvf mongodb-linux-x86_64-2.0.1.tar-C/opt/mongodb

Mkdir/opt/mongodb/data

Touch/opt/mongodb/logs

The installation is very simple. The key is the following STARTUP configuration. There are three boot configurations: normal single-host startup, master-slave startup, and replica set startup.

1.Single host Startup Mode

Start

Cd/opt/mongodb/bin

/Opt/mongodb/bin/mongod-f mongodb. conf

# Mongodb. confIs a custom STARTUP configuration file with ParametersAuthIndicates that you need to authenticate to log on. The content is as follows:

# Start as daemon and need authentication

Port = 27017

Fork = true

Dbpath =/opt/mongodb/data/

Logpath =/opt/mongodb/logs

Auth = true

 

Set automatic start upon startup(Optional)

Echo "/opt/mongodb/bin/mongod-f/opt/mongodb/bin/mongodb. conf">/etc/rc. local

Set Password

#ConnectionMongodb

Cd/opt/mongodb/bin

./Mongo

#By defaultMongodbDefaultTestLibrary

#Set user name and password for the database

#SwitchAdminLibrary, first create an Administrator Account

> Use admin

> Db. addUser ("root", "root ");

#SwitchTestLibrary

Use test

#IsTestAdd username and password to the database

> Db. addUser ("testUser", "123456 ");

#NOTE: If it is displayed at this time

Tue May 22 16:16:29 uncaught exception: error {

"$ Err": "unauthorized db: test lock type:-1 client: 127.0.0.1 ",

"Code": 10057

}

Indicates that the password setting has taken effect.AdminDatabase, input authentication, and then go backTestSet the username and password for the database as follows:

Use admin

Db. auth ("root", "root ");

Use test

#Connect again next timeMongodbUse the following method:

./Mongo-u testUser-p 123456

#Delete a user

Db. system. users. remove ({"user": "testUser "});

#Note:MongodbThe user name and password are for each database, so you can set different user names and passwords for different databases.

  • 1
  • 2
  • 3
  • Next Page

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.