{"id":196,"date":"2025-04-29T07:08:06","date_gmt":"2025-04-29T07:08:06","guid":{"rendered":"http:\/\/www.zhangwk.cn\/?p=196"},"modified":"2025-04-29T07:14:33","modified_gmt":"2025-04-29T07:14:33","slug":"keepalived-%e9%ab%98%e5%8f%af%e7%94%a8","status":"publish","type":"post","link":"https:\/\/www.zhangwk.cn\/index.php\/2025\/04\/29\/keepalived-%e9%ab%98%e5%8f%af%e7%94%a8\/","title":{"rendered":"Keepalived \u9ad8\u53ef\u7528"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">1\u3001\u89c4\u5212  A\u4e3b\u673a \uff1a192.168.1.00  B\u4e3b\u673a\uff1a192.168.1.101   VIP\uff1a192.168.0.250<\/h4>\n\n\n\n<div style=\"height:32px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">2\u3001\u8bbe\u7f6eA\u4e3b\u673a\u4e3a\uff1aMASTER                \u4e3b\u673aB\u4e3a\uff1aBACKUP<\/h4>\n\n\n\n<div style=\"height:32px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">3\u3001\u5b89\u88c5keepalived <\/h4>\n\n\n\n<pre class=\"wp-block-code has-pale-ocean-gradient-background has-background\"><code>yum install  keepalived.x86_64<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">4\u3001\u914d\u7f6eA\u4e3b\u673a\u7684 keepalived\u914d\u7f6e\u6587\u4ef6  <\/h4>\n\n\n\n<pre class=\"wp-block-code has-pale-ocean-gradient-background has-background\"><code>vim \/etc\/keepalived\/keepalived.conf\n\nglobal_defs {\n   notification_email {\n     acassen@firewall.loc\n     failover@firewall.loc\n     sysadmin@firewall.loc\n   }\n   notification_email_from Alexandre.Cassen@firewall.loc\n   smtp_server 192.168.200.1\n   smtp_connect_timeout 30\n   router_id LVS_DEVEL\n   vrrp_skip_check_adv_addr\n<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">#   vrrp_strict<\/mark>\n   vrrp_garp_interval 0\n   vrrp_gna_interval 0\n}\n\nvrrp_instance VI_1 {\n    <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">state MASTER<\/mark>\n    interface eth0\n    virtual_router_id 51\n    <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">priority 150\n<\/mark>    advert_int 1\n    authentication {\n        auth_type PASS\n        auth_pass 1111\n    }\n    virtual_ipaddress {\n        <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">192.168.0.250\/24<\/mark>\n    }\n}\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">5\u3001\u914d\u7f6eB\u4e3b\u673a\u7684 keepalived\u914d\u7f6e\u6587\u4ef6  <\/h4>\n\n\n\n<pre class=\"wp-block-code has-pale-ocean-gradient-background has-background\"><code>vim \/etc\/keepalived\/keepalived.conf\n\nglobal_defs {\n   notification_email {\n     acassen@firewall.loc\n     failover@firewall.loc\n     sysadmin@firewall.loc\n   }\n   notification_email_from Alexandre.Cassen@firewall.loc\n   smtp_server 192.168.200.1\n   smtp_connect_timeout 30\n   router_id LVS_DEVEL\n   vrrp_skip_check_adv_addr\n<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">#   vrrp_strict<\/mark>\n   vrrp_garp_interval 0\n   vrrp_gna_interval 0\n}\n\nvrrp_instance VI_1 {\n   <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\"> state BACKUP<\/mark>\n    interface eth0\n    virtual_router_id 51\n    <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">priority 100\n<\/mark>    advert_int 1\n    authentication {\n        auth_type PASS\n        auth_pass 1111\n    }\n    virtual_ipaddress {\n        <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">192.168.0.250\/24<\/mark>\n    }\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">6\u3001\u91cd\u542fkeepalived\u670d\u52a1\uff0c\u5e76\u914d\u7f6e\u5f00\u673a\u81ea\u542f\u52a8<\/h4>\n\n\n\n<pre class=\"wp-block-code has-pale-ocean-gradient-background has-background\"><code>systemctl restart keepalived.service \nsystemctl enable  keepalived.service <\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">7\u3001\u6d4b\u8bd5\u662f\u5426\u6210\u529f<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728A\u4e3b\u673a\u4e0a\u8fd0\u884c<\/p>\n\n\n\n<pre class=\"wp-block-code has-pale-ocean-gradient-background has-background\"><code>ip add show  \uff08\u67e5\u770b\u662f\u5426\u53ef\u4ee5\u770b\u5230VIP\u5730\u5740\uff09\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728B\u4e3b\u673a\u8fd0\u884c<\/p>\n\n\n\n<pre class=\"wp-block-code has-pale-ocean-gradient-background has-background\"><code>ip add show  \uff08\u6b63\u5e38\u60c5\u51b5\u4e0b\u65e0\u6cd5\u83b7\u53d6\u5230VIP\u5730\u5740\uff09<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">8\u3001\u6a21\u62df\u6545\u969c\u4e0bVIP\u662f\u5426\u4f1a\u6f02\u79fb<\/h4>\n\n\n\n<div style=\"height:32px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u5c06A\u4e3b\u673a\u5173\u673a  \u67e5\u770bB\u4e3b\u673a\u6b63\u786e\u83b7\u53d6\u5230VIP\u5730\u5740<\/p>\n\n\n\n<pre class=\"wp-block-code has-pale-ocean-gradient-background has-background\"><code>ip  add  show\uff08\u67e5\u770b\u662f\u5426\u53ef\u4ee5\u770b\u5230VIP\u5730\u5740\uff09<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001\u89c4\u5212 A\u4e3b\u673a \uff1a192.168.1.00 B\u4e3b\u673a\uff1a192.168.1.101 VIP\uff1a192.168.0.250 2\u3001\u8bbe\u7f6eA\u4e3b\u673a\u4e3a\uff1aMASTER \u4e3b\u673aB\u4e3a\uff1aBACKUP 3\u3001\u5b89\u88c5keepalived 4\u3001\u914d\u7f6eA\u4e3b\u673a\u7684 keepalived\u914d\u7f6e\u6587\u4ef6 5\u3001\u914d\u7f6eB\u4e3b\u673a\u7684 keepalived\u914d\u7f6e\u6587\u4ef6 6\u3001\u91cd\u542fkeepalived\u670d\u52a1\uff0c\u5e76\u914d\u7f6e\u5f00\u673a\u81ea\u542f\u52a8 7\u3001\u6d4b\u8bd5\u662f\u5426\u6210\u529f \u5728A\u4e3b\u673a\u4e0a\u8fd0\u884c \u5728B\u4e3b\u673a\u8fd0\u884c 8\u3001\u6a21\u62df\u6545\u969c\u4e0bVIP\u662f\u5426\u4f1a\u6f02\u79fb \u5c06A\u4e3b\u673a\u5173\u673a \u67e5\u770bB\u4e3b\u673a\u6b63\u786e\u83b7\u53d6\u5230VIP\u5730\u5740<\/p>\n","protected":false},"author":1,"featured_media":189,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[23],"class_list":["post-196","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-5","tag-keepalived"],"_links":{"self":[{"href":"https:\/\/www.zhangwk.cn\/index.php\/wp-json\/wp\/v2\/posts\/196","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhangwk.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangwk.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangwk.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangwk.cn\/index.php\/wp-json\/wp\/v2\/comments?post=196"}],"version-history":[{"count":6,"href":"https:\/\/www.zhangwk.cn\/index.php\/wp-json\/wp\/v2\/posts\/196\/revisions"}],"predecessor-version":[{"id":206,"href":"https:\/\/www.zhangwk.cn\/index.php\/wp-json\/wp\/v2\/posts\/196\/revisions\/206"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.zhangwk.cn\/index.php\/wp-json\/wp\/v2\/media\/189"}],"wp:attachment":[{"href":"https:\/\/www.zhangwk.cn\/index.php\/wp-json\/wp\/v2\/media?parent=196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangwk.cn\/index.php\/wp-json\/wp\/v2\/categories?post=196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangwk.cn\/index.php\/wp-json\/wp\/v2\/tags?post=196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}