mongodb(6)Update Version and HA Proxy
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