【Mongodb】往分片复制集添加复制成员
发表于:2025-01-23 作者:千家信息网编辑
千家信息网最后更新 2025年01月23日,1.新的成员机器上安装mongo,启动shard1[root@ip-10-1-2-183 etc]# more shard1.conflogpath=/usr/local/mongodb/logs/m
千家信息网最后更新 2025年01月23日【Mongodb】往分片复制集添加复制成员1.新的成员机器上安装mongo,启动shard1
/usr/local/mongodb/bin/mongod -f shard1.conf
2.主节点上加入新的复制集成员
3.shard2 config 加成员同理(过程略)
4.检查是否加入成功
4.最后修改下配置文件
- [root@ip-10-1-2-183 etc]# more shard1.conf
- logpath=/usr/local/mongodb/logs/mongo_shard1.log
- logappend=true # need logrotae scripts
- fork=true
- journal=true
- port=27019
- #vvvvv = true
- #diaglog = 3
- dbpath=/usr/local/mongodb/shard1
- pidfilepath=/usr/local/mongodb/logs/mongo_shard1.pid
- bind_ip=10.1.2.183
- replSet=shard1
- shardsvr=true
/usr/local/mongodb/bin/mongod -f shard1.conf
2.主节点上加入新的复制集成员
- [root@ip-10-1-2-32 etc]# /usr/local/mongodb/bin/mongo 10.1.2.32:27019
- shard1:PRIMARY> rs.add({_id: 3, host: "10.1.2.183:27019"})
- {
- "ok" : 1,
- "operationTime" : Timestamp(1525752728, 3),
- "$gleStats" : {
- "lastOpTime" : {
- "ts" : Timestamp(1525752728, 3),
- "t" : NumberLong(1)
- },
- "electionId" : ObjectId("7fffffff0000000000000001")
- },
- "$clusterTime" : {
- "clusterTime" : Timestamp(1525752728, 3),
- "signature" : {
- "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
- "keyId" : NumberLong(0)
- }
- },
- "$configServerState" : {
- "opTime" : {
- "ts" : Timestamp(1525752728, 2),
- "t" : NumberLong(1)
- }
- }
- }
- shard1:PRIMARY> rs.isMaster()
- {
- "hosts" : [
- "10.1.2.32:27019",
- "10.1.2.68:27019",
- "10.1.2.175:27019",
- "10.1.2.183:27019"
- ],
- "setName" : "shard1",
- "setVersion" : 4,
- "ismaster" : true,
- "secondary" : false,
- "primary" : "10.1.2.32:27019",
- "me" : "10.1.2.32:27019",
- "electionId" : ObjectId("7fffffff0000000000000001"),
- "lastWrite" : {
- "opTime" : {
- "ts" : Timestamp(1525752728, 3),
- "t" : NumberLong(1)
- },
- "lastWriteDate" : ISODate("2018-05-08T04:12:08Z"),
- "majorityOpTime" : {
- "ts" : Timestamp(1525752728, 3),
- "t" : NumberLong(1)
- },
- "majorityWriteDate" : ISODate("2018-05-08T04:12:08Z")
- },
- "maxBsonObjectSize" : 16777216,
- "maxMessageSizeBytes" : 48000000,
- "maxWriteBatchSize" : 100000,
- "localTime" : ISODate("2018-05-08T04:12:12.282Z"),
- "logicalSessionTimeoutMinutes" : 30,
- "minWireVersion" : 0,
- "maxWireVersion" : 6,
- "readOnly" : false,
- "ok" : 1,
- "operationTime" : Timestamp(1525752728, 3),
- "$gleStats" : {
- "lastOpTime" : {
- "ts" : Timestamp(1525752728, 3),
- "t" : NumberLong(1)
- },
- "electionId" : ObjectId("7fffffff0000000000000001")
- },
- "$clusterTime" : {
- "clusterTime" : Timestamp(1525752729, 3),
- "signature" : {
- "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
- "keyId" : NumberLong(0)
- }
- },
- "$configServerState" : {
- "opTime" : {
- "ts" : Timestamp(1525752729, 3),
- "t" : NumberLong(1)
- }
- }
- }
- shard1:PRIMARY> rs.conf()
- {
- "_id" : "shard1",
- "version" : 4,
- "protocolVersion" : NumberLong(1),
- "members" : [
- {
- "_id" : 0,
- "host" : "10.1.2.32:27019",
- "arbiterOnly" : false,
- "buildIndexes" : true,
- "hidden" : false,
- "priority" : 1,
- "tags" : {
- },
- "slaveDelay" : NumberLong(0),
- "votes" : 1
- },
- {
- "_id" : 1,
- "host" : "10.1.2.68:27019",
- "arbiterOnly" : false,
- "buildIndexes" : true,
- "hidden" : false,
- "priority" : 1,
- "tags" : {
- },
- "slaveDelay" : NumberLong(0),
- "votes" : 1
- },
- {
- "_id" : 2,
- "host" : "10.1.2.175:27019",
- "arbiterOnly" : false,
- "buildIndexes" : true,
- "hidden" : false,
- "priority" : 1,
- "tags" : {
- },
- "slaveDelay" : NumberLong(0),
- "votes" : 1
- },
- {
- "_id" : 3,
- "host" : "10.1.2.183:27019",
- "arbiterOnly" : false,
- "buildIndexes" : true,
- "hidden" : false,
- "priority" : 1,
- "tags" : {
- },
- "slaveDelay" : NumberLong(0),
- "votes" : 1
- }
- ],
- "settings" : {
- "chainingAllowed" : true,
- "heartbeatIntervalMillis" : 2000,
- "heartbeatTimeoutSecs" : 10,
- "electionTimeoutMillis" : 10000,
- "catchUpTimeoutMillis" : -1,
- "catchUpTakeoverDelayMillis" : 30000,
- "getLastErrorModes" : {
- },
- "getLastErrorDefaults" : {
- "w" : 1,
- "wtimeout" : 0
- },
- "replicaSetId" : ObjectId("5aeab9557a9235efbe4a9b59")
- }
- shard1:PRIMARY> rs.status()
{
"set" : "shard1",
"date" : ISODate("2018-05-08T05:38:35.245Z"),
"myState" : 1,
"term" : NumberLong(1),
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1525757907, 1),
"t" : NumberLong(1)
},
"readConcernMajorityOpTime" : {
"ts" : Timestamp(1525757907, 1),
"t" : NumberLong(1)
},
"appliedOpTime" : {
"ts" : Timestamp(1525757907, 1),
"t" : NumberLong(1)
},
"durableOpTime" : {
"ts" : Timestamp(1525757907, 1),
"t" : NumberLong(1)
}
},
"members" : [
{
"_id" : 0,
"name" : "10.1.2.32:27019",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 425793,
"optime" : {
"ts" : Timestamp(1525757907, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2018-05-08T05:38:27Z"),
"electionTime" : Timestamp(1525332319, 1),
"electionDate" : ISODate("2018-05-03T07:25:19Z"),
"configVersion" : 4,
"self" : true
},
{
"_id" : 1,
"name" : "10.1.2.68:27019",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 425606,
"optime" : {
"ts" : Timestamp(1525757907, 1),
"t" : NumberLong(1)
},
"optimeDurable" : {
"ts" : Timestamp(1525757907, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2018-05-08T05:38:27Z"),
"optimeDurableDate" : ISODate("2018-05-08T05:38:27Z"),
"lastHeartbeat" : ISODate("2018-05-08T05:38:34.014Z"),
"lastHeartbeatRecv" : ISODate("2018-05-08T05:38:34.014Z"),
"pingMs" : NumberLong(0),
"syncingTo" : "10.1.2.32:27019",
"configVersion" : 4
},
{
"_id" : 2,
"name" : "10.1.2.175:27019",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 425606,
"optime" : {
"ts" : Timestamp(1525757907, 1),
"t" : NumberLong(1)
},
"optimeDurable" : {
"ts" : Timestamp(1525757907, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2018-05-08T05:38:27Z"),
"optimeDurableDate" : ISODate("2018-05-08T05:38:27Z"),
"lastHeartbeat" : ISODate("2018-05-08T05:38:34.014Z"),
"lastHeartbeatRecv" : ISODate("2018-05-08T05:38:34.016Z"),
"pingMs" : NumberLong(0),
"syncingTo" : "10.1.2.183:27019",
"configVersion" : 4
},
{
"_id" : 3,
"name" : "10.1.2.183:27019",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 5184,
"optime" : {
"ts" : Timestamp(1525757907, 1),
"t" : NumberLong(1)
},
"optimeDurable" : {
"ts" : Timestamp(1525757907, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2018-05-08T05:38:27Z"),
"optimeDurableDate" : ISODate("2018-05-08T05:38:27Z"),
"lastHeartbeat" : ISODate("2018-05-08T05:38:34.016Z"),
"lastHeartbeatRecv" : ISODate("2018-05-08T05:38:33.567Z"),
"pingMs" : NumberLong(0),
"syncingTo" : "10.1.2.68:27019",
"configVersion" : 4
}
],
"ok" : 1,
"operationTime" : Timestamp(1525757907, 1),
"$gleStats" : {
"lastOpTime" : Timestamp(0, 0),
"electionId" : ObjectId("7fffffff0000000000000001")
},
"$clusterTime" : {
"clusterTime" : Timestamp(1525757911, 2),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
},
"$configServerState" : {
"opTime" : {
"ts" : Timestamp(1525757911, 2),
"t" : NumberLong(1)
}
}
}
3.shard2 config 加成员同理(过程略)
4.检查是否加入成功
- 登陆mongos端口可以看到
- [root@ip-10-1-2-32 etc]# /usr/local/mongodb/bin/mongo 10.1.2.32:30000
- MongoDB shell version v3.6.4
- connecting to: mongodb://10.1.2.32:30000/test
- MongoDB server version: 3.6.4
- Server has startup warnings:
- 2018-05-03T07:47:09.379+0000 I CONTROL [main]
- 2018-05-03T07:47:09.379+0000 I CONTROL [main] ** WARNING: Access control is not enabled for the database.
- 2018-05-03T07:47:09.379+0000 I CONTROL [main] ** Read and write access to data and configuration is unrestricted.
- 2018-05-03T07:47:09.379+0000 I CONTROL [main] ** WARNING: You are running this process as the root user, which is not recommended.
- 2018-05-03T07:47:09.379+0000 I CONTROL [main]
- mongos> db.printShardingStatus();
- --- Sharding Status ---
- sharding version: {
- "_id" : 1,
- "minCompatibleVersion" : 5,
- "currentVersion" : 6,
- "clusterId" : ObjectId("5aeabc4db192a4fefca1c888")
- }
- shards:
- { "_id" : "shard1", "host" : "shard1/10.1.2.175:27019,10.1.2.183:27019,10.1.2.32:27019,10.1.2.68:27019", "state" : 1 } ---新的复制集成员自动同步到分片信息了
- { "_id" : "shard2", "host" : "shard2/10.1.2.175:27018,10.1.2.32:27018,10.1.2.68:27018", "state" : 1 }
- { "_id" : "shard3", "host" : "shard3/10.1.2.175:27017,10.1.2.32:27017,10.1.2.68:27017", "state" : 1 }
- active mongoses:
- "3.6.4" : 3
- 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:
- No recent migrations
- databases:
- { "_id" : "config", "primary" : "config", "partitioned" : true }
- config.system.sessions
- shard key: { "_id" : 1 }
- unique: false
- balancing: true
- chunks:
- shard1 1
- { "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : shard1 Timestamp(1, 0)
- { "_id" : "test", "primary" : "shard2", "partitioned" : true }
- test.users
- shard key: { "_id" : 1 }
- unique: false
- balancing: true
- chunks:
- shard2 1
- { "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : shard2 Timestamp(1, 0)
- mongos> ;
4.最后修改下配置文件
- 避免重启问题,写入配置文件
- [root@ip-10-1-2-32 etc]# more mongos.conf
- logpath=/usr/local/mongodb/logs/mongos.log
- logappend=true # need logrotae scripts
- fork=true
- port=30000
- pidfilepath=/usr/local/mongodb/logs/mongos.pid
- configdb=conf/10.1.2.32:27000,10.1.2.68:27000,10.1.2.175:27000,10.1.2.183:27000
- bind_ip=10.1.2.32
成员
文件
配置
成功
信息
机器
端口
节点
过程
问题
加成
同步
检查
登陆
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
数据库自动生成一个txt文件
电报机软件开发
果蔬分拣系统软件开发
对等网络安全ppt
域名与云服务器
服务器存储方案下载
静海区应用软件开发供应
硬盘怎么合并保留数据库
软件开发中心需要做柜员吗
网络技术研究生招生简章
数据库原理与应用 吴靖
架设aaa服务器
金昌天气预报软件开发
如何进入微信的服务器后台数据
我的世界附魔装备好服务器推荐
加强网络安全意识教育目标
熙珠网络技术直播
高考网络安全分数
网络安全总监吴迪
联想是什么品牌的服务器
北京电商软件开发定做
软件开发许可证怎么办理
怎样从其他表格内提取数据库
企业客户网银登录找不到服务器
ssh连接服务器端口填多少
广州福盈网络技术有限公司人事
跑腿软件开发文档
小喇叭下载软件开发
数据库上的安全软件
服务器pmi是什么意思