The MongoDB cluster uses the replication set mode, at least 3 nodes or more. One question is, how do I let ceilometer automatically connect to the re-elected master node when the MongoDB master node is down?
Here are two solutions, as for which to look at the demand.
1, using VIP to locate the MongoDB master node
Use keepalived to start VIP, here are two vip,vrrp_instance vi_1 is dedicated to MongoDB vip,vrrp_instance vi_2 is OpenStack ha vip
VRRP script Chk_mongo_primary scripts specifically to detect whether the node is MONGO master node, if it is the weight of +2, and Vrrp_instance vi_1 VIP can be preempted;
When the MongoDB master node is switched on, Vrrp_instance Vi_1 's VIP will also switch.
keepalived.conf configuration file
! configuration file for keepalivedvrrp_script chk_haproxy { script "Killall -0 haproxy" interval 2 weight 2}# Define the script used to check if mongod is runningvrrp_script chk_mongod { script "killall -0 Mongod " interval 2 # every two seconds weight 2}# define the script to see if the local node is the primaryvrrp_script chk_mongo_primary { script "MONGO --eval ' (!! Db.runcommand ("IsMaster") ["IsMaster"])? Quit (0): Quit (1) ' " interval 2 # every two seconds weight 2}# configuation for the Virtual interfacevrrp_instance VI_1 { interface br-ex state node master # slave on the other nodes priority 101 # 100 on other nodes virtual_ router_id 55 authentication { auth_type pass auth_pass secret # Set this to some secret phrase } # the virtual ip address shared between the two nodes virtual_ipaddress { 172.16.140.251/24 &nBSP;} # Use the script above to check if we should fail over track_script { chk_mongod chk_mongo_primary }}vrrp_instance VI_2 { interface br-ex virtual_router_id 51 state backup priority 200# if use it,the openstack api do not response normally# use_vmac virtualmac# advert_int 1 dont_track_primary nopreempt authentication { auth_type PASS auth_pass password } virtual_ipaddress { 172.16.140.250/24 } track_script { chk_haproxy }   NOTIFY /USR/LOCAL/BIN/KEEPALIVEDNOTIFY.SH}
2, the use of Haproxy Tcp-check to detect
Haproyx MongoDB Configuration
Listen mongodb_cluster bind openstack_vip:27017 option tcpka option tcplog option tcp-check # MongoDB Wire Protocol tcp-check send-binary 3a000000 # message length ( tcp-check send-binary ) eeeeeeee # request id (Random value) tcp-check send-binary 00000000 # response to (Nothing) tcp-check send-binary d4070000 # opcode (Query) tcp-check send-binary 00000000 # Query Flags tcp-check send-binary 61646d696e2e # fullcollectionname (admin. $cmd) tcp-check send-binary 24636d6400 # continued tcp-check send-binary 00000000 # numtoskip Tcp-check send-binary ffffffff # numtoreturn # start of Document tcp-check send-binary 13000000 # Document length tcp-check send-binary 10 # Type (Int32) tcp-check send-binary 69736d617374657200 # ismaster: tcp-check send-binary 01000000 # Value : 1 Tcp-check send-binary 00 # term tcp-check expect binary 69736d61737465720001 #ismaster true server controller1 controller1:27017 check inter 2000 rise 2 fall 3 server controlLer2 controller2:27017 check inter 2000 rise 2 fall 3
Here's the problem, the non-master nodes that you see on the Haproxy monitoring page are down, because of Tcp-check's sake.
Why did Send-binary write that ? (with Tcpdum grab bag out, get Wireshark analysis)
For details, see here: https://blog.danman.eu/mongodb-haproxy/
Http://serverfault.com/questions/625492/how-to-construct-a-mongodb-health-check-in-haproxy
This article is from the "The-way-to-cloud" blog, make sure to keep this source http://iceyao.blog.51cto.com/9426658/1836237
Haproxy Proxy MongoDB