[SOLVED] load balancer with direct routing (LVS-DIR)
Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am working on a load balancing project. The type of routing I am implementing is direct routing (LVS-DIR). The following is a script that sets up the Linux Virtual Server (LVS) or the load balancer:
VIPeth00=192.168.2.2 #virtual ip on eth0:0
DIPeth0=192.168.2.3 #public (I know it is not public, just to get this running) real ip for lvs or load balancer on eth0
DIPeth1=192.168.1.1 #private real ip for lvs or load balancer on eth1
RIP1=192.168.1.3 #real server 1 private ip on eth0
RIP2=192.168.1.4 #real server 2 private ip on eth0
BCAST=$VIPeth0 #seeting the broadcast address to VIPeth00
NMASK=255.255.255.255
start () {
echo "Start LVS of Director Server"
#set the VIP and systcl parameter
/sbin/ifconfig eth0 $DIPeth0 up
/sbin/ifconfig eth0:0 $VIPeth00 netmask $NMASK broadcast $BCAST
/sbin/route add -host $DIPeth0 dev eth0
/sbin/ifconfig eth1 $DIPeth1 up
#ip forwarding on the lvs
echo "1" > /proc/sys/net/ipv4/ip_forward
/sbin/sysctl -p
#clear the IPVS table
/sbin/ipvsadm -C
#set LVS with web apache
# -t = TCP protocol
# -s = scheduler
# rr = round robin
# -p 120 = indicates the connection duration to 120 seconds
# -g = gatewaying
/sbin/ipvsadm -A -t $VIPeth00:80 -s rr # -p 120
/sbin/ipvsadm -a -t $VIPeth00:80 -r $RIP1:80 -g
On the LVS:
Interface configurations:
eth0 192.168.2.3
eth0:0 192.168.2.2 (This is the VIP as an alias)
eth1 192.168.2.1
lo 127.0.0.1
Routing tables:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.2.3 0.0.0.0 255.255.255.255 UH 0 0 0 eth0
192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
On the real server 1 (I only have one real server setup so far):
Interface configurations:
eth0 192.168.1.3
lo 127.0.0.1
lo:0 192.168.2.2 (This is the VIP)
Routing tables:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.2.2 0.0.0.0 255.255.255.255 UH 0 0 0 lo
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
On both, the LVS and Real Server 1, the firewalls (iptables) are not running.
A few questions I have are:
1) On the LVS, is apache supposed to be running?
2) If so, what would be the ServerName for apache on the LVS?
3) What would be the ServerName for apache on the real server1, is it the server real IP or the VIP?
When I try to access the web content on real server1 in a browser on the LVS, I get “Failed to Connect”. A connection to the server cannot be established.
The load balancer has two NICS, eth0 and eth1. The real servers will connect to the load balancer via eth1, and the client will connect via eth0.
Please help me find a solution to this problem.
Thanks.
--Willie
On both, the LVS and Real Server 1, the firewalls (iptables) are not running.
A few questions I have are:
1) On the LVS, is apache supposed to be running?
2) If so, what would be the ServerName for apache on the LVS?
3) What would be the ServerName for apache on the real server1, is it the server real IP or the VIP?
1) No, the LVS is directing traffic but not acting as a proxy (Servers like NGINX function in the way you're thinking.)
2) N/A
3) All your real servers should share the same ServerName (whatever DNS is saying your VIP resolves to.)
Secondly there are a few issues with your configuration:
Quote:
Originally Posted by williebens
On the LVS:
Interface configurations:
eth0 192.168.2.3
eth0:0 192.168.2.2 (This is the VIP as an alias)
eth1 192.168.2.1
lo 127.0.0.1
Routing tables:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.2.3 0.0.0.0 255.255.255.255 UH 0 0 0 eth0
192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
Your eth1 address should be in the 192.168.1.0. This should allow your LVS to route packets to your real server.
Correct, the site name (www.example.com) should resolve to the VIP. The VIP should be on realserver1 and realserver2 lo0:0. I didn't notice this before but you have it set to lo:0. I'm on a freebsd box at the moment so I can't check whether linux will accept that, but if things still don't work you should change it to lo0:0. The gateway for the real servers should be whatever device is routing traffic from 192.168.1.0 to 192.168.2.0 (this should not be your load balancer box.) If this doesn't work you should include the output of an ifconfig -a on both real servers and the LVS to help troubleshoot further.
I have the load balancer working. It is just one load balancer with two real servers for now. The next step will be to add another load balancer. The solution is a long one. I have it on this website: www.unixmultiverse.com.
I really want to thank you for helping me get this project to work.
Checked out your site and that's a pretty good writeup, one big thing to note: ifconfig will NOT show you LVS configured virtual IP's. You will need to use:
Code:
ip address list
This will be important when you're testing failover of VIPs between two hosts.
I am trying to setup LVS-DR in Amazon EC2. I am planning to use LVS not amazon's elasticity loadbalancer for some reason :-)
Now, when I configure what will be my VIP.
In EC2, I have two instances, both the instances have the public IP and Private IP.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.