Archive

Archive for the ‘High Availability’ Category

RabbitMQ users queues exchanges bindings import export

June 19, 2015 2 comments

All I see it’s dead world
And I know that’s our fault
Living Absent minded
(Archeon – Dead World)

If you want to deploy test RabbitMQ, migrate from one node/cluster to another one or just back up your Rabbit metadata, there is a simple way to do it through RabbitMQ API.

API is available at http://rabbitmq:15762/api/ – with most of the documentation. To back up metadata, simply run:

$ curl -i -u <username>:<password> http://rabbitmq:15672/api/definitions

Output is in JSON format, and you can save it in a file by redirecting curl output to a file.
Later if you decide to restore the saved file to another (or same) Rabbit instance, it’s a single line command again:

$ curl -i -u <username>:<password>   \
  -H "content-type:application/json" \
  -X POST                            \
  --data @/tmp/rabbit_defs           \
  http://rabbitmq-new:15672/api/definitions

And that’s it!

Advertisements

HaProxy error 503 if dependencies are down

November 16, 2014 Leave a comment

Revenge
I’m screaming revenge again
Wrong
I’ve been wrong for far too long
(Pantera – Mouth for War)

Every http app usually has a number of dependencies – like database (PostgreSQL or MySQL), caching layers (memcache, redis) or NoSQL backends like MongoDB. In case any of those dependencies are down, it’s good to inform public about it in a neat way. If you fail to do that, search engines will probably down rank your site. General advice from SEO sites is to avoid returning 200 OK or 404 Not Found when you want to inform users that site is down. In case of downtime, proper way to inform users (which include crawlers too) is to retutrn 503 Service Unavailable.

If your site depends heavily on some service like MySQL and won’t work without it, this check can be done at load balancer (HaProxy) level. Configuration is simple – first step is to create a user in MySQL database for MySQL check:

$ mysql -u root -e "INSERT INTO mysql.user (Host,User) \
  values ('127.0.0.1','haproxy_check'); FLUSH PRIVILEGES;" -p

HaProxy uses this database user for functional checks (runs SELECT(1)). HaProxy config file should look like this:

backend myhttpdfarm
        option httpchk HEAD /check.txt HTTP/1.0
        server web01 127.0.0.1:80 weight 1 web01

backend mysql
        option mysql-check user haproxy_check
        server mysql_master 127.0.0.1:3306 check

listen main
        bind    127.0.0.1:80
        errorfile 503 /etc/haproxy/503.html
        use_backend myhttpdfarm if { srv_is_up(mysql/mysql_master) eq 1 }

Crucial part is “us_backend … if” directive. You can even chain conditionals, and add additional checks for memcache, Mongo, etc…

%d bloggers like this: