1.给数据库增加分片功能
mongos> use admin
mongos> db.runCommand({enablesharding:"cipnet"})
mongos> db.fs.chunks.ensureIndex({files_id:1})
mongos> db.runCommand({shardcollection:"cipnet.fs.chunks",key:{files_id:1}})
查看分片结果
mongos> use cipnet
mongos> db.fs.chunks.stats()
2.关闭shard复制集中的服务:
查询进程:ps aux|grep mongod
关闭进程:kill -9 XXXX
连接复制集中剩余的服务器:
# /usr/local/mongodb/bin/mongo 192.168.1.196:18001
查询状态:rs.status()
3.增加节点:
在另外一台服务器196上开启一Shard服务(参考上一篇中的Shard1在195上的部署)
添加到现在Replica Sets
rs.add("192.168.1.196:18001")
进行数据同步:
rs.status()
rs.status()
rs.status()
验证数据:rs.slaveOk()
查询数据:db.fs.files.find()
4.减少节点
rs.remove("192.168.1.196:18001")
查看状态:rs.status()
5.设置主从
db.getMongo().setSlaveOk()
主库从库都得执行