Re: Can piranha failover all ethernet interfaces?
"Mark T. Dame" <[email protected]> Fri, 14 Dec 2007 17:52:34 -0500
| Newsgroups | gmane.linux.redhat.piranha |
|---|---|
| Organization | MFM Software, Inc. |
| Message-ID | <[email protected]> |
Brian Ghidinelli wrote: > > Mark T. Dame wrote: >> Not directly. You will have to write a script to bring the extra >> interfaces up or down and then use the start_cmd and stop_cmd settings >> to call the script when the service fails over. I did something >> similar for a MySQL server. I have two servers, each with two NICs, >> one external and one internal. On failover, the floating IP for each >> network to switch to the appropriate server. My service definition is: > > Mark, thanks for the response. So, if the heartbeat goes down which > causes the external interface to be brought up on the standby, the > failover will simultaneously be triggered and can execute a script to > change the other NICs? Correct. > I have read conflicting info on whether or not you can have virtual > servers and failover running at the same time. It sounds from your post > like you do? On these servers I only have failover running. > Would you mind sharing your script as a starting point? It would be > appreciated, thanks! Attached lvs.cf and fos_failover.pl -m -- ## Mark T. Dame <mailto:[email protected]> ## VP, Product Development ## MFM Software, Inc. (http://www.mfm.com/) "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." -- The Restaurant at the End of the Universe, Douglas Adams _______________________________________________ Piranha-list mailing list [email protected] https://www.redhat.com/mailman/listinfo/piranha-list
fos_failover.pl
(text/plain, 2.7 KB)
#!/usr/bin/perl
#
######################################################################
#
# MFM Utility Scripts
#
# Copyright (c)2003-2007, MFM Communication Software, Inc.
#
######################################################################
#
# fos_failover.pl
# $Id$
#
# Bring virtual interfaces up/down and send an e-mail message to report
# fail over has occurred
#
######################################################################
use strict;
use Getopt::Std;
use IO::Interface qw(:flags);
use IO::Socket;
use Net::SMTP;
# Make STDOUT unbuffered
$| = 1;
my $host = `hostname -s`;
chomp $host;
# Some "constants"
my @vIP =
(
{
ip => '10.1.4.50',
mask => '255.255.255.0',
bcast => '10.1.4.255',
device => 'eth0:1',
},
{
ip => '10.1.1.50',
mask => '255.255.255.0',
bcast => '10.1.1.255',
device => 'eth2:1',
},
);
# Get the arguments
our ($opt_d, $opt_u);
&getopts("du") || die("$0: getopts() failed: $!");
&main;
sub main
{
if ($opt_u)
{
&StartServices();
}
elsif ($opt_d)
{
&StopServices();
}
else
{
print "Must specify -u or -d\n";
}
}
sub StartServices
{
my $debug = "Commands:\n";
# Turn on back-end virtual IP
foreach my $ip (@vIP)
{
my @cmd = ('/sbin/ifconfig', $ip->{device}, $ip->{ip}, 'netmask', $ip->{mask}, 'broadcast', $ip->{mask}, 'up');
$debug .= (join ' ', @cmd) . "\n";
system(@cmd);
# Get the real NIC
my ($dev) = split /:/, $ip->{device};
# Get the hardware address for the NIC
my $hwAddr = undef;
my $s = IO::Socket::INET->new(Proto => 'udp');
foreach my $if ($s->if_list)
{
my ($name) = split /:/, $if;
if ($name eq $dev)
{
$hwAddr = $s->if_hwaddr($if);
last;
}
}
if ($hwAddr and ($hwAddr ne ''))
{
@cmd = ('/usr/sbin/send_arp', '-i', $dev, $ip->{ip}, $hwAddr, $ip->{bcast}, 'ffffffffffff');
$debug .= (join ' ', @cmd) . "\n";
system(@cmd);
}
}
# Finally send an e-mail
my $msg = <<"MSG";
$host has switched to ACTIVE!
$debug
MSG
SendEMail($msg);
}
sub StopServices
{
my $debug = "Commands:\n";
# Turn off back-end virtual IP
foreach my $ip (@vIP)
{
my @cmd = ('/sbin/ifconfig', $ip->{device}, 'down');
$debug .= (join ' ', @cmd) . "\n";
system(@cmd);
}
# Finally send an e-mail
my $msg = <<"MSG";
$host has switched to INACTIVE!
$debug
MSG
SendEMail($msg);
}
sub SendEMail
{
my $msg = shift;
my $msgtext = <<"END_MSGTEXT";
To: dbfailover\@mfm.com
From: root\@mfm.com
Subject: $host Fail Over
$msg
--
root\@mfm.com
END_MSGTEXT
my $smtp = Net::SMTP->new("localhost");
$smtp->mail("root\@mfm.com");
$smtp->to("dbfailover\@mfm.com");
$smtp->data;
$smtp->datasend($msgtext);
$smtp->dataend;
$smtp->quit;
}
lvs.cf
(text/plain, 415 B)
primary = xxx.yyy.zzz.PRI
service = fos
rsh_command = rsh
backup_active = 1
backup = xxx.yyy.zzz.BAK
heartbeat = 1
heartbeat_port = 539
keepalive = 6
deadtime = 18
network = direct
debug_level = NONE
failover mysql {
active = 1
address = xxx.yyy.zzz.VIRT eth1:1
port = mysql
timeout = 3
start_cmd = "/usr/local/etc/fos_failover.pl -u"
stop_cmd = "/usr/local/etc/fos_failover.pl -d"
}