/ Linux

Setup Piranha LoadBalancer on CentOS

Install Packages:

$ yum install piranha -y

Our Networking Setup:

balancer => Load Balancer IP (10.0.0.1)
mail => Virtual Server (10.0.0.5)
ms1, ms2 => MailScanner Servers (10.0.0.10, 10.0.0.20)

Remember that the Virtual Server is just a virtual IP Address that you will be pointing your A/MX Records to, this will be the IP Address that receives data and sitributes to the target in other words, Real Servers.

Load Balancer Config:

Edit lvs.cfg

$ vi /etc/sysconfig/ha/lvs.cf

Configuration:

serial_no = 132
primary = 10.0.0.1
service = lvs
backup_active = 0
backup = 0.0.0.0
heartbeat = 1
heartbeat_port = 539
keepalive = 20
deadtime = 20
network = direct
debug_level = NONE
monitor_links = 0

virtual balancer {
  active = 1
  address = 10.0.0.5 eth0:1
  vip_nmask = 255.255.255.0
  port = 25
  use_regex = 0
  load_monitor = none
  scheduler = wrr
  protocol = tcp
  timeout = 20
  reentry = 30
  quiesce_server = 0

  server ms1 {
    address = 10.0.0.10
    active = 1
    weight = 1
  }

  server ms2 {
    address = 10.0.0.20
    active = 1
    weight = 1
  }
}

Enable IP Forwarding:

$ vi /etc/sysctl.conf
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.eth0.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.eth0.arp_announce = 2
net.ipv4.ip_forward = 1

Append Changes:

$ sysctl -p

Real Server Configuration:

Create network config

$ vi /etc/sysconfig/network-scripts/ifcfg-lo:1
DEVICE=lo:1
IPADDR=10.0.0.5
NETMASK=255.255.255.255
ONBOOT=yes
NAME=loopback

Start the LoadBalancer:

$ /etc/init.d/pulse start

Verify the status:

$ ipvasdm

Access your server on http://10.0.0.5