Install MongoDB and configure ReplicaSet

Source: Internet
Author: User
Tags install mongodb
MongoDB environments mainly include StandAlone, Replication, and Sharding. Because of the data volume and machine volume, the project eventually uses a Primary and a Secondary

MongoDB environments mainly include StandAlone, Replication, and Sharding. Because of the data volume and machine volume, the project eventually uses a Primary and a Secondary

MongoDB environments mainly include StandAlone, Replication, and Sharding.

  • StandAlone: StandAlone environment, usually used for development and testing.
  • Replication: master-slave structure. One Primary and multiple Secondary may have Arbitry.
  • Sharding: share nothing structure. Each machine stores only a part of data. The mongod server stores data, and the mongos server routes read/write requests. Metadata is stored in the config database.
  • Because of the data volume and machine volume, the project eventually uses a Primary, a Secondary, and an Arbitry. My own development environment is Ubuntu and the test environment is CentOS. The 64-bit MongoDB is installed.

    Install on Ubuntu

    Sudo apt-get install mongodb-10gen

    Installation on CentOS

    Configure the yum source and create the file:/etc/yum. repos. d/mongodb. repo.

    [Mongodb] name = MongoDB Repositorybaseurl = http://downloads-distro.mongodb.org/repo/RedHat/ OS /x86_64/gpgcheck=0enabled=1

    Installation command:

    Yum install mongo-10gen mongo-10gen-server

    Configuration

    The configuration file/etc/initd. conf on each machine is changed to the following:

    # Database file location (default) dbpath =/var/lib/mongo # log location (default) logpath =/var/log/mongo/mongod. log # pid location (default) pidfilepath =/var/run/mongodb/mongod. pid # keyFile location. The generation method is later (ADD) keyFile =/var/lib/mongo/key # port (default) port = 27017 # logs are appended after each start, logappend = true # Start (ADD) in deamon mode fork = true # open operation logs for fault recovery and persistence (default) journal = true # replica set Name (ADD) replSet = test-set

    Run on each machine:

    Sudo cmdd-f/etc/cmdd. conf

    In my environment, Primary ip: 192.168.1.1, Secondary ip: 192.168.1.2, and Arbitary ip: 192.168.1.3. You can set multiple mongodb ports on a single machine. I have tested it.

    Run "mongo" on Primary, open the command line, and Set the Replica Set:

    Rs. initiate ({:,: [{:}, {:}, {::,: true}]}); {: "OK": 1}

    After the history is successful, wait for a while. He will elect Primary and then check the status of the Replica Set:

    Test-set: PRIMARY> rs. status () {: "test-set",: ISODate (),: 7,: [{: 1,:,: 1,: 1,:,: 4086 ,: timestamp (1392972480, 1),: ISODate (),: 0}, {: 2,:,: 1,: 2 ,:,: 3997,: Timestamp (1392972480, 1),: ISODate (),: 0, :}, {: 3 ,:,: 1,: 7,:,: 5781,: true}],: 1}

    In this way, the entire replica set is successfully configured, which is relatively simple.

    MongoDB details: click here
    MongoDB: click here

    Related reading:

    MongoDB backup and recovery

    CentOS compilation and installation of MongoDB

    CentOS compilation and installation of php extensions for MongoDB and mongoDB

    CentOS 6 install MongoDB and server configuration using yum

    Install MongoDB2.4.3 in Ubuntu 13.04

    How to create a new database and set in MongoDB

    MongoDB beginners must read (both concepts and practices)

    MongoDB authoritative Guide (The Definitive Guide) in English [PDF]

    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.