MongoDB High Availability Cluster build (3.4)

Source: Internet
Author: User

I. Overview of the Architecture
192.168.56.101
192.168.56.102
192.168.56.103
OS for CentOS 7.2

Architecture diagram:

Plan the port number for the 5 components, because each machine needs to deploy MONGOs, config server, shard1, Shard2, shard3 at the same time, so the ports need to be differentiated.
The port can be freely defined, MONGOs in this schema is 20000, config server is 21000, Shard1 is 22001, Shard2 is 22002, Shard3 is 22003.

Second, create the appropriate directory

-p/data/mongodb/mongos/-p/data/mongodb/config/-p/data/mongodb/config/-p/data/ mongodb/shard1/-p/data/mongodb/shard1/-p/data/mongodb/shard2/-p/data/mongodb/shard2 /-p/data/mongodb/shard3/-p/data/mongodb/shard3/log

Third, config server configuration

cd/data/mongodb/Config[[email protected] config1]$ VI mongo.confdbpath=/data/mongodb/config/data/LogPath=/data/mongodb/config/log/Config.loglogappend=truePort=21000Fork=trueRest=trueHttpinterface=trueConfigsvr=trueReplset=Cfgreplset/app/mongo/bin/mongod-f/data/mongodb/config/mongo.conf Connect to any configuration server/app/mongo/bin/mongo--host192.168.56.101--port21000Create a configuration server replica set rs.initiate ({_id:"Cfgreplset", Configsvr:true, members:[{_id:0, Host:"192.168.56.101:21000"},{_ID:1, Host:"192.168.56.102:21000"},{_ID:2, Host:"192.168.56.103:21000"}]})

Iv. Shard Server Configuration

cd/data/mongodb/Shard1[[email protected] share_rs1]$ VI mongo.confdbpath=/data/mongodb/shard1/Datalogpath=/data/mongodb/shard1/log/Shard1.loglogappend=truePort=22001Fork=trueRest=trueHttpinterface=trueReplset=Shard1replsetshardsvr=true/app/mongo/bin/mongod-f/data/mongodb/shard1/mongo.conf--nojournal connecting any single shard server/app/mongo/bin/mongo--host192.168.56.101--port22001Create a replica set and initialize Rs.initiate ({_id:"Shard1replset", members:[{_id:0, Host:"192.168.56.101:22001"},{_ID:1, Host:"192.168.56.102:22001"},{_ID:2, Host:"192.168.56.103:22001"}]})

Configure Shard Server 2,shard server 3 in the same way

Five, MONGOs configuration

 cd/data/mongodb/mongos[[email protected] mongs1]$ vi mongo.conf logpath  =/data/mongodb/mongos/log/mongos.loglogappend  =true  port  =20000  fork  =true   ConfigDB  =cfgreplset/192.168 . 56.101 : 21000 , 192.168 . 56.102 : 21000 , 192.168 . 56.103 : 21000 /app/mongo/bin/mongos-f/ data/mongodb/mongos/mongo.conf  

Vi. adding shards to a cluster

Log on to the Routing service client/app/mongo/bin/mongo--host 192.168.56.101--port 20000 add shard to cluster Sh.addshard ("shard1replset/ 192.168.56.101:22001,192.168.56.102:22001,192.168.56.103:22001 ") Add Shard2  shard3sh.addshard (" Shard2replset/192.168.56.101:22002,192.168.56.102:22002,192.168.56.103:22002 ") Sh.addShard (" shard3ReplSet/ 192.168.56.101:22003,192.168.56.102:22003,192.168.56.103:22003 ")--enable sharding for a Databasesh.enableSharding ( "Test")--shard a collectionsh.shardcollection ("Test.testdoc", {id:1})

Seven, testing

192.168. 56.102 20000 inserting test data mongos> use test  for (var1100000; i++) {  Db.testdoc.save ({id:i,"message  ":"message"+I}";} MONGOs> Db.testdoc.status ()

 

MongoDB High Availability Cluster build (3.4)

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.