Ldirector for LVS cluster

2018-05-05|Categories: Cluster, Linux|Tags: |

What is ldirectord?

ldirectord is a daemon to monitor and administer real servers in a LVS cluster.

http://horms.net/projects/ldirectord/

How ldirectord works?

ldirectord monitors the health of the real servers by periodically requesting a known URL and checking that the response contains an expected response.

If a real server fails then the server is removed and will be reactivated once it comes back on line. If all the real servers are down then a fall-back server is inserted into the pool, which will made quiescent one of the real web servers comes back on line. Typically, the fall-back server is localhost. If an HTTP virtual service is being provided then it is useful to run an Apache HTTP server that returns a page indicating that the service is temporarily inaccessible.

Install ldiretord

mkdir /src && cd $_

# The link has been blocked by GFW, you may need a VPN to download it
wget http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-7/x86_64/ldirectord-3.9.6-0rc1.1.2.x86_64.rpm

# It needs too many Perl-based dependencies
yum install -y ldirectord-3.9.6-0rc1.1.2.x86_64.rpm

Configurate ldiretord

NOTE: All configurations about VS, RS and the network topology of them has been written in my another article at https://liyang85.com/implement-lvs-direct-routing-and-session-persistence

cp /usr/share/doc/ldirectord-3.9.6/ldirectord.cf /etc/ha.d
$ vim /etc/ha.d/ldirectord.cf

# Global Directives
checktimeout=3
checkinterval=1
fallback=127.0.0.1:80               # The Sorry server
autoreload=yes
logfile="/var/log/ldirectord.log"
quiescent=no

# Sample for an http virtual service
virtual=80443                       # 80443 is a FWM
        real=172.16.125.72 gate
        real=172.16.125.73 gate 2
        service=http
        scheduler=wrr
        protocol=fwm
        checktype=negotiate
        checkport=80
        request="health.html"       # see below step
        receive="I'm OK"

Prepare the checking file in all RS box

echo "I'm OK" > /var/www/html/health.html

Prepare the Sorry server in VS box

yum install -y httpd
echo 'Sorry server' > /var/www/html/index.html
systemctl start httpd

Start ldirectord.service

ipvsadm -C
systemctl start ldirectord
$ ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
FWM  80443 wrr
  -> 172.16.125.72:0              Route   1      0          0
  -> 172.16.125.73:0              Route   2      0          0

View the log of ldirectord

You can down a RS manually, and the RS will be deleted automatically from the RS list by ldirectord. When you up it again, that RS goes back to the RS list immediately. All the operations can be seen in the log file:

$ cat /var/log/ldirectord.log
[Sat May  5 17:44:24 2018|ldirectord|9867] Invoking ldirectord invoked as: /usr/sbin/ldirectord start
[Sat May  5 17:44:24 2018|ldirectord|9867] Starting Linux Director v1.186-ha as daemon
[Sat May  5 17:44:24 2018|ldirectord|9870] Added virtual server: 80443
[Sat May  5 17:44:24 2018|ldirectord|9870] system(/sbin/ipvsadm -a -f 80443 -r :0   -w 1) failed:
[Sat May  5 17:44:24 2018|ldirectord|9870] Added fallback server: :0 (80443) (Weight set to 1)
[Sat May  5 17:44:24 2018|ldirectord|9870] Added real server: 172.16.125.72:0 (80443) (Weight set to 1)
[Sat May  5 17:44:24 2018|ldirectord|9870] Deleted real server: 172.16.125.72:0 (80443)
[Sat May  5 17:44:24 2018|ldirectord|9870] system(/sbin/ipvsadm -a -f 80443 -r :0   -w 1) failed:
[Sat May  5 17:44:24 2018|ldirectord|9870] Added fallback server: :0 (80443) (Weight set to 1)
[Sat May  5 17:44:24 2018|ldirectord|9870] Added real server: 172.16.125.73:0 (80443) (Weight set to 2)
[Sat May  5 17:44:24 2018|ldirectord|9870] Deleted real server: 172.16.125.73:0 (80443)
[Sat May  5 17:44:24 2018|ldirectord|9870] system(/sbin/ipvsadm -a -f 80443 -r :0   -w 1) failed:
[Sat May  5 17:44:24 2018|ldirectord|9870] Added fallback server: :0 (80443) (Weight set to 1)
[Sat May  5 17:46:25 2018|ldirectord|9870] Resetting soft failure count: 172.16.125.72:0 (fwm:80443)
[Sat May  5 17:46:25 2018|ldirectord|9870] Added real server: 172.16.125.72:0 (80443) (Weight set to 1)
[Sat May  5 17:46:31 2018|ldirectord|9870] Resetting soft failure count: 172.16.125.73:0 (fwm:80443)
[Sat May  5 17:46:31 2018|ldirectord|9870] Added real server: 172.16.125.73:0 (80443) (Weight set to 2)
[Sat May  5 17:48:18 2018|ldirectord|9870] Configuration file '/etc/ha.d/ldirectord.cf' has changed on disk
[Sat May  5 17:48:18 2018|ldirectord|9870]  - reread new configuration
[Sat May  5 17:48:18 2018|ldirectord|9870] Changed virtual server: 80443
[Sat May  5 17:51:16 2018|ldirectord|9870] Deleted real server: 172.16.125.72:0 (80443)
[Sat May  5 17:51:45 2018|ldirectord|9870] Resetting soft failure count: 172.16.125.72:0 (fwm:80443)
[Sat May  5 17:51:45 2018|ldirectord|9870] Added real server: 172.16.125.72:0 (80443) (Weight set to 1)
[Sat May  5 18:20:50 2018|ldirectord|9870] Deleted real server: 172.16.125.73:0 (80443)
[Sat May  5 18:21:23 2018|ldirectord|9870] Resetting soft failure count: 172.16.125.73:0 (fwm:80443)
[Sat May  5 18:21:23 2018|ldirectord|9870] Added real server: 172.16.125.73:0 (80443) (Weight set to 2)

Leave A Comment