Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build mongodb Architecture Replica Set&Sharding-ttlsa

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article is to share with you about how to build mongodb architecture Replica Set&Sharding-ttlsa, the editor feels very practical, so share with you to learn, I hope you can get something after reading this article, say no more, follow the editor to have a look.

Build mongodb architecture Replica Set&Sharding-ttlsa in one minute

In the test phase, we need to have a simulated test environment to test whether the functions of all aspects of the application and system architecture meet the requirements. In my company, I often use the following methods to build mongodb replication sets and sharding architectures for developers to test. I also often use this method to simulate online architecture and test related content.

Open a MongoDB shell without connecting any mongod

?

one

> replicaSet = ReplSetTest ({:})

Start three mongod instances

?

one

two

three

four

five

six

seven

eight

nine

ten

eleven

twelve

thirteen

fourteen

fifteen

sixteen

seventeen

eighteen

nineteen

twenty

twenty-one

twenty-two

twenty-three

twenty-four

twenty-five

twenty-six

twenty-seven

twenty-eight

twenty-nine

thirty

thirty-one

thirty-two

thirty-three

thirty-four

thirty-five

thirty-six

thirty-seven

thirty-eight

thirty-nine

forty

forty-one

forty-two

forty-three

forty-four

forty-five

forty-six

forty-seven

forty-eight

forty-nine

fifty

fifty-one

fifty-two

fifty-three

fifty-four

fifty-five

fifty-six

fifty-seven

fifty-eight

fifty-nine

sixty

sixty-one

sixty-two

sixty-three

sixty-four

Et.startSet ()

ReplSetTest n: ReplSetTest n: ports: [,] number

"useHostName" true "oplogSize" 40 "keyFile" undefined "port" 31000 "noprealloc" smallfiles "rest" replSet "" testReplSet "" dbpath "," $set-$node "" restart "undefined" pathOpts "" node "0" set "" testReplSet "

}

Resetting db path ReplSetTest n: ReplSetTest n: ports: [,] number

"useHostName" true "oplogSize" 40 "keyFile" undefined "port" 31001 "noprealloc" smallfiles "rest" replSet "" testReplSet "" dbpath "," $set-$node "" restart "undefined" pathOpts "" node "1" set "" testReplSet "

}

Resetting db path ReplSetTest n: ReplSetTest n: ports: [,] number

"useHostName" true "oplogSize" 40 "keyFile" undefined "port" 31002 "noprealloc" smallfiles "rest" replSet "" testReplSet "" dbpath "," $set-$node "" restart "undefined" pathOpts "" node "2" set "" testReplSet "

}

Resetting db path > replicaSet.initiate ()

"replSetInitiate"_ id"testReplSet"members" {

:

:}

"_ id" 1 "host"nd0302012029:31001"

{

:

:}

}

#. / mongo-nodb

New "localhost:31000" > primaryDB = conn1.getDB () test

{

:

:

:

: [

]

:

:

:

:

: ISODate ()

:}

Insert 1000 documents

?

one

two

three

For01000 > primaryDB.coll.count ()

> conn2 = Mongo ()

31001

"test" test

/ / secondary is not readable or writable by default

"$err"not master and slaveOk=false"code" 13435 > secondaryDB.coll.insert ({:})

"getLastError" 1 {

:

:

:

Timestamp (,)

:

:}

You can see that secondary does not receive client write operations

Test the automatic failover functionality of the replication set:

Shutdown 31000 instance

Check which instance becomes primary

It can be seen that 31002 instances become the new master

Close replica set

For simple building methods of sharding, see: http://www.ttlsa.com/html/1787.html

The above is how to build mongodb architecture Replica Set&Sharding-ttlsa, the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report