Différences entre les versions de « Lvs verification »

De BlaxWiki
Aller à la navigationAller à la recherche
Ligne 7 : Ligne 7 :


=== Script pour lvs + keepalive avec vrrp ===
=== Script pour lvs + keepalive avec vrrp ===
<pre>
S'assurer que le /etc/hosts du serveur est bon, et que "hostname -f" retourne bien le fqdn du serveur et non pas localhost.
#!/bin/bash
 
KCONF="/opt/applis/keepalived/etc/keepalived/keepalived.conf"
OUTIP="/tmp/output.ipb"
OUTIPV="/tmp/output.ipv"
VISION=/opt/agarik/Vision/bin/bb_send_raw
DISPLAY="supervision.so.agarik.eu:1984"
TARGET="`/bin/hostname -f`"
SERVICE=appli
LOG=/var/log/appli_sup.log
LOOKUPVIP=1
LOOKUPRIP=1
 
function lookup() {
        ip=$1
        host=`host $ip | awk '{print $5}'`
        echo $host
}
 
ip a l > $OUTIP
 
/sbin/ipvsadm -ln  | tee > $OUTIPV # le | tee permet d'eviter un bug sur CA
 
exec > $LOG
 
color="green"
echo "Virtuals routers"
for vrrp in `egrep -e "\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$" $KCONF | grep -v server | grep -v ^#`
do
        host=""
        isactive=0
        shouldbeactive=0
        isstate="SLAVE"
        shouldbestate="SLAVE"
        if [ `cat $OUTIP | grep -c "$vrrp/"` -eq 1 ]; then
                isactive=1
                isstate="MASTER"
        fi
        if [ `egrep -e "state|$vrrp$|$vrrp/" $KCONF | grep -B1 $vrrp | grep -c MASTER` -ne 0 ]; then
                shouldbeactive=1
                shouldbestate="MASTER"
 
        fi
        if [ $LOOKUPVIP -eq 1 ]; then
                host=$(lookup $vrrp)
        fi
        echo "$isstate" > /tmp/tmp_$vrrp
        if [ "$shouldbeactive" == "$isactive" ]; then
                printf "%15s ($isstate &green) $host\n" $vrrp
        else
                echo "$vrrp ($isstate != $shouldbestate &red) $host"
                color="red"
        fi
 
done
 
echo "====================== VIPS =========================="
for service in `cat $KCONF | egrep "\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) " | grep -v real_server | grep -v ^# | grep -v sorry_server | awk '{print $1"_"$2"_"$3}' `
do
        vcolor="green"
        rcolor="clear"
        if [ `echo $service | grep -c "virtual_server"` -eq 1 ]; then
        vip=`echo $service| cut -d '_' -f 3`
        port=`echo $service| cut -d '_' -f 4`
        groupname="";
        else
        vip=`echo $service| cut -d '_' -f 1`
        port=`echo $service| cut -d '_' -f 2`
        groupname=`cat $KCONF | egrep "virtual_server_group|$vip $port" | grep -B1 "$vip $port" | grep "group" | cut -d " " -f 2`
        fi
# TODO : Ajouter un check sur l'etat de la VIP en plus de l'etat des REAL
        thisone=0
        echo > /tmp/tmp_$$
        for real in `egrep -e "virtual_server|real_server" $KCONF | awk '{print $1"_"$2"_"$3}'`
        do
                host=""
                if [ `echo $real | grep -c virtual_server` -eq 1 ]; then
                        thisone=0; # De base, je ne suis pas dans la bonne vip si je commence une nouvelle VIP
                fi
                if [ "virtual_server_"$vip"_$port" == "$real" -o "virtual_server_group_$groupname" == "$real" ]; then
                        thisone=1 # par contre, si je suis dans la bonne, j'active
                        continue;
                fi
                if [ $thisone -eq 0 ]; then
                        continue; # Et je passe tout de suite au suivant si ca n'est pas le cas
                fi
                rip=`echo $real | cut -d '_' -f 3`
                rport=`echo $real | cut -d '_' -f 4`
                active=`egrep -e "$vip:$port|$rip:$rport" $OUTIPV | grep -A1 $vip |grep $rip | awk '{print $5}'`
                inactive=`egrep -e "$vip:$port|$rip:$rport" $OUTIPV | grep -A1 $vip |grep $rip | awk '{print $6}'`
                if [ $LOOKUPRIP -eq 1 ]; then
                        host=$(lookup $rip)
                fi


                if [ `grep -c $rip:$rport $OUTIPV` -eq 0 ]; then
                        isactive=0;
                        isstate="DOWN &red ($active/$inactive) $host";
                        color="red";
                        vcolor="red";
                        if [ "$rcolor" == "green" -o "$rcolor" == "yellow" ]; then rcolor="yellow";else rcolor="red";fi
                else
                        isactive=1;
                        isstate="UP &green ($active/$inactive) $host";
                        if [ "$rcolor" == "red" -o "$rcolor" == "yellow" ]; then rcolor="yellow";else rcolor="green";fi
                fi
                printf "  Real : %15s:$rport : $isstate\n" $rip >> /tmp/tmp_$$
        done
        host=""
        if [ $LOOKUPVIP -eq 1 ]; then
                host=$(lookup $vip)
        fi
        echo -n " VIP : $vip:$port (`cat /tmp/tmp_$vip` &$rcolor) $host"
        cat /tmp/tmp_$$
        echo "------------------------------------------------------"
