mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
This patch enable redundant virtual routers. 1. To enable this feature, db need to be updated using follow SQL by now(we would get a UI way later): UPDATE network_offerings SET redundant_router=1 WHERE guest_type="Virtual" AND system_only=0; 2. System would try to start up two routers at different hosts. But if there is only one host in the zone, system would start up two routers on it. 3. The failover part is using keepalived, and connection tracking part is using conntrackd. There would be one master router and one backup router. The status of router(master or backup) can be query from the database table domain_router now. Management server would update the status every 30s by default. 4. The routers for the same zone would use same external NIC(same ip and mac). The script used for fail-over would ensure only one external NIC present in the network at any time. 5. Currently management server don't got the ability to stop one of router is both of them reported as master. The feature is in the todo list. After two routers start up, disconnect anyone of them, the guest network shouldn't be affected, and established connection(http, ssh, etc.) should still works. The fail-over on gateway part should be 3~4 seconds. Currently the patch works with KVM. Would deal with vmware and XenServer soon.
129 lines
3.2 KiB
Bash
129 lines
3.2 KiB
Bash
#!/bin/sh
|
|
#
|
|
# (C) 2008 by Pablo Neira Ayuso <pablo@netfilter.org>
|
|
#
|
|
# This software may be used and distributed according to the terms
|
|
# of the GNU General Public License, incorporated herein by reference.
|
|
#
|
|
# Description:
|
|
#
|
|
# This is the script for primary-backup setups for keepalived
|
|
# (http://www.keepalived.org). You may adapt it to make it work with other
|
|
# high-availability managers.
|
|
#
|
|
# Do not forget to include the required modifications to your keepalived.conf
|
|
# file to invoke this script during keepalived's state transitions.
|
|
#
|
|
# Contributions to improve this script are welcome :).
|
|
#
|
|
|
|
CONNTRACKD_BIN=/usr/sbin/conntrackd
|
|
CONNTRACKD_LOCK=/var/lock/conntrack.lock
|
|
CONNTRACKD_CONFIG=/etc/conntrackd/conntrackd.conf
|
|
CONNTRACKD_LOG=/root/keepalived.log
|
|
|
|
case "$1" in
|
|
primary)
|
|
#
|
|
# commit the external cache into the kernel table
|
|
#
|
|
$CONNTRACKD_BIN -C $CONNTRACKD_CONFIG -c
|
|
if [ $? -eq 1 ]
|
|
then
|
|
logger "ERROR: failed to invoke conntrackd -c"
|
|
fi
|
|
|
|
#
|
|
# flush the internal and the external caches
|
|
#
|
|
$CONNTRACKD_BIN -C $CONNTRACKD_CONFIG -f
|
|
if [ $? -eq 1 ]
|
|
then
|
|
logger "ERROR: failed to invoke conntrackd -f"
|
|
fi
|
|
|
|
#
|
|
# resynchronize my internal cache to the kernel table
|
|
#
|
|
$CONNTRACKD_BIN -C $CONNTRACKD_CONFIG -R
|
|
if [ $? -eq 1 ]
|
|
then
|
|
logger "ERROR: failed to invoke conntrackd -R"
|
|
fi
|
|
|
|
#
|
|
# send a bulk update to backups
|
|
#
|
|
$CONNTRACKD_BIN -C $CONNTRACKD_CONFIG -B
|
|
if [ $? -eq 1 ]
|
|
then
|
|
logger "ERROR: failed to invoke conntrackd -B"
|
|
fi
|
|
echo Conntrackd switch to primary done >> $CONNTRACKD_LOG
|
|
;;
|
|
backup)
|
|
#
|
|
# is conntrackd running? request some statistics to check it
|
|
#
|
|
$CONNTRACKD_BIN -C $CONNTRACKD_CONFIG -s
|
|
if [ $? -eq 1 ]
|
|
then
|
|
#
|
|
# something's wrong, do we have a lock file?
|
|
#
|
|
if [ -f $CONNTRACKD_LOCK ]
|
|
then
|
|
logger "WARNING: conntrackd was not cleanly stopped."
|
|
logger "If you suspect that it has crashed:"
|
|
logger "1) Enable coredumps"
|
|
logger "2) Try to reproduce the problem"
|
|
logger "3) Post the coredump to netfilter-devel@vger.kernel.org"
|
|
rm -f $CONNTRACKD_LOCK
|
|
fi
|
|
$CONNTRACKD_BIN -C $CONNTRACKD_CONFIG -d
|
|
if [ $? -eq 1 ]
|
|
then
|
|
logger "ERROR: cannot launch conntrackd"
|
|
exit 1
|
|
fi
|
|
fi
|
|
#
|
|
# shorten kernel conntrack timers to remove the zombie entries.
|
|
#
|
|
$CONNTRACKD_BIN -C $CONNTRACKD_CONFIG -t
|
|
if [ $? -eq 1 ]
|
|
then
|
|
logger "ERROR: failed to invoke conntrackd -t"
|
|
fi
|
|
|
|
#
|
|
# request resynchronization with master firewall replica (if any)
|
|
# Note: this does nothing in the alarm approach.
|
|
#
|
|
$CONNTRACKD_BIN -C $CONNTRACKD_CONFIG -n
|
|
if [ $? -eq 1 ]
|
|
then
|
|
logger "ERROR: failed to invoke conntrackd -n"
|
|
fi
|
|
echo Conntrackd switch to backup done >> $CONNTRACKD_LOG
|
|
;;
|
|
fault)
|
|
#
|
|
# shorten kernel conntrack timers to remove the zombie entries.
|
|
#
|
|
$CONNTRACKD_BIN -C $CONNTRACKD_CONFIG -t
|
|
if [ $? -eq 1 ]
|
|
then
|
|
logger "ERROR: failed to invoke conntrackd -t"
|
|
fi
|
|
echo Conntrackd switch to fault done >> $CONNTRACKD_LOG
|
|
;;
|
|
*)
|
|
logger "conntrackd: ERROR: unknown state transition: " $1
|
|
echo "Usage: primary-backup.sh {primary|backup|fault}"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
exit 0
|