{"id":17237,"date":"2024-11-18T08:51:29","date_gmt":"2024-11-18T00:51:29","guid":{"rendered":"https:\/\/fwq.ai\/blog\/17237\/"},"modified":"2024-11-18T08:51:29","modified_gmt":"2024-11-18T00:51:29","slug":"%e5%a6%82%e4%bd%95%e6%90%ad%e5%bb%ba%e9%ab%98%e5%8f%af%e7%94%a8%e7%9a%84linux%e9%9b%86%e7%be%a4%e7%8e%af%e5%a2%83","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/17237\/","title":{"rendered":"\u5982\u4f55\u642d\u5efa\u9ad8\u53ef\u7528\u7684Linux\u96c6\u7fa4\u73af\u5883"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/465\/014\/169932054787669.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u642d\u5efa\u9ad8\u53ef\u7528\u7684Linux\u96c6\u7fa4\u73af\u5883\u63d2\u56fe\" alt=\"\u5982\u4f55\u642d\u5efa\u9ad8\u53ef\u7528\u7684Linux\u96c6\u7fa4\u73af\u5883\u63d2\u56fe\" \/><\/p>\n<p>\u5982\u4f55\u642d\u5efa\u9ad8\u53ef\u7528\u7684Linux\u96c6\u7fa4\u73af\u5883<\/p>\n<p>\u6982\u8ff0\uff1a<br \/>\u968f\u7740\u4e92\u8054\u7f51\u7684\u5feb\u901f\u53d1\u5c55\u548c\u4e1a\u52a1\u9700\u6c42\u7684\u4e0d\u65ad\u589e\u957f\uff0c\u9ad8\u53ef\u7528\u6027\u6210\u4e3a\u73b0\u4ee3\u8ba1\u7b97\u7cfb\u7edf\u8bbe\u8ba1\u7684\u91cd\u8981\u76ee\u6807\u4e4b\u4e00\u3002Linux\u96c6\u7fa4\u73af\u5883\u662f\u5b9e\u73b0\u9ad8\u53ef\u7528\u6027\u7684\u4e00\u79cd\u5e38\u89c1\u89e3\u51b3\u65b9\u6848\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u642d\u5efa\u9ad8\u53ef\u7528\u7684Linux\u96c6\u7fa4\u73af\u5883\uff0c\u5e76\u63d0\u4f9b\u8be6\u7ec6\u7684\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<p>\u4e00\u3001\u9009\u53d6\u5408\u9002\u7684\u96c6\u7fa4\u8f6f\u4ef6<br \/>Linux\u7cfb\u7edf\u6709\u591a\u79cd\u53ef\u9009\u7684\u96c6\u7fa4\u8f6f\u4ef6\uff0c\u5982Pacemaker\u3001Keepalived\u3001Heartbeat\u7b49\u3002\u5728\u9009\u62e9\u96c6\u7fa4\u8f6f\u4ef6\u65f6\uff0c\u9700\u8981\u8003\u8651\u4ee5\u4e0b\u56e0\u7d20\uff1a<\/p>\n<ol>\n<li>\u7cfb\u7edf\u7a33\u5b9a\u6027\uff1a\u9009\u62e9\u7ecf\u8fc7\u957f\u671f\u4f7f\u7528\u3001\u7a33\u5b9a\u6027\u8f83\u597d\u7684\u8f6f\u4ef6\uff1b<\/li>\n<li>\u793e\u533a\u652f\u6301\uff1a\u9009\u62e9\u6709\u6d3b\u8dc3\u793e\u533a\u652f\u6301\u548c\u957f\u671f\u7ef4\u62a4\u7684\u8f6f\u4ef6\uff1b<\/li>\n<li>\u529f\u80fd\u4e30\u5bcc\u6027\uff1a\u9009\u62e9\u5177\u5907\u6240\u9700\u529f\u80fd\u7684\u8f6f\u4ef6\uff1b<\/li>\n<li>\u6613\u7528\u6027\uff1a\u9009\u62e9\u6613\u4e8e\u914d\u7f6e\u548c\u7ba1\u7406\u7684\u8f6f\u4ef6\u3002<\/li>\n<\/ol>\n<p>\u4e8c\u3001\u5b89\u88c5\u914d\u7f6e\u96c6\u7fa4\u8f6f\u4ef6<br \/>\u4ee5Pacemaker\u4f5c\u4e3a\u793a\u4f8b\uff0c\u4ecb\u7ecd\u5176\u5b89\u88c5\u548c\u914d\u7f6e\u8fc7\u7a0b\u3002<\/p>\n<ol>\n<li>\n<p>\u5b89\u88c5\u96c6\u7fa4\u8f6f\u4ef6\uff1a<br \/>\u5728\u6240\u6709\u8282\u70b9\u4e0a\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Pacemaker\uff1a<\/p>\n<pre>sudo apt-get install pacemaker corosync<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/li>\n<li>\n<p>\u914d\u7f6e\u96c6\u7fa4\u8f6f\u4ef6\uff1a<br \/>\u7f16\u8f91corosync\u7684\u914d\u7f6e\u6587\u4ef6\/etc\/corosync\/corosync.conf\uff0c\u8bbe\u7f6e\u8282\u70b9\u95f4\u901a\u4fe1\u548c\u96c6\u7fa4IP\u5730\u5740\u7b49\u53c2\u6570\uff1a<\/p>\n<pre>totem {\n version: 2\n secauth: off\n cluster_name: mycluster\n transport: udpu\n}\n\nnodelist {\n node {\n     ring0_addr: &lt;node1_ip&gt;\n     nodeid: 1\n }\n node {\n     ring0_addr: &lt;node2_ip&gt;\n     nodeid: 2\n }\n}\n\nquorum {\n provider: corosync_votequorum\n two_node: 1\n}&lt;\/node2_ip&gt;&lt;\/node1_ip&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/li>\n<\/ol>\n<p>\u7f16\u5199Pacemaker\u7684\u914d\u7f6e\u6587\u4ef6\/etc\/corosync\/cib.xml\uff0c\u914d\u7f6e\u96c6\u7fa4\u8d44\u6e90\u548c\u7ea6\u675f\u7b49\u4fe1\u606f\u3002<br \/>\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a\u57fa\u672c\u7684Apache\u865a\u62dfIP\u8d44\u6e90\uff1a<\/p>\n<pre>&lt;cib ...&gt;&lt;configuration&gt;&lt;resources&gt;&lt;primitive id=\"virtual_ip\" class=\"ocf:heartbeat:IPaddr2\"&gt;&lt;instance_attributes ip=\"192.168.1.100\" cidr_netmask=\"24\"&gt;&lt;\/instance_attributes&gt;&lt;operations&gt;&lt;op name=\"monitor\" interval=\"10s\"&gt;&lt;\/op&gt;&lt;op name=\"start\" interval=\"0s\"&gt;&lt;\/op&gt;&lt;op name=\"stop\" interval=\"0s\"&gt;&lt;\/op&gt;&lt;\/operations&gt;&lt;\/primitive&gt;&lt;\/resources&gt;&lt;constraints&gt;&lt;rsc_location rule=\"1000\" score=\"-INFINITY\" id=\"constraint_virtual_ip\" node=\"node1\"&gt;&lt;\/rsc_location&gt;&lt;\/constraints&gt;&lt;\/configuration&gt;&lt;\/cib&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li>\n<p>\u542f\u52a8\u96c6\u7fa4\u670d\u52a1\uff1a<br \/>\u5728\u6240\u6709\u8282\u70b9\u4e0a\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8\u96c6\u7fa4\u670d\u52a1\uff1a<\/p>\n<pre>sudo service corosync start\nsudo service pacemaker start<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/li>\n<\/ol>\n<p>\u4e09\u3001\u9a8c\u8bc1\u96c6\u7fa4\u73af\u5883<\/p>\n<ol>\n<li>\n<p>\u67e5\u770b\u96c6\u7fa4\u72b6\u6001\uff1a<br \/>\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b\u96c6\u7fa4\u72b6\u6001\uff1a<\/p>\n<pre>sudo crm_mon<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5982\u679c\u8f93\u51fa\u4e2d\u663e\u793a\u6240\u6709\u8282\u70b9\u90fd\u6b63\u5e38\u8fd0\u884c\uff0c\u5219\u8868\u793a\u96c6\u7fa4\u73af\u5883\u5df2\u6210\u529f\u642d\u5efa\u3002<\/p>\n<\/li>\n<li>\n<p>\u6d4b\u8bd5\u8d44\u6e90\u8fc1\u79fb\uff1a<br \/>\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u6d4b\u8bd5\u8d44\u6e90\u8fc1\u79fb\u529f\u80fd\uff1a<\/p>\n<pre>sudo crm resource migrate virtual_ip node2<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5982\u679c\u8d44\u6e90\u8fc1\u79fb\u6210\u529f\uff0c\u5e76\u4e14\u865a\u62dfIP\u5730\u5740\u88ab\u8f6c\u79fb\u5230\u4e86node2\u8282\u70b9\uff0c\u5219\u8868\u793a\u8d44\u6e90\u8fc1\u79fb\u529f\u80fd\u6b63\u5e38\u3002<\/p>\n<\/li>\n<\/ol>\n<p>\u56db\u3001\u603b\u7ed3<br \/>\u901a\u8fc7\u9009\u62e9\u5408\u9002\u7684\u96c6\u7fa4\u8f6f\u4ef6\uff0c\u5b89\u88c5\u914d\u7f6e\u96c6\u7fa4\u8f6f\u4ef6\uff0c\u4ee5\u53ca\u9a8c\u8bc1\u96c6\u7fa4\u73af\u5883\uff0c\u6211\u4eec\u6210\u529f\u642d\u5efa\u4e86\u9ad8\u53ef\u7528\u7684Linux\u96c6\u7fa4\u73af\u5883\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u8fd8\u9700\u8981\u6839\u636e\u5177\u4f53\u4e1a\u52a1\u9700\u6c42\uff0c\u914d\u7f6e\u5176\u4ed6\u9ad8\u53ef\u7528\u8d44\u6e90\uff0c\u5982\u6570\u636e\u5e93\u3001\u5e94\u7528\u670d\u52a1\u7b49\u3002\u901a\u8fc7\u5408\u7406\u914d\u7f6e\u548c\u7ba1\u7406\uff0c\u53ef\u4ee5\u786e\u4fdd\u9ad8\u53ef\u7528\u6027\uff0c\u5e76\u63d0\u4f9b\u53ef\u9760\u7684\u670d\u52a1\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u642d\u5efa\u9ad8\u53ef\u7528\u7684Linux\u96c6\u7fa4\u73af\u5883\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u642d\u5efa\u9ad8\u53ef\u7528\u7684Linux\u96c6\u7fa4\u73af\u5883 \u6982\u8ff0\uff1a\u968f\u7740\u4e92\u8054\u7f51\u7684\u5feb\u901f\u53d1\u5c55\u548c\u4e1a\u52a1\u9700\u6c42\u7684\u4e0d\u65ad\u589e\u957f\uff0c\u9ad8\u53ef\u7528\u6027\u6210\u4e3a\u73b0\u4ee3\u8ba1\u7b97\u7cfb\u7edf\u8bbe\u8ba1\u7684\u91cd\u8981\u76ee\u6807\u4e4b\u4e00\u3002Linux\u96c6\u7fa4\u73af\u5883\u662f\u5b9e\u73b0\u9ad8\u53ef\u7528\u6027\u7684\u4e00\u79cd\u5e38\u89c1\u89e3\u51b3\u65b9\u6848\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u642d\u5efa\u9ad8\u53ef\u7528\u7684Linux\u96c6\u7fa4\u73af\u5883\uff0c\u5e76\u63d0\u4f9b\u8be6\u7ec6\u7684\u4ee3\u7801\u793a\u4f8b\u3002 \u4e00\u3001\u9009\u53d6\u5408\u9002\u7684\u96c6\u7fa4\u8f6f\u4ef6Linux\u7cfb\u7edf\u6709\u591a\u79cd\u53ef\u9009\u7684\u96c6\u7fa4\u8f6f\u4ef6\uff0c\u5982Pacemaker\u3001Keepalived\u3001Heartbeat\u7b49\u3002\u5728\u9009\u62e9\u96c6\u7fa4\u8f6f\u4ef6\u65f6\uff0c\u9700\u8981\u8003\u8651\u4ee5\u4e0b\u56e0\u7d20\uff1a \u7cfb\u7edf\u7a33\u5b9a\u6027\uff1a\u9009\u62e9\u7ecf\u8fc7\u957f\u671f\u4f7f\u7528\u3001\u7a33\u5b9a\u6027\u8f83\u597d\u7684\u8f6f\u4ef6\uff1b \u793e\u533a\u652f\u6301\uff1a\u9009\u62e9\u6709\u6d3b\u8dc3\u793e\u533a\u652f\u6301\u548c\u957f\u671f\u7ef4\u62a4\u7684\u8f6f\u4ef6\uff1b \u529f\u80fd\u4e30\u5bcc\u6027\uff1a\u9009\u62e9\u5177\u5907\u6240\u9700\u529f\u80fd\u7684\u8f6f\u4ef6\uff1b \u6613\u7528\u6027\uff1a\u9009\u62e9\u6613\u4e8e\u914d\u7f6e\u548c\u7ba1\u7406\u7684\u8f6f\u4ef6\u3002 \u4e8c\u3001\u5b89\u88c5\u914d\u7f6e\u96c6\u7fa4\u8f6f\u4ef6\u4ee5Pacemaker\u4f5c\u4e3a\u793a\u4f8b\uff0c\u4ecb\u7ecd\u5176\u5b89\u88c5\u548c\u914d\u7f6e\u8fc7\u7a0b\u3002 \u5b89\u88c5\u96c6\u7fa4\u8f6f\u4ef6\uff1a\u5728\u6240\u6709\u8282\u70b9\u4e0a\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Pacemaker\uff1a sudo apt-get install pacemaker corosync \u767b\u5f55\u540e\u590d\u5236 \u914d\u7f6e\u96c6\u7fa4\u8f6f\u4ef6\uff1a\u7f16\u8f91corosync\u7684\u914d\u7f6e\u6587\u4ef6\/etc\/corosync\/corosync.conf\uff0c\u8bbe\u7f6e\u8282\u70b9\u95f4\u901a\u4fe1\u548c\u96c6\u7fa4IP\u5730\u5740\u7b49\u53c2\u6570\uff1a totem { version: 2 secauth: off cluster_name: mycluster transport: udpu } nodelist { node { ring0_addr: &lt;node1_ip&gt; nodeid: 1 } node { ring0_addr: &lt;node2_ip&gt; nodeid: 2 } } quorum { provider: corosync_votequorum two_node: 1 }&lt;\/node2_ip&gt;&lt;\/node1_ip&gt; \u767b\u5f55\u540e\u590d\u5236 \u7f16\u5199Pacemaker\u7684\u914d\u7f6e\u6587\u4ef6\/etc\/corosync\/cib.xml\uff0c\u914d\u7f6e\u96c6\u7fa4\u8d44\u6e90\u548c\u7ea6\u675f\u7b49\u4fe1\u606f\u3002\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a\u57fa\u672c\u7684Apache\u865a\u62dfIP\u8d44\u6e90\uff1a &lt;cib &#8230;&gt;&lt;configuration&gt;&lt;resources&gt;&lt;primitive [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-17237","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/17237","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=17237"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/17237\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=17237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=17237"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=17237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}