来源:AustinDatabases
Mongoshake 是阿里云自研的开源工具,实现Mongodb 数据库之间的数据同步,数据灾备,数据多活,分库分表,版本升级无间断。
其中需要注意的一些事项
mongo_urls = mongodb://username:password@10.1.1.1:1001/admin?readPreference=secondary
filter.pass.special.db = admin 这里主要指定的是一些特殊情况下,针对 admin system.views , mongoshake config 等数据库在默认不迁移的情况下,因为某些问题,需要进行数据迁移的情况
filter.ddl_enable = false 这个选项是在复制中不对DDL的操作进行复制,所以数据迁移中为避免一些问题,可以使用false 而数据同步的情况就需要考虑打开这个设置。
13 关于并发
full_sync.reader.collection_parallel =6 这个参数默认为 6 为一次最大并发拉取的表的数目,拉取一次过多,会导致IOPS 升高影响业务。
full_sync.reader.write_document_parallel = 8 ,对于一个表进行拉取的过程中,产生多少线程,来同时进行数据的拉取,这里注意要有主键。
full_sync.reader.document_batch_size 一次将写入多少文件进行聚合 128 表示一次写入 128个文档进行聚合 默认值为128
full_sync.executor.insert_on_dup_update = false
在目的库存在同样的数据库和collation 是否要进行insert to update的转换
use config
while( sh.isBalancerRunning() ) {
print("waiting...");
sleep(1000);
}
sh.stopBalancer()
sh.setBalancerState(true)
下面就将整体的工作情况进行一个流程化的记录
1 登录到分片的mongodb 中,确认当前的工作状态
这里可以看到,balancer 是开启的状态,当前并未运行
[mongos] admin> sh.status()
shardingVersion
{ _id: 1, clusterId: ObjectId('5e1bdb2dbd7ea0ac43') }
---
shards
[
{
_id: 'd-2ze2fde064',
host: 'mgset-21218075/7:3044',
state: 1
},
{
_id: 'd-2ze77e7e4e38ad64',
host: 'mgset-21218077/',
state: 1
}
]
---
active mongoses
[ { '4.2.1': 1 }, { '4.2.10': 1 } ]
---
autosplit
{ 'Currently enabled': 'yes' }
---
balancer
{
'Currently enabled': 'yes',
'Currently running': 'no',
'Failed balancer rounds in last 5 attempts': 0,
'Migration Results for the last 24 hours': { '11': 'Success' }
}
---
databases
[
{
database: { _id: 'config', primary: 'config', partitioned: true },
collections: {
'config.system.sessions': {
shardKey: { _id: 1 },
unique: false,
balancing: true,
chunkMetadata: [
{ shard: 'd-2ze2fde06cf92d74', nChunks: 512 },
{ shard: 'd-2ze77e7e4e38ad64', nChunks: 512 }
],
chunks: [
'too many chunks to print, use verbose if you want to force print'
],
tags: []
}
}
},
{
database: {
_id: 'report',
primary: 'd-2ze77e7e4e38ad64',
partitioned: true,
version: {
uuid: UUID('a3efc46e-b05f-4557-af1b-ddfeb212dd5e'),
lastMod: 1
}
},
collections: {
'report.request_record_new': {
shardKey: { requestId: 'hashed' },
unique: false,
balancing: true,
chunkMetadata: [
{ shard: 'd-2ze2fde06cf92d74', nChunks: 42853 },
{ shard: 'd-2ze77e7e4e38ad64', nChunks: 42852 }
],
chunks: [
'too many chunks to print, use verbose if you want to force print'
],
tags: []
}
}
}
]
[mongos] config> sh.stopBalancer()
{
ok: 1,
operationTime: Timestamp({ t: 1701137103, i: 45 }),
'$clusterTime': {
clusterTime: Timestamp({ t: 1701137103, i: 45 }),
signature: {
hash: Binary.createFromBase64('9RIHAXxDGxhwvcAVNQw5N0/3w9g=', 0),
keyId: Long('7253280536863440980')
active mongoses
[ { '4.2.1': 1 }, { '4.2.10': 1 } ]
---
autosplit
{ 'Currently enabled': 'no' }
---
balancer
{
'Currently running': 'no',
'Currently enabled': 'no',
vi collector.conf
conf.version = 10
id = mongoshake
master_quorum = false
full_sync.http_port = 9190
incr_sync.http_port = 9190
system_profile_port = 820
log.level = info
log.dir = /mongoshake
log.file = collector.log
log.flush = false
sync_mode = all
mongo_urls = mongodb://mongosd:g_cs_1127@d-2183.mongodb.com:3797;mongodb://mongos:fe1127@d64952.mongodb.com:3797
mongo_cs_url = mongodb://mongocs:feg_cs_1127@ddee63.mongodb.rdscom:3719/admin
mongo_s_url = mongodb://ot9:%301%2318a4.mong.com:3719/admin
tunnel = direct
tunnel.address = mongodb://otg:B3X@dds-2ze220fb41051a641.moncom:377,1a642.mongodbs.com:377/admin?replicaSet=mset-73
tunnel.message = raw
tunnel.kafka.partition_number = 1
mongo_connect_mode = primary
A: This is usually a problem with insufficient
account permissions, so, please check your permission of oplog table. If
the source is sharding, the account should be added into each shard
because there is no local database in mongos. When source is sharding, the mongo_urls should be the shards address split by semicolon(;) like: mongo_urls: mongodb://user1:passwd1@10.1.1.1:20011,10.1.1.2:20112;mongodb://user2:passwd2@10.1.2.1:20011,10.1.2.2:20112.
Since v2.0.6, MongoShake doesn't throw this error when sync mode is full sync(sync_mode = document).
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70024420/viewspace-2998115/ ,如需转载,请注明出处,否则将追究法律责任。