VoIP, Linux, Security & much more fun
If you need any help regarding these subjects do not hesitate about sending me a text
north-america-servers-and-users.png

These days all is in the cloud. Being in the cloud means your service or information is on someone's server without knowing exactly where it is. Being in the cloud is as easy as renting some VPS'es. Now you are "in" with the technology, but that it is not enough. Depending your business, you may be worried about being online as much as possible and at the same time to keep your costs down. If you do an Internet search, you will find that the most common high availability option is having all servers in the same datacenter by sharing an IP (also known as floating IP). This could work, but you will have all your eggs in the same nest (not very smart for high availability), there are some VPS companies with this option, but again, in order to allow the IP switch the containers must be in the same collision domain (that not always is the same sub-network) which it means again, all eggs in the same nest.

Well, today is your lucky day, there is another approach that allows high availability: the smart DNS balancing. DNS will let the end-points get the correct IP depending some network, software and business conditions. This means that you can have VPS'es spread around the world, and depending the real-time decision they may get IP A or IP Z. If you do a little research, you will find some professional solutions such as F5 which it is crazy expensive and it is really a headache to make it work properly. So, I have my own solution: my very own smart DNS software.

I will introduce this software to you and I will show a brief setup.

Smart DNS

This software I have coded (ANSI C if you wonder the language) answers an IP depending many conditions. In this article. I am going to talk about the Less Latency connection. The name is very descriptive, the DNS will send you to the server that it believes you will have less latency (usually the closest one). You may think this could be archived by IP Geolocalization, but you are half wrong. IP Geolocalization may your servers are in a small country, let's call it Andorra for example. Most VPS'es are hosted in the USA. USA, Canada, Russia are countries where the city you are hosting matters; France, Germany, and many European countries have more than one border, servers in countries close to the border may not be the fastest for that country, take for example Roubaix, France (where OVH hosts its servers), it is very close to German border. Some cities from Germany may have a better latency rather than cities within France close to the Spanish border. These are the case where IP Geolocalization will fail.

Installation of Smart DNS Server

With all this said, let's start with installation. At this very moment, the only way to get the software is by installing RPM's. You would need to install OKay's RPM repository for Centos 6 or 7. You will find the following packages:

  • low-latency-pdns-plugin.x86_64 : low-latency-pdns allows you to resolve IPs based on different criteria.
  • low-latency-pdns-plugin-check-dns.x86_64 : low-latency-pdns check DNS scripts
  • low-latency-pdns-plugin-check-latency.x86_64 : low-latency-pdns check latency scripts
  • low-latency-pdns-plugin-monitoring.x86_64 : low-latency-pdns monitoring scripts

When you install it, PowerDNS will be required with some additional dependencies.

Configuration of Smart DNS Server

Do the following configuration in the pdns.conf file:

setuid=pdns
setgid=pdns
launch=pipe,bind
pipe-command=/usr/libexec/low-latency-pdns-plugin/latency.pdns.plugin
pipe-regex=^.*\.(inside-out)\.(xyz);.*$
bind-config=/etc/pdns/bind.conf
bind-check-interval=300

This configuration tells PowerDNS to send the queries of the domain inside-out.xyz to the smart plugin. If for a reason the plugin answers with no result, PowerDNS will forward the answer to the bind plugin, which it should answer with a static answer.

Configuration fo the Database for the Smart DNS Server

The next step is to create the database structure. You can read the script at /usr/libexec/low-latency-pdns-plugin/configure.database. Please take note of the input data as you will need it later. If for a reason you can not execute the script, what it matters is the data structure, if you read it, you will find the MySQL queries you will need to run. When you are done, edit the file /etc/sysconfig/low-latency-pdns-plugin with correct database information.

  • MYSQL_HOSTNAME=127.0.0.1
  • MYSQL_USER=root
  • MYSQL_PASSWORD=f1l3m0n3lgr4nd3
  • MYSQL_DB=latency
  • MYSQL_PORT=3306
  • DEBUG=1
  • PEERS=('127.0.0.1')

The MYSQL_* options are self-explained, DEBUG allows you to see more messages than usual. PEERS variable is an array where you must list all your peers in the cluster. It really does not matter if they are using hostnames or IP addresses.

Configuring the Smart DNS Plugin

Next step is to configure the plugin. The first step is to contact OKay directly to get a license. As this is a personal blog, I can only say that licensing model is based on the balancing algorithm and domain name. Licenses look like 40bd001563085fc35165329ea1ff5c5ecbdbbeef. When you get it, edit the file /etc/latency.pdns.plugin.conf. Most parameters are self-explained, but I will list them here.

[Application]
Version = 1.2.0
License = da9cc627d31758c037d5c96adfbb19e4c369b83d
Debug = true

[DNS]
Zone = inside-out.xyz
Email = This email address is being protected from spambots. You need JavaScript enabled to view it.
NS1 = ns1.isp.net
NS2 = ns2.isp.net
TTL = 60

[DB]
Type = mysql
Server = 127.0.0.1
User = mysql_user
Password = mysql_user_password
Port = 3306
Database = latency

[Memcached]
Server = 127.0.0.1
Port = 11211
TTL = 60

The application section must have the license and the correct version. DNS section must have basic DNS information, such as the zone name, email of zone responsible (this will be used when answering the SOA request) and at least two name servers. Please don't mix domains here, as it could happen to be an infinity loop. Database section will need the same information you entered in the last step when configuring the database). The mMemcached section is just to let the plugin where to store information. Memcaching is used to speed up request, especially when they are very frequent.

Configuration of the Crontabs

Crontabs play a very important role in this solution. Please read and edit the /usr/libexec/low-latency-pdns-plugin/check.client.latency to fit your needs.

Good Luck!

blog comments powered by Disqus
If you need more help than the free one provided here...