Ii. mongodb cluster in Windows 7

Source: Internet
Author: User
Tags key string
1. The three mongoReplicaSets nodes deploy data replication between the master and slave nodes. Unlike the shard nodes, the cluster can continue to work after one node is lost. Ii. file configuration: Go to the mongo official website to download the latest mongo. Copy three copies, named mongob_1, mongodb_2, mongodb_3 mongo__1.bat, mongo _

I. mongo Replica Sets three nodes are deployed to copy data between the master and slave nodes. Different from the sharding, after one node is lost, other nodes can continue to work. Ii. file configuration: Go to the mongo official website to download the latest mongo. Copy three copies, named mongob_1, mongodb_2, mongodb_3 mongo__1.bat, mongo _

I. mongo Replica Sets three nodes are deployed to copy data between the master and slave nodes. Different from the sharding, after one node is lost, other nodes can continue to work.

Ii. File Configuration

For example:

Go to the mongo official website to download the latest mongo. Copy the three copies and name them mongob_1, mongodb_2, and mongodb_3 respectively. The contents of mongo_1.bat, mongo_2.bat, and mongo_3.bat are as follows: Mongodb_1 \ bin \ mongod -- replSet rs1 -- keyFile data \ key \ r0 -- port 4001 -- dbpath data \ r0 -- logpath = data \ log \ r0.log -- logappend mongodb_2 \ bin \ mongod -- replSet rs1 -- keyFile data \ key \ r1 -- port 4002 -- dbpath data \ r1 -- logpath = data \ log \ r1.log -- logappend mongodb_3 \ bin \ mongod -- replSet rs1 -- keyFile data \ key \ r2 -- port 4003 -- dbpath data \ data/r2 -- logpath = data \ log \ r2.log -- logappend different colors distinguish different filesCreate a data folder and create data, key, and log files in the data folder. Create r0, r1, and r2 files in the key folder respectively, and write the same key string to the file. Click mongo_1.bat, mongo_2.bat, and mongo_3.bat respectively to start mongo.

Iii. Configuration Service

1. Connect to port 4001 and configure members

2. initialize the configuration

3. The cluster has been completed. log on to 4001 again and insert data.

4. In the synchronized Vue, we can see that all three nodes have the data just inserted.

5. view the cluster status. Health: 1 indicates normal, 0 indicates exception. PRIMARY indicates the master database


6. view the cluster status in addition. The cluster IP address and other information are displayed.

7. You can view the Master/Slave operation logs of the cluster. Ts indicates the timestamp, op indicates the operation, ns indicates the collection name, and o indicates the data.

8. View operation log information

9. Check the slave Database Synchronization status and synchronize the world at last.

10. view the node information of the entire cluster

3. add or delete nodes in cluster management

Add nodes through rs. add ('IP: port ')

2. read/write splitting

Execute db. getMongo (). setSlaveOk () to enable the slave database to have the READ function. This allows the Master/Slave read/write splitting.

3. failover when we stop the master database, the status of the query is found to be 4002 changed to the master database

4. Restore to slave database. When 4001 mongo is re-enabled, the original master database is now changed to slave database.


5. Copy the node data and deploy a new node to quickly add nodes. Use -- fastsync to start the node and add nodes using rs. add.

The added pai_5.bat content is as follows:

Mongodb_5 \ bin \ mongod -- replSet rs1 -- keyFile data \ key \ r4 -- port 4005 -- dbpath data/r4 -- logpath = data \ log \ r4.log -- logappend -- fastsync

6. Use rs. remove ("ip: port") to remove the node. Check the cluster status again and find that the node has been removed.


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.