{"id":151,"date":"2015-04-21T13:09:26","date_gmt":"2015-04-21T04:09:26","guid":{"rendered":"http:\/\/www.raythebm.net\/weblog\/?p=151"},"modified":"2015-04-21T13:09:26","modified_gmt":"2015-04-21T04:09:26","slug":"%e4%bb%ae%e6%83%b3-ip-%e3%82%a2%e3%83%89%e3%83%ac%e3%82%b9%e3%82%92%e3%83%95%e3%82%a7%e3%82%a4%e3%83%ab%e3%82%aa%e3%83%bc%e3%83%90%e3%83%bc%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.raythebm.net\/weblog\/archives\/151","title":{"rendered":"\u4eee\u60f3 IP \u30a2\u30c9\u30ec\u30b9\u3092\u30d5\u30a7\u30a4\u30eb\u30aa\u30fc\u30d0\u30fc\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>\u304a\u4e45\u3057\u3076\u308a\u3067\u3059\u3002<br \/>\n\u76f8\u5909\u3089\u305a\u4e0d\u5b9a\u671f\u66f4\u65b0\u3067\u3001\u4f5c\u696d\u30e1\u30e2\u3070\u304b\u308a\u306e\u30d6\u30ed\u30b0\u3067\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306f (Debian\u7cfb)Linux \u3067\u3001\u4eee\u60f3 IP \u30a2\u30c9\u30ec\u30b9\u3092\u30d5\u30a7\u30a4\u30eb\u30aa\u30fc\u30d0\u30fc\u3059\u308b\u65b9\u6cd5\u306e\u30e1\u30e2\u3067\u3059\u3002<br \/>\n\u7c21\u5358\u306b\u8a00\u3046\u3068\u3001\u30b5\u30fc\u30d0 2\u53f0\u306e\u72b6\u614b\u3067\u7247\u65b9\u304c\u30b3\u30b1\u305f\u6642\u306b\u6b8b\u3063\u3066\u308b\u65b9\u3067\u30b5\u30fc\u30d3\u30b9\u3092\u7d99\u7d9a\u3057\u305f\u3044\u6642\u306b\u4f7f\u3046\u624b\u6cd5\u3067\u3059\u3002\u3063\u3066\u3001\u5168\u7136\u7c21\u5358\u3058\u3083\u306a\u3044\u3067\u3059\u306d\u2026<\/p>\n<p>\u3067\u306f\u4e0b\u6e96\u5099\u304b\u3089\u3067\u3059\u3002<br \/>\n\u25a0\u6750\u6599<\/p>\n<ul>\n<li>\u30b5\u30fc\u30d0 2\u53f0(\u3082\u3061\u308d\u3093\u4eee\u60f3\u30de\u30b7\u30f3\u3067\u3082\u53ef)<\/li>\n<li>\u30cd\u30c3\u30c8\u30ef\u30fc\u30af 2\u500b(\u3064\u307e\u308a NIC 2\u679a\u305a\u3064\u3068\u30cf\u30d6 2\u500b)<\/li>\n<li>\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u30de\u30b7\u30f3 1\u53f0(\u5207\u308a\u66ff\u3048\u72b6\u6cc1\u3092\u30c1\u30a7\u30c3\u30af\u3057\u307e\u3059)<\/li>\n<\/ul>\n<p>\u25a0\u6e96\u5099\u624b\u9806<\/p>\n<ol>\n<li>\u30b5\u30fc\u30d0\u306b Debian\u7cfbOS(\u6700\u8fd1\u3060\u3068 Ubuntu \u304c\u591a\u3044\u3067\u3059\u304b\u306d)\u3092\u5165\u308c\u307e\u3059<\/li>\n<li>\u30b5\u30fc\u30d0\u306b fake \u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059(send_arp \u30b3\u30de\u30f3\u30c9\u304c\u5165\u308a\u307e\u3059)<\/li>\n<li>\u30b5\u30fc\u30d0\u306b arping \u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059<\/li>\n<li>\u30b5\u30fc\u30d0\u3092 2\u3064\u306e\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u306b\u63a5\u7d9a\u3059\u308b\u8a2d\u5b9a\u3092\u3057\u307e\u3059(\/etc\/network\/interfaces \u3067\u3059\u306d)<br \/>\n   \u4fbf\u5b9c\u4e0a\u305d\u308c\u305e\u308c\u3092 WAN \u3068 LAN \u3068\u547c\u3073\u307e\u3059\u3002\u307e\u305f\u3001\u30b5\u30fc\u30d0\u540d\u306f srv1\u3001srv2 \u3068\u3057\u307e\u3059\u3002<\/p>\n<ul>\n<li>LAN(eth0)\uff1a192.168.1.0\/24, srv1(192.168.1.11), srv2(192.168.1.12)<\/li>\n<li>WAN(eth1)\uff1a10.0.0.0\/24, srv1(10.0.0.11), srv2(10.0.0.12)<\/li>\n<\/ul>\n<\/li>\n<li>\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u30de\u30b7\u30f3(\u540d\u524d\uff1acli)\u3092 WAN \u306b\u63a5\u7d9a\u3057\u307e\u3059(IP\uff1a10.0.0.20)<\/li>\n<\/ol>\n<hr \/>\n<p>\u305d\u308c\u3067\u3001\u5b9f\u969b\u306b\u5207\u308a\u66ff\u3048\u308b\u64cd\u4f5c\u3067\u3059\u3002<\/p>\n<ul>\n<li>\u4eee\u60f3 IP \u30a2\u30c9\u30ec\u30b9($VIP)\u3092 10.0.0.1 \u3068\u3057\u307e\u3059<\/li>\n<li>WAN\u5074\u30c7\u30d0\u30a4\u30b9($DEV = eth1)\u306e MAC \u30a2\u30c9\u30ec\u30b9($MAC)\u3092\u6b21\u3060\u3068\u3057\u307e\u3059<\/li>\n<ul>\n<li>srv1(000011110000)<\/li>\n<li>srv2(222200002222)<\/li>\n<\/ul>\n<\/ul>\n<p>\u25a0\u30e1\u30a4\u30f3\u5074\u30b5\u30fc\u30d0(srv1)\u3078\u4eee\u60f3 IP \u3092\u4ed8\u3051\u307e\u3059<\/p>\n<p>\u300c<code>srv1&gt; ip addr add $VIP\/24 dev $DEV<\/code>\u300d<\/p>\n<p>\u25a0\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074\u304b\u3089\u30c1\u30a7\u30c3\u30af\u3057\u307e\u3059<\/p>\n<ul>\n<li>IP \u30a2\u30c9\u30ec\u30b9\uff1a\u300c<code>cli&gt; ping $VIP<\/code>\u300d<\/li>\n<li>ARP \u30ad\u30e3\u30c3\u30b7\u30e5\uff1a\u300c<code>cli&gt; arp<\/code>\u300d(10.0.0.1 \u304c 000011110000 \u306b\u306a\u308b\u306f\u305a\u3067\u3059)<\/li>\n<\/ul>\n<p>\u25a0\u4eee\u60f3 IP \u3092\u30d5\u30a7\u30a4\u30eb\u30aa\u30fc\u30d0\u30fc\u3059\u308b\u30b3\u30de\u30f3\u30c9\u3067\u3059<br \/>\n\u3053\u3053\u3067\u306f\u4eee\u60f3 IP \u306e\u5b58\u5728\u30c1\u30a7\u30c3\u30af\u3092\u7e70\u308a\u8fd4\u3057\u3066\u3001\u5931\u6557\u3057\u305f\u3089 \u4eee\u60f3 IP \u306e\u8a2d\u5b9a\u3068 ARP \u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u66f4\u65b0\u901a\u77e5\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n<ol>\n<li>\u4eee\u60f3 IP \u306e\u5b58\u5728\u30c1\u30a7\u30c3\u30af\uff1a\u300c<code>srv2&gt; arping -q -c 1 -I $DEV $VIP<\/code>\u300d<\/li>\n<li>\u4eee\u60f3 IP \u306e\u8a2d\u5b9a(srv1 \u306e\u6642\u3068\u540c\u69d8)\uff1a\u300c<code>srv2&gt; ip addr add $VIP\/24 dev $DEV<\/code>\u300d<\/li>\n<li>ARP \u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u66f4\u65b0\u901a\u77e5\uff1a\u300c<code>srv2&gt; send_arp $VIP $MAC 255.255.255.255 ffffffffffff $DEV $MAC ffffffffffff reply<\/code>\u300d<\/li>\n<\/ol>\n<p>\u305f\u3076\u3093\u3001\u5b9f\u969b\u306b\u306f\u4e0b\u306b\u66f8\u3044\u305f\u3088\u3046\u306a\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u25a0srv1 \u306e\u4eee\u60f3 IP \u3092\u5916\u3057\u307e\u3059<br \/>\n\u300c<code>srv1&gt; ip addr del $VIP dev $DEV<\/code>\u300d<\/p>\n<p>\u25a0\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074\u304b\u3089\u30c1\u30a7\u30c3\u30af\u3057\u307e\u3059<br \/>\n\u524d\u3068\u540c\u69d8\u306b ping \u3068 arp \u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<br \/>\narp \u306e\u8868\u793a\u3067 10.0.0.1 \u304c 222200002222 \u306b\u5909\u308f\u3063\u3066\u3044\u308b\u306f\u305a\u3067\u3059\u3002<\/p>\n<hr \/>\n<p>\u4eee\u60f3 IP \u30d5\u30a7\u30a4\u30eb\u30aa\u30fc\u30d0\u30fc\u7528\u30b9\u30af\u30ea\u30d7\u30c8<\/p>\n<blockquote><p><code><br \/>\n#!\/bin\/bash<\/p>\n<p>VIP=\"10.0.0.1\"<br \/>\nDEV=\"eth1\"<br \/>\nBCAST_IP=\"255.255.255.255\"<br \/>\nBCAST_MAC=\"ffffffffffff\"  # f x 12<\/p>\n<p>health_check() {<br \/>\n  arping -q -c 1 -I $DEV $VIP<br \/>\n  return $?<br \/>\n}<\/p>\n<p>ip_failover() {<br \/>\n  MAC=`ip link show $DEV | egrep -o '([0-9a-f]{2}:){5}[0-9a-f]{2}' | head -1 | tr -d \\:`<br \/>\n  ip addr add $VIP\/24 dev $DEV<br \/>\n  send_arp $VIP $MAC $BCAST_IP $BCAST_MAC $DEV $MAC $BCAST_MAC reply<br \/>\n}<\/p>\n<p>while health_check; do<br \/>\n  echo \"health check ok!\"<br \/>\n  sleep 1<br \/>\ndone<br \/>\necho \"fail over!\"<br \/>\nip_failover<br \/>\n<\/code><\/p><\/blockquote>\n<p>\u3082\u3061\u308d\u3093\u3001\u5b9f\u969b\u306b\u4f7f\u3046\u6642\u306b\u306f echo \u306e\u90e8\u5206\u306f\u30b3\u30e1\u30f3\u30c8\u30a2\u30a6\u30c8\u3059\u308b\u4e8b\u306b\u306a\u308b\u3067\u3057\u3087\u3046\u3002<\/p>\n<hr \/>\n<p>\u307e\u305f\u3001\u4f5c\u696d\u4e2d\u306b\u6c17\u4ed8\u3044\u305f\u70b9\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n<ul>\n<li>\u4eee\u60f3 IP \u306e\u30c1\u30a7\u30c3\u30af\u306f \u300c<code>arping -q -c 1 -I $DEV $VIP<\/code>\u300d \u306e\u65b9\u304c \u300c<code>ping -c 1 $VIP >\/dev\/null<\/code>\u300d \u3088\u308a\u3082\u65e9\u304f\u30c0\u30a6\u30f3\u306b\u6c17\u4ed8\u304d\u307e\u3057\u305f<\/li>\n<li>Web \u3067\u30af\u30e9\u30a4\u30a2\u30f3\u30c8(\u5b9f\u969b\u306b\u306f WAN \u306e\u30eb\u30fc\u30bf)\u306b \u300c<code>echo 1 > \/proc\/sys\/net\/ipv4\/conf\/all\/arp_accept<\/code>\u300d \u3092\u8a2d\u5b9a\u3057\u305f\u65b9\u304c\u826f\u3044\u3068\u66f8\u3044\u3066\u3042\u308a\u307e\u3057\u305f\u304c\u3001\u4eca\u56de\u306f\u8a2d\u5b9a\u5024\u304c 0 \u3067\u3082\u671f\u5f85\u901a\u308a\u306b\u52d5\u304d\u307e\u3057\u305f<\/li>\n<li>ARP \u30ad\u30e3\u30c3\u30b7\u30e5\u66f4\u65b0\u306b\u4f7f\u3046 send_arp \u30b3\u30de\u30f3\u30c9\u3067\u3059\u304c\u3001Web \u3067\u8abf\u3079\u305f \u300c<code>send_arp $VIP $MAC $BCAST_IP $BCAST_MAC $DEV<\/code>\u300d \u3067\u306f\u671f\u5f85\u3059\u308b ARP Reply \u3067\u306f\u306a\u304f ARP Request \u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3057\u305f<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u304a\u4e45\u3057\u3076\u308a\u3067\u3059\u3002 \u76f8\u5909\u3089\u305a\u4e0d\u5b9a\u671f\u66f4\u65b0\u3067\u3001\u4f5c\u696d\u30e1\u30e2\u3070\u304b\u308a\u306e\u30d6\u30ed\u30b0\u3067\u3059\u3002 \u4eca\u56de\u306f (Debian\u7cfb)Linux \u3067\u3001\u4eee\u60f3 IP \u30a2\u30c9\u30ec\u30b9\u3092\u30d5\u30a7\u30a4\u30eb\u30aa\u30fc\u30d0\u30fc\u3059\u308b\u65b9\u6cd5\u306e\u30e1\u30e2\u3067\u3059\u3002 \u7c21\u5358\u306b\u8a00\u3046\u3068\u3001\u30b5\u30fc\u30d0 2\u53f0\u306e\u72b6\u614b\u3067\u7247\u65b9\u304c\u30b3\u30b1\u305f\u6642 &hellip; <a href=\"https:\/\/www.raythebm.net\/weblog\/archives\/151\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[44,9,15,14,11],"class_list":["post-151","post","type-post","status-publish","format-standard","hentry","category-it","tag-hacluster","tag-howto","tag-linux","tag-memo","tag-system"],"_links":{"self":[{"href":"https:\/\/www.raythebm.net\/weblog\/wp-json\/wp\/v2\/posts\/151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.raythebm.net\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.raythebm.net\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.raythebm.net\/weblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.raythebm.net\/weblog\/wp-json\/wp\/v2\/comments?post=151"}],"version-history":[{"count":13,"href":"https:\/\/www.raythebm.net\/weblog\/wp-json\/wp\/v2\/posts\/151\/revisions"}],"predecessor-version":[{"id":164,"href":"https:\/\/www.raythebm.net\/weblog\/wp-json\/wp\/v2\/posts\/151\/revisions\/164"}],"wp:attachment":[{"href":"https:\/\/www.raythebm.net\/weblog\/wp-json\/wp\/v2\/media?parent=151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.raythebm.net\/weblog\/wp-json\/wp\/v2\/categories?post=151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.raythebm.net\/weblog\/wp-json\/wp\/v2\/tags?post=151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}