Set up a MongoDB cluster many times, each time will be or more, or less some of the hell of the problem, write this blog for later reference.
This is based on the mongodb3.0 to build the cluster, the construction steps are as follows:
1. Setting the operating system environment
echo "Never" > "/sys/kernel/mm/transparent_hugepage/enabled" echo "Never" > "/sys/kernel/mm/transparent_ Hugepage/defrag "Ulimit-n 64000
2. Modification of configuration Files [Mongod.conf]
Shards configuration: port=27018, directoryperdb=true, bind_ip=0.0.0.0 config configuration: port=27019, bind_ip=0.0.0.0 monogs configuration: MONGOs-- ConfigDB 192.168.12.150:27019--logpath/var/log/mongodb/mongos.log--pidfilepath/var/run/mongodb/mongos.pid-- Logappend--logrotate Reopen--FO hosts configuration: {shardone.mongodb.local,shardtwo.mongodb.local,shardthree.mongodb.local} Add the domain name resolution for the IP address that corresponds to each shard server
3. Adding shards
>>mongo Admin>>db.runcommand ({addshard: "shardone.mongodb.local:27018", Name: "Shardone"})--Add Shard >&G T;db.runcommand ({addshard: "shardtwo.mongodb.local:27018", Name: "Shardtwo"}) >>db.runcommand ({addshard: " shardthree.mongodb.local:27018 ", Name:" Shardthree "})
As far as possible, the Shard server avoids the change of IP address of the server in the way of domain name resolution
4. Start the Shard and add the slice key to the database
>>db.runcommand ({"enablesharding": "Mc_visit"}) >>db.runcommand ({"Shardcollection": "Mc_visit.mc_ Visit "," key ": {" Visitdate ":-1," Virus ": 1}})
5, no data in the case of modified tablet key
>>use Config>>db.collections.find ()--View all tab keys >>db.chunks.find ()--view blocks of existing shards
MongoDB Cluster Setup Steps