-1

I have two replicated LAMP servers, one as slave and the other as master:

Master: Name = master.kimsufi.com - IP = 5.5.5.1
Slave:  Name = slave.kimsufi.com  - IP = 5.5.5.2

(as you can see, both are registered with kimsufi)

With these servers and without an additional IP address, my purpose is host a www.domain.com with Master and in case it fails transfer the control to the slave (I know there is software like Heartbeat that allows this but needs a virtual IP, it is, an additional IP address and Kimsufi doesn't allow that ).

I was thinking in this problem and "found" a possible solution that I'm sure is not valid because I haven't found it published anywhere (and my network knowledge is low). May be you can help me to see the problem.

The idea is to add a DNS server in each server and configure the slave as a backup server in case Master cannot resolve. More or less the idea is to setup in the register domain.com something like this:

Primary DNS: Master (5.5.5.1)
Secondary DNS: Slave (5.5.5.2)

Then, the Master server will be configured as usual, pointing his bind9 service to the Master server:

$TTL        86400
@       IN      SOA     master.kimsufi.com. user.gmail.com. (
                        2014011302       ; serial, todays date + todays serial #
                        28800              ; refresh, seconds
                        7200              ; retry, seconds
                        604800              ; expire, seconds
                        86400 )            ; minimum, seconds
;

domain.com.   86400 A        5.5.5.1
domain.com.      NS        master.kimsufi.com.
domain.com.      NS        slave.kimsufi.com.
www           86400 A        5.5.5.1

And the slave:

$TTL        86400
@       IN      SOA     slave.kimsufi.com. user.gmail.com. (
                        2014011304       ; serial, todays date + todays serial #
                        28800              ; refresh, seconds
                        7200              ; retry, seconds
                        604800              ; expire, seconds
                        86400 )            ; minimum, seconds
;

domain.com.   86400 A        5.5.5.2
domain.com.      NS        master.kimsufi.com.
domain.com.      NS        slave.kimsufi.com.
www           86400 A        5.5.5.2

So if you try a dig with this you'll get something like:

ivan@local:~$ dig domain.com NS

; <<>> DiG 9.8.4-rpz2+rl005.12-P1 <<>> domain.com NS
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 33268
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;domain.com.            IN  NS

;; ANSWER SECTION:
domain.com.     86400   IN  NS  master.kimsufi.com.
domain.com.     86400   IN  NS  slave.kimsufi.com.

;; Query time: 87 msec
;; SERVER: 192.168.1.1#53(192.168.1.1)
;; WHEN: Wed Jan 14 15:30:11 2015
;; MSG SIZE  rcvd: 78

The idea is that as Master is the primary name server, it will process any query for domain.com but if it is offline, Slave do the job.

I haven't tested it, it's just an idea (currently I only own a server at kimsufi). Is it possible? What are the fail in this scheme?

Ivan
  • 192
  • 2
  • 11
  • 1
    Please take a moment to review [Should we host our own nameservers?](http://serverfault.com/questions/23744/should-we-host-our-own-nameservers). It's laudable that you're asking questions before trying to implement things that you don't understand, but running your own DNS servers without a mentor is *very dangerous* for everyone involved. If you must continue, you would be best served by buying a book on the topic and sitting down with it for the weekend. Right now you do not have a good grasp of the basics. – Andrew B Jan 14 '15 at 16:05
  • 1
    I know, that's why I'm asking :) And of course, I'm reading everything I can about this. Thanks for the link. – Ivan Jan 14 '15 at 18:04

2 Answers2

2

The failure in that scheme is that DNS in a master/slave setup can not actually serve different records for a single domain. In fact, the slave server should receive the zone file from the master to ensure it is serving the exact same information.

NickW
  • 10,183
  • 1
  • 18
  • 26
  • Yes, true. That's the theory, but in practice, what happens if the records are differents? May be nothing works at all? :) – Ivan Jan 14 '15 at 15:36
  • 1
    Well for sure your DNS servers will complain about it, and so will anyone who goes to verify information on your domain.. – NickW Jan 14 '15 at 15:42
  • 2
    More importantly, the ordering has no bearing on which DNS server will be hit first. It's random. And if it is able to get a response from the first one tried, there's no attempt to hit the second server. – Andrew B Jan 14 '15 at 15:46
2

First of all you need to setup your dns servers properly.

Your setup is somewhat unorthodox and it will probably fail on standard checks (for example your SOA record must be the same on all nameservers serving the zone)

The proper way to setup a Master/Slave DNS server is that you setup your master and configure the slave to AXFR transfer the zone to it from the master.

So both DNS servers will serve requests at any time and any changes to the zone should be done only on the master server. After any changes you simply reload the zone on the master and it will be automatically transferred to the slave as well.

There are numerous tutorials on the web on how to setup any DNS server with a master/slave configuration.

With a standard Master/Slave configuration with zone-transfers you don't have to worry about failovers in the DNS level.
Those are automatically handled by the DNS protocol itself.
So if one nameserver is down, the DNS resolver querying your domain will automatically go to the next available Nameserver (as defined in the NS records of your zonefile)

Now to serve your HTTP traffic you simply add 2 A records pointing to the 2 servers' IPs.

domain.com.   86400 A        5.5.5.1
domain.com.   86400 A        5.5.5.2
www           86400 A        5.5.5.1
www           86400 A        5.5.5.2

This way when the browser wants to connect to the website, it will see that there are 2 IPs serving the website, and it will choose the first one that the DNS server responded with. If that IP does not respond to any requests then it will automatically try the next one.

The same goes if an IP is working and then is suddenly stops responding to requests. The browser will automatically switch to the next IP (with some delay of course the first time)

Essentially with having 2 A records you get High Availability/Redundancy plus Load Balancing since the DNS servers will serve the IPs in a round-robin fashion to the clients.

Keep in mind though that the above setup requires that both servers have the exact same content to serve.
So if your website is dynamic with a database backend you should probably have to configure database master-master replication, a way of replicating sessions (if that's important to the website) and some way of replicating the files as well.

Again, this is highly dependent on your website so there is no one-solution-for-all

Cha0s
  • 2,432
  • 2
  • 15
  • 26
  • I've never heard about that: 2 A records are "free" load balancing? That's great! What are the drawbacks of this technique? I've tested a bit and I've seen that gmail.com (dig gmail.com) has two A records with two different IPs. Nice – Ivan Jan 14 '15 at 15:38
  • I guess it depends on what you need to do. One drawback is that you don't have control over which server each client will connect. Also you may not have to implement a failover mechanism for the DNS but you will have to implement a replication mechanism for the website itself (database, files, sessions, etc). Depending on the design and architecture of the website this might be quite difficult or even impossible. – Cha0s Jan 14 '15 at 15:43
  • 1
    Also, it's important to keep in mind that while many web browsers know how to perform round robin failover, *most other applications do not*. – Andrew B Jan 14 '15 at 15:49