【Mongodb】分片复制集环境添加新的分片
发表于:2025-11-12 作者:千家信息网编辑
千家信息网最后更新 2025年11月12日,1.每个节点上分别创建新的shard3配置文件[root@ip-10-1-2-68 etc]# more shard3.conflogpath=/usr/local/mongodb/logs/mong
千家信息网最后更新 2025年11月12日【Mongodb】分片复制集环境添加新的分片1.每个节点上分别创建新的shard3配置文件
2. 每个节点启动shard3 服务
3.登陆第一个节点,搭建shard3的复制集
4.登陆第一个节点的mongs端口,将shard3分片加入分片组
5、设置均衡器
参考:https://docs.mongodb.com/manual/reference/method/sh.getBalancerState/
- [root@ip-10-1-2-68 etc]# more shard3.conf
- logpath=/usr/local/mongodb/logs/mongo_shard3.log
- logappend=true # need logrotae scripts
- fork=true
- journal=true
- port=27017
- #vvvvv = true
- #diaglog = 3
- dbpath=/usr/local/mongodb/shard3
- pidfilepath=/usr/local/mongodb/logs/mongo_shard3.pid
- bind_ip=10.1.2.68 ---bind ip 修改为自己的机器
- replSet=shard3
- shardsvr=true
2. 每个节点启动shard3 服务
- [root@ip-10-1-2-68 etc]# /usr/local/mongodb/bin/mongod -f shard3.conf
3.登陆第一个节点,搭建shard3的复制集
- [root@ip-10-1-2-32 etc]# /usr/local/mongodb/bin/mongo 10.1.2.32:27017
- MongoDB shell version v3.6.4
- connecting to: mongodb://10.1.2.32:27017/test
- MongoDB server version: 3.6.4
- Server has startup warnings:
- 2018-05-08T03:26:23.290+0000 I CONTROL [initandlisten]
- 2018-05-08T03:26:23.290+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
- 2018-05-08T03:26:23.290+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
- 2018-05-08T03:26:23.290+0000 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
- 2018-05-08T03:26:23.290+0000 I CONTROL [initandlisten]
- 2018-05-08T03:26:23.290+0000 I CONTROL [initandlisten]
- 2018-05-08T03:26:23.290+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
- 2018-05-08T03:26:23.290+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
- 2018-05-08T03:26:23.290+0000 I CONTROL [initandlisten]
- 2018-05-08T03:26:23.290+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
- 2018-05-08T03:26:23.290+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
- 2018-05-08T03:26:23.290+0000 I CONTROL [initandlisten]
- > config_rs3 = {_id: 'shard3', members: [{_id: 0, host: '10.1.2.32:27017', priority:1}, {_id: 1, host: '10.1.2.68:27017'},{_id: 2, host: '10.1.2.175:27017'}]}
- {
- "_id" : "shard3",
- "members" : [
- {
- "_id" : 0,
- "host" : "10.1.2.32:27017",
- "priority" : 1
- },
- {
- "_id" : 1,
- "host" : "10.1.2.68:27017"
- },
- {
- "_id" : 2,
- "host" : "10.1.2.175:27017"
- }
- ]
- }
- > rs.initiate(config_rs3);
- { "ok" : 1 }
4.登陆第一个节点的mongs端口,将shard3分片加入分片组
- [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> use admin;
- switched to db admin
- mongos> db.runCommand({ addshard: 'shard3/10.1.2.32:27017,10.1.2.68:27017,10.1.2.175:27017'})
- {
- "shardAdded" : "shard3",
- "ok" : 1,
- "$clusterTime" : {
- "clusterTime" : Timestamp(1525750332, 7),
- "signature" : {
- "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
- "keyId" : NumberLong(0)
- }
- },
- "operationTime" : Timestamp(1525750332, 7)
- }
- 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.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)
5、设置均衡器
- # 查看状态
- mongos> sh.isBalancerRunning();
- false
- # 设置均衡器
- mongos> sh.setBalancerState(true);
- mongos> sh.enableBalancing("bg")
- mongos> sh.getBalancerState()
true
参考:https://docs.mongodb.com/manual/reference/method/sh.getBalancerState/
节点
均衡
均衡器
登陆
信息
文件
机器
状态
端口
参考
服务
配置
环境
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
网络安全为人民宣传活动
威廉斯托林斯的现代网络技术
做软件开发的怎么找客户
云隙服务器的ip
数据库是汉字 到了前端
互联网科技设计公司简介
修改服务器管理员
软件开发三年规划方案
数据库技术与应用牛莉
远程管理csgo服务器
什么服务器运维管理好
skywars服务器地址
数据库2016自动备份
数据库输出到页面乱码
网络技术和互联网是一回事吗
年龄为奇数怎么表示数据库
网络安全认证技术缺点
淮北点餐系统软件开发公司哪家好
针对网络安全小学生课间
网络安全批评与自我批评
上海软件开发工程师年薪
怎么弹出网络安全认证
互联网招聘软件开发
遗传算法是哪个数据库的检索方法
云服务器你本地电脑如何相互通信
黑色沙漠单机数据库连接
学校网络安全和信息化材料
软件开发项目框架协议和资源池
小程序买什么数据库
pubmed数据库中作者格式