多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# mongo常用副本集常用操作命令 ### 集群配置 ``` config={ _id:"goumin", members:[ {_id:0,host:'192.168.56.200:27017',priority:10}, {_id:1,host:'192.168.56.201:27018',priority:5},{_id:2,host:'192.168.56.202:27019',priority:5}]}; ``` ### 初始化集群 ``` rs.initiate(config); ``` ### 副本可读 ``` rs.slaveOk(); ``` ### 写入测试数据 ``` goumin:PRIMARY> for(var i=0;i<1000;i++)db.c.insert({uid:i,uname:'osqlfan'+i}); goumin:PRIMARY> db.c.find().count(); 1000000 ``` ### 查看集群状态 ``` goumin:PRIMARY> db.stats(); ``` ### 设置副本启动可读写 ``` root@db200:~# cat .mongorc.js rs.slaveOk(); ``` ### 关闭命令 ``` /usr/local/mongodb/bin/mongo localhost:27017<<EOF use admin db.shutdownServer() EOF ``` ### 启动命令 ``` /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/etc/mongodb.conf ``` ### 移除节点 ``` rs.remove("192.168.5.22:27017"); ``` ### 添加节点 ``` rs.add("192.168.5.26:27017"); ``` ### 主库降级 ``` rs.stepDown() ```