1. Environmental preparedness
centos6.6 x64 3 units
192.168.0.23
192.168.0.24
192.168.0.201
2. Cluster planning
Each machine simultaneously starts MONGOs, config server, shard0, Shard2, Shard3,
Config server IP ports are: 192.168.0.23:1111,192.168.0.24:1111,192.168.0.201:1111
MONGOs IP ports are: 192.168.0.23:2222,192.168.0.24:2222,192.168.0.201:2222
Shard0 IP ports are: 192.168.0.23:3333,192.168.0.24:3333,192.168.0.201:3333
Shard1 IP ports are: 192.168.0.23:4444,192.168.0.24:4444,192.168.0.201:4444
Shard2 IP ports are: 192.168.0.23:5555,192.168.0.24:5555,192.168.0.201:5555
3. Software version:
Https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon-3.2.6.tgz
4. Each directory that installs MongoDB separately and creates a good response
Wget-c https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon-3.2.6.tgz
Tar XF mongodb-linux-x86_64-amazon-3.2.6.tgz
Mkdir-pv/export/{configsvr,shard0,shard1,shard2}/data
5. Start config server on each machine
To create a configuration file:
Vim configsvr.conf
DBPath =/export/mongodb/configsvr/data/
Port = 1111
Configsvr = True
Fork = True
Logpath=/export/log/mongconfigsvr.log
Logappend=true
maxconns=1000
Pidfilepath=/var/run/mongconfigsvr.pid
Httpinterface=true
Start Configsvr
mkdir-pv/export/log/
cd/export/log/
Touch Mongconfigsvr.log
/opt/mongodb3.2.6/bin/mongod-f/opt/mongodb3.2.6/configsvr.conf
Netstat-tlnup 1111 Port Boot
6. Configure routing on each machine
Create a configuration file for MONGOs
Vim mongos.conf
Port = 2222
maxconns=1000
Logpath=/var/log/mongos.log
Logappend=true
Logrotate=rename
Pidfilepath=/var/run/mongos.pid
Fork=true
Httpinterface=true
ConfigDB = 192.168.0.23:1111,192.168.0.24:1111,192.168.0.201:1111
To start a route:
/opt/mongodb3.2.6/bin/mongos-f/opt/mongodb3.2.6/mongos.conf
Note that there are machine time is not the same error, error log has an error checking clock skew of cluster
Please synchronize time
7. Configure the replica set shard on each machine shard0
Create a configuration file for Shard
Vim shard0.conf
port=3333
maxconns=1000
Logpath=/var/log/shard0.log
Logappend=true
Logrotate=rename
Pidfilepath=/var/run/shard0.pid
Fork=true
Cpu=true
Dbpath=/export/mongodb/shard0/data
oplogsize=1000
Replset = Testrs0
Rest = True
Httpinterface=true
Start Shard
/opt/mongodb3.2.6/bin/mongos-f/opt/mongodb3.2.6/mongos.conf
#注意下面的操作在一起机器上操作即可, if you do not have a problem without the master node, if the poor, please delete the operation on a single machine.
/opt/mongodb3.2.6/bin/mongo 127.0.0.1:3333
Use admin
#将其他的分片添加进来
config={_id: "Testrs0", Members: [{"_id": 0, "host": "192.168.0.23:3333"},{"_id": 1, "host": "192.168.0.24:3333"},{"_id" ": 2," host ":" 192.168.0.201:3333 "}]}
#使用config配置初始化
Rs.initiate (config)
#查看主节点
Db.ismaster ()
#查看副本集信息
Rs.status ()
Configure replica set Shard 2
port=4444
maxconns=1000
Logpath=/var/log/sahrd1.log
Logappend=true
Logrotate=rename
Pidfilepath=/var/run/shard1.pid
Fork=true
Cpu=true
Dbpath=/export/mongodb/shard1/data
oplogsize=1000
Replset = testrs1
Rest = True
Httpinterface=true
Start Shard
/opt/mongodb3.2.6/bin/mongo 127.0.0.1:4444
Use admin
config={_id: "Testrs1", Members: [{"_id": 0, "host": "192.168.0.23:4444"},{"_id": 1, "host": "192.168.0.24:4444"},{"_id" ": 2," host ":" 192.168.0.201:4444 "}]}
Configure replica set Shard 3
port=5555
maxconns=1000
Logpath=/var/log/sahrd2.log
Logappend=true
Logrotate=rename
Pidfilepath=/var/run/shard2.pid
Fork=true
Cpu=true
Dbpath=/export/mongodb/shard2/data
oplogsize=1000
Replset = Testrs2
Rest = True
Httpinterface=true
Start Shard
/opt/mongodb3.2.6/bin/mongo 127.0.0.1:4444
Use admin
config={_id: "Testrs2", Members: [{"_id": 0, "host": "192.168.0.23:5555"},{"_id": 1, "host": "192.168.0.24:5555"},{"_id" ": 2," host ":" 192.168.0.201:555 "}]}
8. Adding a replica set
/opt/mongodb3.2.6/bin/mongo 127.0.0.1:2222
mongos> Use admin
Switched to DB admin
Mongos> Db.runcommand ({addshard: "testrs0/192.168.0.23:3333,192.168.0.24:3333,192.168.0.201:3333"})
{"shardadded": "Testrs0", "OK": 1}
Mongos> Db.runcommand ({addshard: "testrs1/192.168.0.23:4444,192.168.0.24:4444,192.168.0.201:4444"})
{"shardadded": "Testrs1", "OK": 1}
Mongos> Db.runcommand ({addshard: "testrs2/192.168.0.23:5555,192.168.0.24:5555,192.168.0.201:5555"})
{"shardadded": "Testrs2", "OK": 1}
To view the configuration of a shard server
Db.runcommand ({listshards:1});
Specify the TestDB shard to take effect
mongos> Use admin
Switched to DB admin
Mongos> Db.runcommand ({enablesharding: "TestDB"});
{"OK": 1}
mongos> Use admin
Switched to DB admin
Mongos> Db.runcommand ({shardcollection: "Testdb.tid", key: {id:1}})
We set the Table1 table for TestDB to be fragmented, automatically sharding to shard0 according to the ID, Shard1,shard2 above. This is set because not all MONGODB databases and tables require sharding!
Centos6.6 build mongodb3.2.6 Replica set Shard