标签:tar.gz 插入数据 insert 9.1 选择 复制 rect rhel body
192.168.50.131 192.168.50.131 192.168.50.132
mongos |
|
mongos |
|
mongos |
configsvr |
|
configsvr |
|
configsvr |
Shard1 |
|
Shard1 |
|
Shard1 |
Shard2 |
|
Shard2 |
|
Shard2 |
Shard3 |
|
Shard3 |
|
Shard3 |
192.168.50.130,192.168.50.131,192.168.50.132
mongodb-linux-x86_64-rhel62-3.4.0.tar.gz
ln -s /usr/local/ mongodb-linux-x86_64-rhel62-3.4.0/bin/mongo /usr/bin/mongo
ln -s /usr/local/ mongodb-linux-x86_64-rhel62-3.4.0/bin/mongos /usr/bin/mongos
ln -s /usr/local/ mongodb-linux-x86_64-rhel62-3.4.0/bin/mongod /usr/bin/mongod
mkdir -p /data/mongodb && cd /data/mongodb/ && mkdir -p conf/data conf/log mongos/log shard{1..3}/data shard{1..3}/log
mongod --configsvr --replSet configset --dbpath /data/mongodb/conf/data --port 27100 --logpath /data/mongodb/conf/confdb.log --bind_ip 0.0.0.0 --fork
mongo192.168.25.131:27100
config_replset={_id:"configset",members:[{_id:0,host:"192.168.25.130:27100"},{_id:1,host:"192.168.25.131:27100"},{_id:2,host:" 192.168.25.132:27100"}]}
rs.initiate(config_replset)
mongos
--configdb configset/192.168.25.130:27100,192.168.25.131:27100,192.168.25.132:27100 --port 27200 --logpath /data/mongodb/mongos/mongos.log --fork
mongod --shardsvr --replSet shard1 --port 27001 --bind_ip 0.0.0.0 --dbpath /data/mongodb/shard1/data --logpath /data/mongodb/shard1/log/shard1.log --directoryperdb --fork
mongod --shardsvr --replSet shard2 --port 27002 --bind_ip 0.0.0.0 --dbpath /data/mongodb/shard2/data --logpath /data/mongodb/shard2/log/shard2.log --directoryperdb --fork
mongod --shardsvr --replSet shard3 --port 27003 --bind_ip 0.0.0.0 --dbpath /data/mongodb/shard3/data --logpath /data/mongodb/shard3/log/shard3.log --directoryperdb --fork
mongo --port 27001
use admin
rs.initiate({
_id: ‘shard1‘,
members: [
{_id: 84, host: ‘192.168.25.130:27001‘},
{_id: 89, host: ‘192.168.25.131:27001‘},
{_id: 90, host: ‘192.168.25.132:27001‘}
]
});
mongo --port 27002
use admin
rs.initiate({
_id: ‘shard2‘,
members: [
{_id: 84, host: ‘192.168.25.130:27002‘},
{_id: 89, host: ‘192.168.25.131:27002‘},
{_id: 90, host: ‘192.168.25.132:27002‘}
]
});
如果要设置仲裁节点的话:
config = {_id: ‘shard3‘, members: [{_id: 0, host: ‘192.168.10.202:27022‘},{_id:1, host: ‘192.168.10.204:27022‘},{_id: 2, host: ‘192.168.10.203:30001‘, arbiterOnly:true}]}
rs.initiate(config);
mongo --port 27003
use admin
rs.initiate({
_id: ‘shard3‘,
members: [
{_id: 84, host: ‘192.168.25.130:27003‘},
{_id: 89, host: ‘192.168.25.131:27003‘},
{_id: 90, host: ‘192.168.25.132:27003‘}
]
});
Mongo –port 27200
use admin
db.runCommand({addShard: ‘shard1/192.168.25.130:27001,192.168.25.131:27001,192.168.25.132:27001‘});
db.runCommand({addShard: ‘shard2/192.168.25.130:27002,192.168.25.131:27002,192.168.25.132:27002‘});
db.runCommand({addShard: ‘shard3/192.168.25.130:27003,192.168.25.131:27003,192.168.25.132:27003‘});
查看shard
use admin
db.runCommand({listshards: 1});
{
"shards" : [
{
"_id" : "shard1",
"host" : "shard1/10.199.144.84:27001,10.199.144.89:27001"
},
{
"_id" : "shard2",
"host" : "shard2/10.199.144.89:27002,10.199.144.90:27002"
},
{
"_id" : "shard3",
"host" : "shard3/10.199.144.90:27003,10.199.144.84:27003"
}
],
"ok" : 1
}
mongo --port 27200
use admin
db.runCommand({enablesharding: ‘dbtest‘});
db.runCommand({shardcollection: ‘dbtest.coll1‘, key: {id: 1}});
use dbtest
db.coll1.stats()
结果是数据分配不平均,因为id没hash
此处对sano1y库的testtb使用hash策略:
目前为止,已经对sano1y库的testtb集合进行了shard配置。
测试:
稍等片刻,等待插入完毕:
进入shard1(187)的PRIMARY实例检查
另外如果到shard2可以看到shard1这些不连续的id。
可发现shard1和2中的document数量,还是比较均匀的。
shard1: 33320
shard2: 33421
Shard3: 33259
可以看出,count数量基本还是保持平衡的,又很小的落差
标签:tar.gz 插入数据 insert 9.1 选择 复制 rect rhel body
原文地址:https://www.cnblogs.com/byfboke/p/9105178.html