MongoDB installation (stand-alone, replica set, fragmentation)

Source: Internet
Author: User
Tags mkdir mongodb

One. Stand-alone deployment startup

1. Directly download the relevant Mongodb_linux installation package, to the Linux environment, decompression can be.

2. Start MongoDB
/data/program/mongo/mongodb-linux-x86_64-2.6.6/bin/mongod--port 8050--fork--dbpath=/data/program/mongo/data/-- Logpath=/data/program/mongo/log/mongodb.log--logappend

./mongod--port 27017--fork--dbpath=/home/wuly/mongo/data/--logpath=/home/wuly/mongo/log/mongodb.log--logappend

3./mongo--port=8050
Client-side queries for this port

=================================================================================================

Two. How the replica set is deployed to start

Replica Set

The Chinese translation is called the replica set, but I do not like to translate English into Chinese, always feel strange. In fact, it is simple to say that the cluster contains a number of data to ensure that the main node is hung up, the standby node can continue to provide data services, provided that the premise is that the data need to be consistent with the main node. The following figure:

Mongodb (M) represents the master node, Mongodb (S) represents the standby node, and Mongodb (A) represents the quorum node. The primary standby node stores the data, and the quorum node does not store the data. The client connects the master and Standby nodes at the same time and does not connect to the quorum node.

By default, the main node provides all additions and deletions to the service, the standby node does not provide any services. However, by setting up the standby node to provide the query service, this can reduce the pressure on the primary node, when the client makes a data query, the request automatically go to the standby node. This setting is called Read Preference Modes, and the Java client provides a simple way to configure the database without having to operate directly on it.

The quorum node is a special node that itself does not store data, and the primary role is to determine which standby node is promoted as the primary node after the main node has been hung, so the client does not need to connect to this node. Although there is only one standby node here, a quorum node is still required to raise the standby node level. I did not believe that there must be a quorum node, but I also tried without the quorum node, the main node hangs a standby or a standby node, so we still need it.

After introducing the cluster scheme, it is now starting to build.


1. Create a Data folder

In general, the data directory will not be based on the MongoDB of the extract directory, but here is convenient, built in MongoDB decompression directory.

[plain] view plain copy mkdir-p/mongodb/data/master mkdir-p/mongodb/data/slaver mkdir-p /arbiter #三个目录分别对应主, Standby, quorum node

2. Create a configuration file

Because the configuration is more, we write the configuration to the file.

[Plain]View plain copy #master. conf dbpath=/mongodb/data/master logpath=/mongodb/log/master.log Pidfilepath=/mongodb/master . PID directoryperdb=true logappend=true replset=testrs bind_ip=10.10.148.130 port=27017 oplogSize=10000 =true Noprealloc=true[Plain]View plain copy #slaver. conf dbpath=/mongodb/data/slaver logpath=/mongodb/log/slaver.log Pidfilepath=/mongodb/slaver . PID directoryperdb=true logappend=true replset=testrs bind_ip=10.10.148.131 port=27017 oplogSize=10000 =true Noprealloc=true[Plain]View plain copy #arbiter. conf dbpath=/mongodb/data/arbiter logpath=/mongodb/log/arbiter.log Pidfilepath=/mongodb/arb   Iter.pid directoryperdb=true logappend=true replset=testrs bind_ip=10.10.148.132 port=27017 Fork=true noprealloc=true Parameter Explanation:

DBPath: Data Storage Directory

LogPath: Log Storage path

Pidfilepath: Process file, easy to stop MongoDB

Directoryperdb: Create a folder for each database by database name

Logappend: Logging in an append way

Replset:replica Set's name

The IP address to which the Bind_ip:mongodb is bound

Port:mongodb the port number used by the process, defaults to 27017

Oplogsize:mongodb the maximum size of the action log file. MB, defaults to 5% of the hard disk space left

Fork: Run the process in a later way

Noprealloc: Do not allocate storage beforehand


3. Start MongoDB

Enter the bin directory for each MongoDB node

[Java] view plain copy./monood-f master.conf./mongod-f slaver.conf./mongod-f arbiter.conf

Note that the path to the configuration file must be guaranteed to be correct, either as a relative path or as an absolute path.


4. Configure the Master, standby, and quorum node

You can connect MongoDB through a client, or you can select a connection MongoDB directly in three nodes.

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.