首頁 > 資料庫 > mysql教程 > mongo单台设备分片--2

mongo单台设备分片--2

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
發布: 2016-06-07 14:58:46
原創
1546 人瀏覽過

mongo单台设备分片--2 mongodb please create an index over the sharding key before sharding 使用单一索引,如果collection中没有索引,就会报错 config={_id:shard1,members:[{_id: 0, host: 127.0.0.1:27018},{_id: 1, host: 127.0.0.1:27019},{_id: 2,

mongo单台设备分片--2

 

mongodb please create an index over the sharding key before sharding 

 

使用单一索引,如果collection中没有索引,就会报错 

 

config={_id:'shard1',members:[{_id: 0, host: '127.0.0.1:27018'},{_id: 1,
host: '127.0.0.1:27019'},{_id: 2, host: '127.0.0.1:27020'},{_id: 3, host: '127.0.0.1:27021'}]} 

 

rs.initiate(config); 

rs.add({"_id" : 4,host : "127.0.0.1:27022",arbiterOnly:true}); 

 

config={_id:'shard2',members:[{_id: 0, host: '127.0.0.1:27028'},{_id: 1,
host: '127.0.0.1:27029'},{_id: 2, host: '127.0.0.1:27030'},{_id: 3, host: '127.0.0.1:27031'}]} 

 

rs.initiate(config); 

rs.add({"_id" : 4,host : "127.0.0.1:27032",arbiterOnly:true}); 

 

config={_id:'shard3',members:[{_id: 0, host: '127.0.0.1:27038'},{_id: 1,
host: '127.0.0.1:27039'},{_id: 2, host: '127.0.0.1:27040'},{_id: 3, host: '127.0.0.1:27041'}]} 

 

rs.initiate(config); 

rs.add({"_id" : 4,host : "127.0.0.1:27042",arbiterOnly:true}); 

 

sudo mongod --configsvr --dbpath /data/mongo/ReplicaSetData-shard1/
config --port 20000 --logpath /data/mongo/ReplicaSetData-shard1/config.log --logappend --fork 

 

sudo mongod --configsvr --dbpath /data/mongo/ReplicaSetData-shard2/
config --port 20001 --logpath /data/mongo/ReplicaSetData-shard2/config.log --logappend --fork 

 

sudo mongod --configsvr --dbpath /data/mongo/ReplicaSetData-shard3/
config --port 20002 --logpath /data/mongo/ReplicaSetData-shard3/config.log --logappend --fork 

 

sudo mongos --configdb 127.0.0.1:20000,127.0.0.1:20001,127.0.0.1:
20002 --port 30000 --chunkSize 5 --logpath /data/mongo/ReplicaSetData-
shard-log/mongos.log --logappend --fork 

 

db.runCommand( { addshard : "shard1/127.0.0.1:27018,127.0.0.1:27019,
127.0.0.1:27020,127.0.0.1:
27021,127.0.0.1:27022",name:"s1",maxsize:20480} ); 

 

db.runCommand( { addshard : "shard2/127.0.0.1:27028,127.0.0.1:27029,
127.0.0.1:27030,127.0.0.1:27031,
127.0.0.1:27032",name:"s2",maxsize:20480} ); 

 

db.runCommand( { addshard : "shard3/127.0.0.1:27038,127.0.0.1:27039,
127.0.0.1:27040,127.0.0.1:27041,
127.0.0.1:27042",name:"s3",maxsize:20480} ); 

 

db.runCommand( { listshards : 1 } ) 

 

db.runCommand( { enablesharding : "cooler" } ); 

 

 

db.runCommand( { shardcollection : "cooler.c1",key : {id: 1} } ) 

 

for (var i = 1; i value2:"1234567890",value3:
"1234567890",value4:"1234567890"}); 

 

db.printShardingStatus() 

db.c1.stats()

 

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
mongodb - mongo修改字段名?
來自於 1970-01-01 08:00:00
0
0
0
mongodb - mongo 的group用法
來自於 1970-01-01 08:00:00
0
0
0
mongodb - mongo全文索引
來自於 1970-01-01 08:00:00
0
0
0
mongodb - 怎麼開啟和關閉mongo-server
來自於 1970-01-01 08:00:00
0
0
0
mongodb - Mongo的collection太多
來自於 1970-01-01 08:00:00
0
0
0
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板