关闭:
1:分别关闭三个分片
[ec2-user@mg2 mongo-conf]$ mongo --port 27017 #27017分片端口号
MongoDB shell version v3.6.6
connecting to: mongodb://127.0.0.1:27017/
MongoDB server version: 3.6.5
Server has startup warnings:
shard1:SECONDARY>rs.stepDown()
shard1:SECONDARY>use admin
shard1:SECONDARY>db.shutdownServer()
2:配置服务器
[ec2-user@mg2 mongo-conf]$ mongo --port 30000 #30000配置端口号
MongoDB shell version v3.6.6
connecting to: mongodb://127.0.0.1:30000/
MongoDB server version: 3.6.5
Server has startup warnings:
shard1:SECONDARY>rs.stepdown()
shard1:SECONDARY>use admin
shard1:SECONDARY>db.shutdownServer()
3:关闭服务器
[ec2-user@mg2 mongo-conf]$ reboot
启动:
4:关闭自带的mongo
[ec2-user@mg2 mongo-conf]$ sudo service mongod stop
5:启动config
[ec2-user@mg2 mongo-conf]$ sudo mongod -f configsvr.conf
[ec2-user@mg2 mongo-conf]$ mongo --port 30000 #检查
6:脚本启动分片
[ec2-user@mg2 mongo-conf]$ ./start_shard1.sh
[ec2-user@mg2 mongo-conf]$ ./start_shard2.sh
[ec2-user@mg2 mongo-conf]$ ./start_shard3.sh
7.启动mongo
[ec2-user@mg2 mongo-conf]$ sudo mongos -f mongos.conf
8:检查
[ec2-user@mg2 mongo-conf]$ mongostat -h localhost:27017
[ec2-user@mg2 mongo-conf]$ mongostat -h localhost:27018
[ec2-user@mg2 mongo-conf]$ mongostat -h localhost:27019
[ec2-user@mg2 mongo-conf]$ mongo --port 27017 #检查节点关系
[ec2-user@mg2 mongo-conf]$ mongo --port 27018 #检查
[ec2-user@mg2 mongo-conf]$ mongo --port 27019 #检查
9:切掉一台服务器的双主分片
若mg1有两个分片 为 PRIMARY
,可在其中一分片进行切换,执行如下命令:
shard2:PRIMARY> rs.stepdown()