done
rm -f $OUTIP
rm -f $OUTIPV
rm -f /tmp/tmp_*
DATA="status+12 $TARGET.$SERVICE $color `/bin/date` $SERVICE
`cat $LOG`"
$VISION $DISPLAY "$DATA"
</pre>
=== Script pour lvs + keepalive sans vrrp ===
<pre>
<pre>
#!/bin/bash
#!/bin/bash
Ligne 144 : Ligne 17 :
VISION=/opt/agarik/Vision/bin/bb_send_raw
VISION=/opt/agarik/Vision/bin/bb_send_raw
DISPLAY="supervision.agarik.com"
DISPLAY="supervision.agarik.com"
TARGET="lb1.ext-cms.randstad.fr"
TARGET="lb1.bull.com"
SERVICE=appli
SERVICE=appli
LOG=/var/log/appli_sup.log
LOG=/var/log/appli_sup.log
Ligne 164 : Ligne 37 :
color="green"
color="green"
echo "Virtuals routers"
echo "Virtuals routers"
for vrrp in `egrep -e "\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/.*$" $KCONF | grep -v server | grep -v ^\s*#`
for vrrp in `egrep -e "\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]                                     ?[0-9][0-9]?)/.*$" $KCONF | grep -v server | grep -v ^\s*#`
do
do
         host=""
         host=""
Ligne 194 : Ligne 67 :
done
done
echo "====================== VIPS =========================="
echo "====================== VIPS =========================="
for service in `cat $KCONF | egrep "\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) " | grep -v real_server | grep -v ^\s*# | grep -v sorry_server | awk '{print $1"_"$2"_"$3}' `
for service in `cat $KCONF | egrep "\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0                                     -4][0-9]|[01]?[0-9][0-9]?) " | grep -v real_server | grep -v ^\s*# | grep -v sorry_server | awk '{print $1"_"$2"_"$3}' `
do
do
         vcolor="green"
         vcolor="green"
Ligne 248 : Ligne 121 :
                 host=$(lookup $vip)
                 host=$(lookup $vip)
         fi
         fi
         if [ -f /tmp/tmp_$vip ]; then
         echo -n " VIP : $vip:$port (`cat /tmp/tmp_$vip` &$rcolor) $host"
                echo -n " VIP : $vip:$port (`cat /tmp/tmp_$vip` &$rcolor) $host"
        else
                echo -n " VIP : $vip:$port $host"
        fi
         cat /tmp/tmp_$$
         cat /tmp/tmp_$$
         echo "------------------------------------------------------"
         echo "------------------------------------------------------"
done
done


rm -f $OUTIP
rm -f $OUTIP
Ligne 266 : Ligne 134 :


$VISION $DISPLAY "$DATA"
$VISION $DISPLAY "$DATA"


</pre>
</pre>


[[Catégorie:Script]]
[[Catégorie:Script]]

Version du 7 août 2014 à 15:43


Ce script vérifie l'état de la synchro drdb, certaines lignes concernent de la supervision spécifique, elles peuvent etre ignorées. Cela remonte un état des vip et des virtual routers comme ca :

Rapport check LVS

Script pour lvs + keepalive avec vrrp

S'assurer que le /etc/hosts du serveur est bon, et que "hostname -f" retourne bien le fqdn du serveur et non pas localhost.

#!/bin/bash

KCONF="/opt/applis/keepalived/etc/keepalived/keepalived.conf"
OUTIP="/tmp/output.ipb"
OUTIPV="/tmp/output.ipv"
VISION=/opt/agarik/Vision/bin/bb_send_raw
DISPLAY="supervision.agarik.com"
TARGET="lb1.bull.com"
SERVICE=appli
LOG=/var/log/appli_sup.log
LOOKUPVIP=0
LOOKUPRIP=0

function lookup() {
        ip=$1
        host=`host $ip | awk '{print $5}'`
        echo $host
}

ip a l > $OUTIP

/sbin/ipvsadm -ln  | tee > $OUTIPV # le | tee permet d'eviter un bug sur CA

