MongoDB-Shard Management

Source: Internet
Author: User
Tags findone

1. Status check
Mongos> sh.status ();mongos> sh.status (true);

2. Check configuration information

Configuration information is present in the Config database
Config.changelog          #跟踪集群记录操作config. Chunks             #集合中块的信息config. Collections        #集群内所有分片集合的信息config. Databases          #集群内所有数据库的信息config. Settings           #块大小设置config. Shards             #集群内所有分片信息config. tags               #标签设置


3. Connection Information

#查看连接统计
Mongos> Db.admincommand ({"Connpoolstats": 1}) {"        hosts": {"                localhost:30000::0": {                        "available": 1,                        "created": 1                },                "localhost:30000::30": {                        "available": 3,                        "created": 3                },                "localhost : 30001::0 ": {                        " available ": 1,                        " created ": 1                },                " localhost:30002::0 ": {                        " available ": 1,                        "created": 1                }        ,        "Replicasets": {        },        "Createdbytype": {                "master": 6        },< c23/> "Totalavailable": 6,        "totalcreated": 6,        "Numdbclientconnection": 9,        "Numascopedconnection": 1,        

#限制连接数

A client connecting to Mongos,mongos creates at least one connection to the Shard; one mongos supports up to 20,000 connections.

The parameter maxcons option can limit the number of connections, you can specify the parameter Maxconns when running MONGOs, and calculate the number of connections from a single mongos that the Shard can handle:

Maxcons = 20000-(number of MONGOs processes)-(number of members per replica set)-(number of other/mongos processes)

(number of MONGOs processes) : Each MONGOs creates 3 connections per Mongod: One for forwarding client requests, one for tracing error messages, and one for monitoring replica set status

(number of members per replica set): The master node creates one connection with each backup node, and each backup node creates two connections to the master node, so a total of 3 connections

(number of other/mongos processes): Other processes refer to the number of processes that may be connected to Mongod

4. Add a server
(1) Adding shards

$./mongod--dbpath/mdb/data/s5--logpath/mdb/mlog/s5.log--fork--port 27025  --smallfiles> sh.addShard (" 172.31.11.230:27025 ");

(2) Add MONGOs

./mongos--logpath/mdb/mlog/ss2.log--fork--port 30001--configdb 172.31.11.230:27020

(3) Add Configuration server

./mongod--dbpath/mdb/data/sc--logpath/mdb/mlog/sc.log--fork--port 27020  --configsvrmongos Connect to multiple "configuration Servers":./ MONGOs--configdb Config-1:port,config-2:port,config-3:port ...

5. Remove the Shard to ensure that the equalizer is turned on

If the shards to be deleted are not used as primary libraries, use the

> Db.admincommand ({"Removeshard": "172.31.11.230:27028"})

If they are used as primary libraries, these databases need to be moved:

> Db.admincommand ({"Moveprimary": "blog", "to": "172.31.11.230:27109"}) > Db.admincommand ({"Removeshard": " 172.31.11.230:27028 "})

6. Modify the size of the block

> Use config> db.settings.save ({"_id": "Chunksize", "value": +});  #单位是m

7. Manually move the Block

Sh.movechunk ("Test.users", {"user_id": Numberlong ("223439877780288900")}, "Spock");

Move the block with user_id 223439877780288900 to the Shard named Spock.
You must use the slice key to find the block you want to move. The simplest way to usually specify a block is to specify his lower bounds, but any value within the specified block range can be (except the maximum).

8. Extra large block If the size of the block exceeds the size set in the Config.settings, the equalizer cannot move the block. (1) Check the large block Sh.status (); If the block appears with the Jumbo property, it indicates that the block is a jumbo block (2) using the DataSize command to check the block size using the Config.chunks collection, view block range > Use config> var chunks = Db.chunks.find ({"NS  ":" Shop.goods "}). ToArray () > Chunks.foreach (Printjson); #可以查看上一步得到的变量的值根据块的范围, find out the possible mega blocks > Use dbname> db.runcommand ({"DataSize": "Dbname.collname", "Keypattern": {"date ": 1}, #片名" min ": Chunks[0].min," Max ": Chunks[0].max}) (3) Mega block distribution • Off Equalizer > Sh.setbalancerstate (FALSE); Temporarily increase the maximum block size value > Use config> db.settings.findOne ({"_id": "Chunksize"});> Db.settings.save ({"_id": "Chunksize", " Value ": 1024}); Use the Movechunk command to move the Mega block > Sh.movechunk ("Test.users", {"user_id": Numberlong ("223439877780288900")}, "Spock");> Db.admincommand ({"Movechunk": "Dbname.collname", "find": {"date": New Date ("10/03/2015")}, "to": "shard0002", "sec Ondary "Throttle:true #要求迁移过程间歇进行, so as not to affect performance}) • Use the Splitchunk command to split the remaining blocks from the From Shard (to achieve block equalization from the number of shards and other shards) • Modify block size > usage config > Db.settings.findOne ({"_id": "Chunksize"});> Db.settings.save ({"_id": "Chunksize", "Value": 32}); Enable the Homogenizer > Sh.setbalancerstate (True) (4) to prevent the granularity of the thinning slice key in the large block, as much as possible to ensure that each document has a unique slice key. 9. Manually refresh the configuration if MONGOs cannot get configuration information from the configuration server, you can manually refresh > Db.admincommand ({"Flushrouterconfig": 1});

MongoDB-Shard Management

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.