配置文件
1-3为三个存储节点,其实一个为Primary,两个secondary作为备份,4为仲裁节点
mongo.conf
执行配置
mongod -f conf.conf
设定副本集合:
mongo --port 33198
use admin
db.runCommand({"replSetInitiate":{
"_id":"android-test",
"members":[
{
"_id":1,
"host":"127.0.0.1:33198"
},
{
"_id":2,
"host":"127.0.0.1:33197"
},
{
"_id":3,
"host":"127.0.0.1:33196"
}
]}})
增加仲裁节点
rs.addArb("127.0.0.1:33195")
#!/usr/bin/env python #-*- encoding:utf-8 -*- from pymongo import MongoClient, MongoReplicaSetClient dbList = '127.0.0.1:33198,127.0.0.1:33197,127.0.0.1:33196' def init(dbname): try: client = MongoReplicaSetClient(dbList, replicaSet='android- test') db = client[dbname] return db except Exception as e: print 'error:%s'%e return False if __name__ == '__main__': db = init('test') print db.appinfo.find_one()
本文转自cococo点点博客园博客,原文链接:http://www.cnblogs.com/coder2012/p/4130695.html,如需转载请自行联系原作者