exec > $LOG

color="green"
echo "Virtuals routers"
for vrrp in `egrep -e "\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]                                      ?[0-9][0-9]?)/.*$" $KCONF | grep -v server | grep -v ^\s*#`
do
        host=""
        isactive=0
        shouldbeactive=0
        isstate="SLAVE"
        shouldbestate="SLAVE"
        if [ `cat $OUTIP | grep -c "$vrrp"` -eq 1 ]; then
                isactive=1
                isstate="MASTER"
        fi
        if [ `egrep -e "state|$vrrp$|$vrrp/" $KCONF | grep -B1 $vrrp | grep -c MASTER` -ne 0 ]; then
                shouldbeactive=1
                shouldbestate="MASTER"

        fi
        if [ $LOOKUPVIP -eq 1 ]; then
                host=$(lookup $vrrp)
        fi
        vrrponly=`echo $vrrp |cut -d '/' -f 1`
        echo "$isstate" > /tmp/tmp_$vrrponly
        if [ "$shouldbeactive" == "$isactive" ]; then
                printf "%15s ($isstate &green) $host\n" $vrrp
        else
                echo "$vrrp ($isstate != $shouldbestate &red) $host"
                color="red"
        fi

done
echo "====================== VIPS =========================="
for service in `cat $KCONF | egrep "\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0                                      -4][0-9]|[01]?[0-9][0-9]?) " | grep -v real_server | grep -v ^\s*# | grep -v sorry_server | awk '{print $1"_"$2"_"$3}' `
do
        vcolor="green"
        rcolor="clear"
        if [ `echo $service | grep -c "virtual_server"` -eq 1 ]; then
        vip=`echo $service| cut -d '_' -f 3`
        port=`echo $service| cut -d '_' -f 4`
        groupname="";
        else
        vip=`echo $service| cut -d '_' -f 1`
        port=`echo $service| cut -d '_' -f 2`
        groupname=`cat $KCONF | egrep "virtual_server_group|$vip $port" | grep -B1 "$vip $port" | grep "group" | cut -d " " -f 2`
        fi
# TODO : Ajouter un check sur l'etat de la VIP en plus de l'etat des REAL
        thisone=0
        echo > /tmp/tmp_$$
        for real in `egrep -e "virtual_server|real_server" $KCONF | grep -v ^# | awk '{print $1"_"$2"_"$3}'`
        do
                host=""
                if [ `echo $real | grep -c virtual_server` -eq 1 ]; then
                        thisone=0; # De base, je ne suis pas dans la bonne vip si je commence une nouvelle VIP
                fi
                if [ "virtual_server_"$vip"_$port" == "$real" -o "virtual_server_group_$groupname" == "$real" ]; then
                        thisone=1 # par contre, si je suis dans la bonne, j'active
                        continue;
                fi
                if [ $thisone -eq 0 ]; then
                        continue; # Et je passe tout de suite au suivant si ca n'est pas le cas
                fi
                rip=`echo $real | cut -d '_' -f 3`
                rport=`echo $real | cut -d '_' -f 4`
                active=`egrep -e "$vip:$port|$rip:$rport" $OUTIPV | grep -A1 $vip |grep $rip | awk '{print $5}'`
                inactive=`egrep -e "$vip:$port|$rip:$rport" $OUTIPV | grep -A1 $vip |grep $rip | awk '{print $6}'`
                if [ $LOOKUPRIP -eq 1 ]; then
                        host=$(lookup $rip)
                fi

                if [ `grep -c $rip:$rport $OUTIPV` -eq 0 ]; then
                        isactive=0;
                        isstate="DOWN &red ($active/$inactive) $host";
                        color="red";
                        vcolor="red";
                        if [ "$rcolor" == "green" -o "$rcolor" == "yellow" ]; then rcolor="yellow";else rcolor="red";fi
                else
                        isactive=1;
                        isstate="UP &green ($active/$inactive) $host";
                        if [ "$rcolor" == "red" -o "$rcolor" == "yellow" ]; then rcolor="yellow";else rcolor="green";fi
                fi
                printf "   Real : %15s:$rport : $isstate\n" $rip >> /tmp/tmp_$$
        done
        host=""
        if [ $LOOKUPVIP -eq 1 ]; then
                host=$(lookup $vip)
        fi
        echo -n " VIP : $vip:$port (`cat /tmp/tmp_$vip` &$rcolor) $host"
        cat /tmp/tmp_$$
        echo "------------------------------------------------------"
done

rm -f $OUTIP
rm -f $OUTIPV
rm -f /tmp/tmp_*

DATA="status+12 $TARGET.$SERVICE $color `/bin/date` $SERVICE
`cat $LOG`"

$VISION $DISPLAY "$DATA"