Sharding
Face: On behalf of the client, the client must say, you do not shard database shard with me, I told you to do what you do, there is no good to discuss.
MONGOs: First we need to understand the concept of "chip key", that is, what is the basis for splitting the set? To split a collection by what key value ....
Well, MONGOs is a routing server that will distribute the data to the Mongod cluster that it manages, based on the "tablet key" set by the administrator.
and the corresponding configuration information is stored on the "config server".
Mongod: An ordinary database instance, if not sharding, we will directly connect to the Mongod.
First, MONGO copy paste 7 copies
The date folder is an empty folder
Add a bat to each bin folder
Filename |
Content |
Config1.bat |
Mongod--dbpath=f:\mongo\mongodb_config1\data--port 2001 |
Config2.bat |
Mongod--dbpath=f:\mongo\mongodb_config2\data--port 2002 |
Config3.bat |
Mongod--dbpath=f:\mongo\mongodb_config3\data--port 2003 |
Mongos.bat |
MONGOs--port 2222--configdb 127.0.0.1:2001,127.0.0.1:2002,127.0.0.1:2003 |
Mongod1.bat |
Mongod--dbpath=f:\mongo\mongodb_data1\data--port 2004 |
Mongod2.bat |
Mongod--dbpath=f:\mongo\mongodb_data2\data--port 2005 |
Mongod3.bat |
Mongod--dbpath=f:\mongo\mongodb_data3\data--port 2006 |
Start in sequence
Config1.bat
Config2.bat
Config3.bat
Mongos.bat
Mongod1.bat
Mongod2.bat
Mongod3.bat
Open a new cmd
F:
CD F:\mongo\mongodb_mongos\bin
MONGO 127.0.0.1:2222/admin
Db.runcommand ({"Addshard": "127.0.0.1:2004"})
Db.runcommand ({"Addshard": "127.0.0.1:2005"})
Db.runcommand ({"Addshard": "127.0.0.1:2006"})
Db.runcommand ({"enablesharding": "Test"})
Db.runcommand ({"Shardcollection": "Test.person", "key": {"name": 1}})
Inserting data
Use test
for (Var i=0;i<10000;i++) {
Db.person.insert ({"Name": "Jack" +i, "age": i})
}
View Effects
Questions:
1.mongos has always reported this: Distributed Lock ' balancer/**** ' unlocked
2. Fragmented, 1W of data is divided into 4444,5555,1 to 3 databases
MONGO Study Note (v): Shard