Network in a Box Part 2
Long, long, looong time ago I wrote about setting up a virtual network using XEN virtual machines, with everything running on the same server. In the first part of this post I’ve mostly described my 2-day experience with making this work and now I’m simply going to copy & paste a README file I’ve created for myself to remember what exactly needs to be done to get such a setup up and running.
This file describes how to create a load-balanced virtual network of XEN guests (virtual machines) on a XEN Debian server. It is assumed that the XEN server and xen-tools are already installed. Step 1: Creating the XEN virtual machine using CentOS as guest OS ------- - Fix rinse installation of CentOS 5. Add the following lines to /etc/rinse/centos-5.packages: nss nspr python-iniparse - Optionally, install the packages for CentOS 5 version from a new location. Modify /etc/rinse/rinse.conf: [centos-5] mirror = http://mirror.bytemark.co.uk/centos/5/os/i386/CentOS/ mirror.amd64 = http://mirror.bytemark.co.uk/centos/5/os/x86_64/CentOS/ - Create the XEN virtual machine with the following command. Modify parameters to suit needs: xen-create-image --hostname node01 --dist centos-5 --install-method \ rinse --size 4Gb --swap 1Gb --memory 2Gb --ip 192.168.1.101 \ --netmask 255.255.255.0 --gateway 192.168.1.1 --passwd Step 2: Bring the new virtual machine online and open a console to it ------- - Run the following command: xm create /etc/xen/node01.cfg -c Step 3: Set up the network settings on the node ------- echo 1 > /proc/sys/net/ipv4/ip_forward echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce echo 1 > /proc/sys/net/ipv4/conf/eth0/arp_ignore echo 2 > /proc/sys/net/ipv4/conf/eth0/arp_announce - Setup the ipip tunnel to the load balancer: ifconfig tunl0 <public IP of load-balancer> netmask 255.255.255.255 - Optionally, set up another public IP address on eth0:1 (to access this node directly, which is good when developing or debugging): On the node, type: ifconfig eth0:1 <IP> broadcast <IP> netmask 255.255.255.255 On the gateway (XEN server / Dom0), type: route add -host <IP> <vifX.Y> The vifX.Y must be the one used by XEN for the virtual machine on which the node runs. Step 4: Install and start the HTTP server ------- yum install httpd.x86_64 echo "node01" > /var/www/html/index.html echo "ok" > /var/www/html/status.html /etc/init.d/httpd start The status.html file is used by the load balancer to determine if the node is online or not so that it knows if it can use it. Step 5: Configure the load balancer to use the new node ------- On the load balancer node (lb), edit /etc/ha.d/conf/ldirectord.cf: real=192.168.1.101:80 ipip 10 Test that the new node is load-balanced (you should see node01 after a few refreshes, in case you have more than 1 node): http://<public Load-balancer IP address>/
A few remarks:
- You need at least 2 public IP addresses on your server, but I would recommend 3 or more. One will be used by the server itself (to connect to Dom0), one will be used by the load balancer (your web requests will go to that IP and will be distributed among the available nodes) and at least another one should be assigned to one of the nodes to access it directly and not through the load balancer, which is very important for development and debugging of your load-balanced application.
- The load balancer in my setup is another (virtual) node of the system… a XEN guest. This is needed because the load balancer cannot be on the same machine as the router for your virtual network, which will be Dom0 (i.e.: the main server itself, on which XEN and everything else runs). Why not? Well, because if you use the same IP for both your router and your load balancer when a packet is sent from one of your end nodes to a client it will have the source IP set to the public IP of the load balancer. Now, the router will receive a packet from “outside” that needs to be routed with the same IP address as its own IP address and will say “no, no! this isn’t right” and will drop that packet as being “source martian”. Google a bit for “source martian problem” and you’ll get a clearer picture.
