> Alex Balashov wrote:

>

> Why would you want to do this versus sending a gratuitous ARP?
> 
> Nagaraja, Madhukar (Madhukar) wrote:
> 
> > Hello,
> > Is there any script just like IPaddr for the MAC address takeover ??
> > If not, any other options.
> > 
> > Please let me know.
> > 
> > Thanks.


Hi,

I used a script I wrote to take macaddresses over. I did this because
some devices dont accept the gratuituos arp. In fact, I take the MAC
over and after that I take the virtual IP over too sending the
gratuituous ARP to update the switch. I think that this works only if
your network card supports mac address modification with "ip link set
NETWORK_INTERFACE address DESIRED_MAC_ADDRESS"

I use a script and a folder with four configuration files. For example,
the name of my cluster is mycluster and there are two nodes, mycluster1
and mycluster2, then I have four files like these:

|-- here-comes-the-folder-with-the-cluster-conf
|   |-- cluster.conf
|   `-- mac
|       |-- mycluster
|       |-- mycluster1
|       `-- mycluster2

The content of each file is:

::::::::::::::
cluster.conf
::::::::::::::
CLUSTER="mycluster"

::::::::::::::
mycluster
::::::::::::::
eth0    01:01:01:12:34:56
::::::::::::::
mycluster1
::::::::::::::
eth0    00:14:35:7c:25:2f
::::::::::::::
mycluster2
::::::::::::::
eth0    00:14:35:7c:26:b8

The cluster.conf file contains the cluster name. The files in the mac
folder contain the virtual macs in the mycluster file, and the network
cards real macs of each node in the mycluster1 and mycluster2 file.
These files have the same name as the returned by `hostname` on each
cluster node. In this example, the cluster uses the network interface
eth0 with example IPs 10.0.0.1, 10.0.0.2 and 10.0.0.3. Take care too use
unused mac address ranges for your virtual macs, I think the 01:01:01
vendor does not exist (http://www.coffer.com/mac_find/?string=01%3A01%
3A01), and then I set the second part of the virtual cluster mac as I
like.

Then I have a script that I use in haresources to take the macs over to
the active node:
::::::::::::::
haresources
::::::::::::::
# /etc/ha.d/haresources
mycluster1      cluster-mac-takeover 10.0.0.1/24


Finally I put the script cluster-mac-takeover in the init.d folder with
the following contents:

#!/bin/bash
# Cluster MAC Takeover

#
# Variables

CONFDIR="here-comes-the-folder-with-the-cluster-conf"
DESC="Cluster MAC Takeover"
HOSTNAME="`hostname`"
LOCK="$DIR/var/tmp/cluster-mac-takeover"

IP="/sbin/ip"
CAT="/bin/cat"

#
# Configuration

if [ -f $CONFDIR/cluster.conf ]; then
        source $CONFDIR/cluster.conf
else
        echo "Cluster MAC Takeover Conf Not Found."
        exit 1
fi

if [ ! -f $CONFDIR/mac/$CLUSTER ]; then
        echo "Cluster MAC Takeover Conf Not Found."
        exit 1
fi

if [ ! -f $CONFDIR/mac/$HOSTNAME ]; then
        echo "Cluster MAC Takeover Conf Not Found."
        exit 1
fi

#
## Compatibility

COMPATIBILITY="yes"

#
# Funcions
start() {
        
        $CAT $CONFDIR/mac/$CLUSTER | grep -v "^#" | grep -v "^$" | while read
INTERFACE
        do
                IF="`echo $INTERFACE  | awk '{ print $1 }'`"
                MAC="`echo $INTERFACE | awk '{ print $2 }'`"

                # Cluster Mac Address Takeover
                $IP link set $IF address $MAC
        done
}

stop() {

        $CAT $CONFDIR/mac/$HOSTNAME | grep -v "^#" | grep -v "^$" | while read
INTERFACE
        do
                IF=`echo $INTERFACE  | awk '{ print $1 }'`
                MAC=`echo $INTERFACE | awk '{ print $2 }'`

                # Host Mac Address Reset
                $IP link set $IF address $MAC
        done
}

#
# Process
case $1 in
        start)
                if [ -f $LOCK ]; then
                        echo "$DESC is already started."
                else    
                        echo -n "Starting $DESC " 
                        start
                        if [ "$?" -eq "0" ]; then
                                touch $LOCK
                                 echo done.
                        else
                                 echo failed.
                        fi
                fi
                ;;

        stop)
                if [ ! -f $LOCK ]; then
                        echo "$DESC is already stopped."
                else
                        echo -n "Stopping $DESC "
                        stop
                        if [ "$?" -eq "0" ]; then
                                rm -f $LOCK
                                 echo done.
                         else
                                 echo failed.
                        fi
                fi
                ;;

        status)
                if [ -f $LOCK ]; then
                        if [ "$COMPATIBILITY" = "yes" ]; then
                                echo "running"
                        else
                                echo "$DESC is started."
                        fi
                else
                        echo "$DESC is stopped."
                        exit 3
                fi
                ;;

        *)
                echo "Usage: $0 start|stop|status"
                exit 2
                ;;
esac
exit 0

The COMPATIBILITY in the script flag is set so that the script behaves
as expected by heartbeat (AFAIK) and the script returns also the
expected exit codes.
Maybe this is not be the best way to do this and maybe there exists
already a builtin solution I dont know but I hope this helps,

Best Regards,
Eric Janz
_______________________________________________
Linux-HA mailing list
Linux-HA@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha
See also: http://linux-ha.org/ReportingProblems

Reply via email to