免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1308 | 回复: 0
打印 上一主题 下一主题

linux下HA中sendarp配置示例 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-06-07 14:48 |只看该作者 |倒序浏览
HA部署中,经常会遇到ARP问题.由于路由刷新慢,服务在切换后,client端访问出错.需要等到ARP表刷新后,才能正确访问.
解决方法就是使用sendarp.前段时间为它,捆扰好长时间.所以帖个例子出来.可以放在启动服务脚本中.

#!/bin/bash
#
# iptakeover script
#
# Simple script to take over an IP address.
#
# Usage is "iptakeover {start|stop|status}"
#
# SENDARP is the program included with the Heartbeat program that
# sends out an ARP request. Send_arp usage is:
#
#
SENDARP="/usr/lib/heartbeat/send_arp"
#
# REALIP is the IP address for this NIC on your LAN.
#
REALIP="299.100.100.2"
#
# ROUTERIP is the IP address for your router.
#
ROUTER_IP="299.100.100.1"
#
# SECONDARYIP is the first IP alias for a service/resource.
#
SECONDARYIP1="299.100.100.3"
# or
#IPALIAS1="299.100.100.3"
#
# NETMASK is the netmask of this card.
#
NETMASK="24"
# or
# NETMASK="255.255.255.0"
#
BROADCAST="299.100.100.0"
#
# MACADDR is the hardware address for the NIC card.
# (You'll find it using the command "/sbin/ifconfig")
#
MACADDR="091230910990"
case $1 in
start)
    # Make sure our primary IP is up
    /sbin/ifconfig eth0 $REALIP up
    # Associate the virtual IP address with this NIC
    /sbin/ip addr add $SECONDARYIP1/$NETMASK broadcast $BROADCAST dev eth0
    # Or, to create an IP alias instead of secondary IP address, use the
    command:
    # /sbin/ifconfig eth0:0 $IPALIAS1 netmask $NETMASK up
    # Create a new default route directly to the router
    /sbin/route add default gw $ROUTER_IP
    # Now send out 5 Gratuitous ARP broadcasts (ffffffffffff)
    # at two second intervals to tell the local computers to update
    # their ARP tables.
    $SENDARP -i 2000 -r 5 eth0 $SECONDARYIP1 $MACADDR $SECONDARYIP1 ffffffffffff
;;
stop)
    # Take down the secondary IP address for the service/resource.
    /sbin/ip addr del $SECONDARYIP1/$NETMASK broadcast $BROADCAST dev eth0
    # or
    /sbin/ifconfig eth0:0 down
;;
    status)
    # We check to see if we own the IPALIAS.
    OWN_ALIAS=`ifconfig | grep $SECONDARYIP1`
    if [ "$OWN_ALIAS" != "" ]; then
    echo "OK"
    else
    echo "DOWN"
    fi
;;
# End of the case statement.
    esac


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/7707/showart_124666.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP