MongoDB Learning notes for sharding and replica sets mixed use

Source: Internet
Author: User
Tags snmp

Shard and replica set blending:

Basic Architecture Diagram:

Build detailed configuration:

3 x Shard + 3 Replicat set + 3 Configserver + 3 x MONGOs

Shardrsname

Primary

Secondary

Secondary

Port

Bigdata-sh-a

Bigdata-sh-a1

Bigdata-sh-a2

Bigdata-sh-a3

28111

Bigdata-sh-b

Bigdata-sh-b2

Bigdata-sh-b1

Bigdata-sh-b3

28112

Bigdata-sh-c

Bigdata-sh-c3

Bigdata-sh-c2

Bigdata-sh-c1

28113

Bigdata-cs

Configserver1

Configserver2

Configserver3

28200

Create the following folder in the MONGO root directory of the three Linux machines:

Log:

/usr/local/mongodb/logs/a1

/usr/local/mongodb/logs/b1

/usr/local/mongodb/logs/c1

/usr/local/mongodb/logs/configserver1

Db:

/usr/local/mongodb/db/a1

/usr/local/mongodb/db/b1

/usr/local/mongodb/db/c1

/usr/local/mongodb/db/configserver1

Bigdata-sh-a1.conf:

# Mongod Configsystemlog:  destination:file  logappend:true  Path:/usr/local/mongodb/logs/a1/ mongodb.log# Where and how to store Data.storage:  dbPath:/usr/local/mongodb/db/a1  Journal:    enabled:true#  engine:#  mmapv1:#  wiredtiger:# How the process runs# fork:fork and run in background# pidfilepath:location of Pidfile processmanagement:  fork:true  pidfilepath:/usr/local/mongodb/pidfile/mongod-a1.pid# Network interfaces# Listen to local interface only, comment to Listen on all interfaces.net:  port:28111  bindip:0.0.0.0 #security:  enabled  disabled#security:#  keyfile:/mongodb/keyfile#  clusterauthmode:keyfile# Operationprofiling:operationprofiling:   slowopthresholdms:1000   mode:slowop#replication:replication:  replsetname:bigdata-sh-a#sharding:sharding:  clusterrole:shardsvr## enterprise-only Options#auditLog:# Snmp:

Bigdata-sh-configserver1.conf:

# Mongod Configsystemlog:  destination:file  logappend:true  Path:/usr/local/mongodb/logs/configserver1 /mongodb.log# Where and how to store Data.storage:  dbPath:/usr/local/mongodb/db/configserver1  Journal:    enabled:true#  engine:#  mmapv1:#  wiredtiger:# How the process runs# fork:fork and run in background# pidfile Path:location of pidfileprocessmanagement:  fork:true  Pidfilepath:/usr/local/mongodb/pidfile/ mongod-configserver1.pid# network interfaces# Listen to local interface only, comment to Listen on all INTERFACES.NET:
   port:28200  bindip:0.0.0.0#security:  enabled  disabled#security:#  keyfile:/mongodb/keyfile #  clusterauthmode:keyfile#operationprofiling:operationprofiling:   slowopthresholdms:1000   mode: Slowop#replication:replication:  replsetname:bigdata-cs#sharding:sharding:  clusterrole:configsvr## Enterprise-only Options#auditlog: #snmp:

After the configuration is complete, start the service:

./mongod-f. /conf/bigdata-sh-a1.conf

./mongod-f. /conf/bigdata-sh-b1.conf

./mongod-f. /conf/bigdata-sh-c1.conf

./mongod-f. /conf/bigdata-sh-configserver1.conf

./mongod-f. /conf/bigdata-sh-a2.conf

./mongod-f. /conf/bigdata-sh-b2.conf

./mongod-f. /conf/bigdata-sh-c2.conf

./mongod-f. /conf/bigdata-sh-configserver2.conf

./mongod-f. /conf/bigdata-sh-a3.conf

./mongod-f. /conf/bigdata-sh-b3.conf

./mongod-f. /conf/bigdata-sh-c3.conf

./mongod-f. /conf/bigdata-sh-configserver3.conf

To create a replica set:

./mongo Hadoop1:28111/admin

Use admin

Rs.initiate ()

Rs.add ("hadoop2:28111")

Rs.add ("hadoop3:28111")

./mongo Hadoop2:28112/admin

Rs.initiate ()

Rs.add ("hadoop1:28112")

Rs.add ("hadoop3:28112")

./mongo Hadoop3:28113/admin

Rs.initiate ()

Rs.add ("hadoop2:28113")

Rs.add ("hadoop1:28113")

./mongo Hadoop1:28200/admin

Rs.initiate ()

Rs.add ("hadoop2:28200")

Rs.add ("hadoop3:28200")

Start the MONGOs on three Linux:

./mongos--port 28300--configdb bigdata-cs/hadoop1:28200,hadoop2:28200,hadoop3:28200--fork--logpath/usr/local/ Mongodb/logs/mongos/mongos.log--bind_ip 0.0.0.0

Connect one of the MONGOs and add shards:

./mongo Hadoop1:28300/admin

Use admin

Sh.addshard ("bigdata-sh-a/hadoop1:28111,hadoop2:28111,hadoop3:28111")

Sh.addshard ("bigdata-sh-b/hadoop1:28112,hadoop2:28112,hadoop3:28112")

Sh.addshard ("bigdata-sh-c/hadoop1:28113,hadoop2:28113,hadoop3:28113")

Sh.enablesharding ("Shop")

Sh.shardcollection ("Shop.goods", {"Goodid": 1});

Insert large amounts of data for validation:

for (var i=80002; i<=90001; i++) {Db.goods.insert ({goodid:i, Name: "My First Shard"})}

Done!

MongoDB Learning notes for sharding and replica sets mixed use

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.