#!/bin/bash # Konfiguration der Knoten MYNODE=1 DEVICE=eth0 OTHERNODE=192.168.20.2 # Cluster-Konfiguration CLUSTERIP=192.168.10.3 CLUSTERMAC=01:02:03:04:05:06 ONLINE=0 check_node () { ip link list dev $DEVICE | grep -q UP return $? } failover () { ip address delete $CLUSTERIP/24 dev $DEVICE echo "-$MYNODE" > /proc/net/ipt_CLUSTERIP/$CLUSTERIP ssh $OTHERNODE "echo '+$MYNODE' > /proc/net/ipt_CLUSTERIP/$CLUSTERIP" } recover () { ssh $OTHERNODE "echo '-$MYNODE' > /proc/net/ipt_CLUSTERIP/$CLUSTERIP" ip address add $CLUSTERIP/24 dev $DEVICE echo "+$MYNODE" > /proc/net/ipt_CLUSTERIP/$CLUSTERIP } # Knoten initialisieren modprobe ipt_conntrack ip address add $CLUSTERIP/24 dev $DEVICE iptables -F INPUT iptables -I INPUT -d $CLUSTERIP -i $DEVICE \ -p icmp --icmp-type echo-request -j CLUSTERIP --new \ --hashmode sourceip --clustermac $CLUSTERMAC \ --total-nodes 2 --local-node $MYNODE # Test, ob das Cluster-Interface funktioniert ONLINE=1 while (true); do if ( check_node ) then echo "Interface up" if [ $ONLINE -eq 0 ]; then recover ONLINE=1 fi else echo "Interface down" if [ $ONLINE -eq 1 ]; then failover ONLINE=0 fi fi sleep 1 done exit 0