mongodb(6)Update Version and HA Proxy

本文指导如何更新MongoDB并配置HAProxy,包括复制集初始化、成员添加及状态检查,以及HAProxy配置实现MongoDB集群负载均衡。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

mongodb(6)Update Version and HA Proxy

1. Update the mongodb and configure the cluster
I update the latest version of mongodb, and I copy my old configuration files there as follow:
mongodb-master.conf
mongodb-client1.conf
mongodb-client2.conf

Start them one by one
>mongod -f mongodb-master.conf
>mongod -f mongodb-client1.conf
>mongod -f mongodb-client2.conf

Logon on to the First MongoDB Server
>mongo -host 127.0.0.1 -port 27017

Some Error Message
>> rs.status()
{ "startupStatus" : 3, "info" : "run rs.initiate(...) if not yet done for the set", "ok" : 0, "errmsg" : "can't get local.system.replset config from self or any seed (EMPTYCONFIG)" }

>rs.add("sparkworker1.local:27018")
assert failed : no config object retrievable from local.system.replset Error: assert failed : no config object retrievable from local.system.replset    at Error (<anonymous>)    at doassert (src/mongo/shell/assert.js:11:14)    at assert (src/mongo/shell/assert.js:20:5)    at Function.rs.add (src/mongo/shell/utils.js:977:5)    at (shell):1:4

Solution:
>rs.help()
>rs.initiate()
>rs.add("sparkworker1.local:27018")
>rs.add("sparkworker1.local:27019")

Check the Status
>rs.status()
>db.users.insert({name:"Carl", age:31});
WriteResult({ "nInserted" : 1 })
>db.users.find();
{ "_id" : ObjectId("5372b103116a21a0820f5a66"), "name" : "Carl", "age" : 31 }

Login in the Second Server
>mongo --host 127.0.0.1 --port 27018
>rs.slaveOk();
>db.users.find();
{ "_id" : ObjectId("5372b103116a21a0820f5a66"), "name" : "Carl", "age" : 31 }

2. Configure the HA Proxy in front of Mongo Servers
My mongo servers are running as follow:

127.0.0.1 27017
127.0.0.1 27018
127.0.0.1 27019

The configuration should be as follow:
listen

mongodb_local_cluster 127.0.0.1:27010      

#配置TCP模式      

mode      tcp      

#balance url_param userid      

#balance url_param session_id check_post 64      

#balance hdr(User-Agent)      

#balance hdr(host)      

#balance hdr(Host) use_domain_only      

#balance rdp-cookie      

#balance leastconn      

#balance source 

//ip       #简单的轮询      

balance roundrobin      

#集群节点配置      

server mongo1  127.0.0.1:27017 check inter 5000 rise 2 fall 2      

server mongo2  127.0.0.1:27018 check inter 5000 rise 2 fall 2       

server mongo3  127.0.0.1:27019 check inter 5000 rise 2 fall 2

References:
http://sillycat.iteye.com/blog/1965857 Replica
http://sillycat.iteye.com/blog/2065123 NOSQL latest mongodb



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值