Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Since now, I used the vhost feature of apache2 to bind multiple domains to one public and static ip.

Now I'm setting up a XEN Host with 4 IPs, and several VMs, two of them are pure webservers. It's possible for these to 2 VMs to share one public ip? Eachone would have a set of vhosts on the same public ip.

alt text

Edit: Okay, what about a Host based redirection? alt text

share|improve this question
    
I just care about HTTP(S) Requests on Port 80 or 443. Everything can be handled by NATing. –  Henrik P. Hessel Jul 9 '09 at 14:13
    
+else ..damn you stress :) –  Henrik P. Hessel Jul 9 '09 at 14:13
add comment

7 Answers

up vote 7 down vote accepted

If you only care about serving http, you most likely want to install a software load balancer / reverse proxy like Pound. The configuration on the Xen host would (again-- most likely) look like

ListenHTTP
            Address xx.xx.xx.xx
            Port    80

            Service
                BackEnd
                    Address ip.of.webserver.1
                    Port    80
                End
                BackEnd
                    Address ip.of.webserver.2
                    Port    80
                End
            End
End

You'll also need to setup forwarding and iptables rules on the Xen host; it may already be setup for that.

share|improve this answer
    
Nice mention of Pound, was gonna suggest it. –  Karolis T. Jul 9 '09 at 14:10
add comment

I don't think you would be able to split the requests going to both servers if they are the same IP?

Why do you need to set them on the same IP?

nice diagram though

share|improve this answer
    
Apache2 vhost feature serves the correct website by reading out the request header. Why shoudn't it possible to "split" the requests on level above? –  Henrik P. Hessel Jul 9 '09 at 13:57
    
I would of thought you would need to split the request before is get to the apache server? so from DNS or a server above to know where to route say bob.intranet > xxx.xxx.xxx.xxx –  Rodent43 Jul 9 '09 at 13:58
    
Right, something like this: microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/… –  Henrik P. Hessel Jul 9 '09 at 14:00
    
But is that not referring to hosts on one server not multiple servers with same IP? If it is possible I would love to know how and I don't want to sound offensive, I just cant see how the requests would know which server is which unless you could use ports for traffic so only one IP listens on specific ports? but then i'm not sure it would be split before it gets to V Machines? –  Rodent43 Jul 9 '09 at 14:04
    
From my point of perspective, it's always better to ask "is it possible?" and to hear "no, it isn't!" then never asked it and thinking "it's just impossible". I appreciated your contribution, though. –  Henrik P. Hessel Jul 9 '09 at 14:18
show 1 more comment

As radius and the others say, I don't believe that it's possible to do it just by giving the servers the same IP (they'll complain about duplicate addresses and one of them will end up IP-less), or the same secondary IP (as above, but harder to troubleshoot).

A better option would be either round-robin DNS, where you can add the IPs of each webserver to the same "A" record, and a query for that "A" record will return either a different address each time, or a list of addresses for your clients to choose from. Another option would be to add some kind of load-balancing app in front of the two webservers to route traffic to each one equally (or just to one, with the other as a failvover) You can do this with another instance of Apache with mod_proxy installed.

Which one of these you want to use depends on why you want to do it - are we talking about some kind of high-availability/clustering thing?

share|improve this answer
    
Dave Cheney has a great answer why would one want to avoid DNS round robin: serverfault.com/questions/6702/… –  Karolis T. Jul 9 '09 at 14:05
    
True, it's a bad idea for doing failover with (although rAyt didn't mention what he was actually trying to achieve with this). I've never used it for anything myself, just sticking it out there in case someone finds it useful. –  RainyRat Jul 9 '09 at 14:58
add comment

You can not have a single IP on both machines at the same time, but you can quickly move it between them.

It seems you're after a load balancing/high availability solution.

I suggest you look into Linux-Ha - Heartbeat [1].

It's basically a daemon that would run on both machines, Webserver 1 and Webserver 2 and send "I'm alive" signals to each other, whenever the signal is not received for a specified amount of time, the other node is assumed dead (or made dead using a STONITH [2] device) and the active node takes everything over.

You can also pick active/passive nodes by hand. Starting from heartbeat v2, it's possible to monitor nodes at resource level, though the configuration is XML based and kind of complex, if you're going to look into it, I suggest using heartbeat-gui to configure it (Ubuntu has a package [3])

Novell has a great free ebook about this stuff [4].

[1] http://www.linux-ha.org/

[2] http://www.linux-ha.org/STONITH

[3] http://packages.ubuntu.com/hardy/admin/heartbeat-gui

[4] http://www.novell.com/documentation/sle_ha/

share|improve this answer
add comment

As per your edit, you can use a reverse proxy. Apache can do that. Pound is another solution already mentioned.

share|improve this answer
    
Not true, what about codinghorror.com/blog/archives/000984.html –  Henrik P. Hessel Jul 9 '09 at 13:53
    
This not sharing the same IP on 2 computers but using a reverse proxy as a workaround. –  radius Jul 9 '09 at 14:07
    
The codinghorror article is about using Windows ISA Server, which looks like the same (basic) thing as Pound. The backend servers actually have different IPs (192.168.0.1 and 192.168.0.2) that ISA forwards requests to. –  Matt Jul 9 '09 at 14:13
add comment

I don't believe anyone is suggesting two VMs with the same IP. I agree with your reply though. You can't have two machines on the same subnet sharing an IP as you would have an ARP table problem.

The only reason for doing this is load balancing and disaster recovery where if one VM fails, traffic and continue to flow to the other VM; however if the physical hardware fails then both VMs are down so I'm not sure what the value is here or with load balancing. I mean you would be load balancing between two VMs on same physical hardware. What's the goal here?

share|improve this answer
    
The Goal is to reduce costs. Each IP Adress costs money. –  Henrik P. Hessel Jul 9 '09 at 15:48
    
Well, two things: (1) You can't reduce cost at the expense of violating basic network fundamentals. You cannot have the same IP on two VMs or machines on the same subnet because your ARP tables would get confused. (2) Not knowing your situation, I can't imagine the cost savings related to reducing IPs! It seems like hair splitting to me but here is a thought. Can you use one public IP and two RFC1918 addresses and not be charged for those? –  Kilo Jul 10 '09 at 0:19
add comment

No, you can't have two servers with the same IP. You will need to get at least one public IP per VM, or do some sort of NATing, but if your going to be serving web pages from these VM's, then you definitely need separate IP's

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.