{"id":164613,"date":"2024-11-05T09:22:38","date_gmt":"2024-11-05T01:22:38","guid":{"rendered":"https:\/\/server.hk\/cnblog\/164613\/"},"modified":"2024-11-05T09:22:39","modified_gmt":"2024-11-05T01:22:39","slug":"%e5%85%b7%e5%82%99%e8%b2%a0%e8%bc%89%e5%9d%87%e8%a1%a1%e5%8a%9f%e8%83%bdmysql%e6%9c%8d%e5%8b%99%e5%99%a8%e9%9b%86%e7%be%a4%e9%83%a8%e7%bd%b2%e5%8f%8a%e5%af%a6%e7%8f%be","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/164613\/","title":{"rendered":"\u5177\u5099\u8ca0\u8f09\u5747\u8861\u529f\u80fdMySQL\u670d\u52d9\u5668\u96c6\u7fa4\u90e8\u7f72\u53ca\u5be6\u73fe"},"content":{"rendered":"<h1 id=\"%e5%85%b7%e5%82%99%e8%b2%a0%e8%bc%89%e5%9d%87%e8%a1%a1%e5%8a%9f%e8%83%bdmysql%e6%9c%8d%e5%8b%99%e5%99%a8%e9%9b%86%e7%be%a4%e9%83%a8%e7%bd%b2%e5%8f%8a%e5%af%a6%e7%8f%be-XpKigDIdhF\">\u5177\u5099\u8ca0\u8f09\u5747\u8861\u529f\u80fdMySQL\u670d\u52d9\u5668\u96c6\u7fa4\u90e8\u7f72\u53ca\u5be6\u73fe<\/h1>\n<p>\u5728\u7576\u4eca\u6578\u64da\u9a45\u52d5\u7684\u4e16\u754c\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u6027\u80fd\u548c\u53ef\u7528\u6027\u5c0d\u65bc\u4f01\u696d\u7684\u6210\u529f\u81f3\u95dc\u91cd\u8981\u3002MySQL\u4f5c\u70ba\u4e00\u500b\u6d41\u884c\u7684\u958b\u6e90\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u7a2e\u61c9\u7528\u7a0b\u5e8f\u4e2d\u3002\u70ba\u4e86\u63d0\u9ad8MySQL\u7684\u6027\u80fd\u548c\u53ef\u7528\u6027\uff0c\u8a31\u591a\u4f01\u696d\u9078\u64c7\u90e8\u7f72\u5177\u5099\u8ca0\u8f09\u5747\u8861\u529f\u80fd\u7684MySQL\u670d\u52d9\u5668\u96c6\u7fa4\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u5be6\u73fe\u9019\u4e00\u76ee\u6a19\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u5be6\u7528\u7684\u5efa\u8b70\u548c\u793a\u4f8b\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%afmysql%e6%9c%8d%e5%8b%99%e5%99%a8%e9%9b%86%e7%be%a4%ef%bc%9f-XpKigDIdhF\">\u4ec0\u9ebc\u662fMySQL\u670d\u52d9\u5668\u96c6\u7fa4\uff1f<\/h2>\n<p>MySQL\u670d\u52d9\u5668\u96c6\u7fa4\u662f\u4e00\u7d44\u76f8\u4e92\u9023\u63a5\u7684MySQL\u670d\u52d9\u5668\uff0c\u9019\u4e9b\u670d\u52d9\u5668\u5171\u540c\u5de5\u4f5c\u4ee5\u63d0\u4f9b\u9ad8\u53ef\u7528\u6027\u548c\u8ca0\u8f09\u5747\u8861\u3002\u901a\u904e\u5c07\u6578\u64da\u5206\u6563\u5230\u591a\u500b\u670d\u52d9\u5668\u4e0a\uff0c\u96c6\u7fa4\u53ef\u4ee5\u8655\u7406\u66f4\u591a\u7684\u8acb\u6c42\uff0c\u5f9e\u800c\u63d0\u9ad8\u6574\u9ad4\u6027\u80fd\u3002\u9019\u7a2e\u67b6\u69cb\u7279\u5225\u9069\u5408\u9700\u8981\u9ad8\u53ef\u7528\u6027\u548c\u5feb\u901f\u97ff\u61c9\u7684\u61c9\u7528\u7a0b\u5e8f\u3002<\/p>\n<h2 id=\"%e8%b2%a0%e8%bc%89%e5%9d%87%e8%a1%a1%e7%9a%84%e5%bf%85%e8%a6%81%e6%80%a7-XpKigDIdhF\">\u8ca0\u8f09\u5747\u8861\u7684\u5fc5\u8981\u6027<\/h2>\n<p>\u8ca0\u8f09\u5747\u8861\u662f\u6307\u5c07\u9032\u5165\u7684\u8acb\u6c42\u5206\u914d\u5230\u591a\u500b\u670d\u52d9\u5668\u4e0a\uff0c\u4ee5\u78ba\u4fdd\u6c92\u6709\u55ae\u4e00\u670d\u52d9\u5668\u904e\u8f09\u3002\u9019\u4e0d\u50c5\u63d0\u9ad8\u4e86\u7cfb\u7d71\u7684\u6027\u80fd\uff0c\u9084\u589e\u5f37\u4e86\u53ef\u7528\u6027\uff0c\u56e0\u70ba\u5373\u4f7f\u67d0\u500b\u670d\u52d9\u5668\u51fa\u73fe\u6545\u969c\uff0c\u5176\u4ed6\u670d\u52d9\u5668\u4ecd\u7136\u53ef\u4ee5\u7e7c\u7e8c\u63d0\u4f9b\u670d\u52d9\u3002\u5c0d\u65bcMySQL\u670d\u52d9\u5668\u96c6\u7fa4\u4f86\u8aaa\uff0c\u8ca0\u8f09\u5747\u8861\u662f\u5be6\u73fe\u9ad8\u53ef\u7528\u6027\u548c\u6027\u80fd\u7684\u95dc\u9375\u3002<\/p>\n<h2 id=\"mysql%e9%9b%86%e7%be%a4%e7%9a%84%e9%83%a8%e7%bd%b2%e6%ad%a5%e9%a9%9f-XpKigDIdhF\">MySQL\u96c6\u7fa4\u7684\u90e8\u7f72\u6b65\u9a5f<\/h2>\n<h3 id=\"1-%e7%92%b0%e5%a2%83%e6%ba%96%e5%82%99-XpKigDIdhF\">1. \u74b0\u5883\u6e96\u5099<\/h3>\n<p>\u5728\u958b\u59cb\u90e8\u7f72MySQL\u96c6\u7fa4\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u6e96\u5099\u597d\u74b0\u5883\u3002\u9019\u5305\u62ec\u9078\u64c7\u5408\u9069\u7684\u786c\u4ef6\u548c\u64cd\u4f5c\u7cfb\u7d71\uff0c\u4e26\u78ba\u4fdd\u6240\u6709\u670d\u52d9\u5668\u4e4b\u9593\u7684\u7db2\u7d61\u9023\u63a5\u826f\u597d\u3002\u5efa\u8b70\u4f7f\u7528Linux\u7cfb\u7d71\uff0c\u56e0\u70ba\u5b83\u5c0dMySQL\u7684\u652f\u6301\u8f03\u597d\u3002<\/p>\n<h3 id=\"2-%e5%ae%89%e8%a3%9dmysql-XpKigDIdhF\">2. \u5b89\u88ddMySQL<\/h3>\n<p>\u5728\u6bcf\u53f0\u670d\u52d9\u5668\u4e0a\u5b89\u88ddMySQL\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5728Ubuntu\u4e0a\u5b89\u88ddMySQL\uff1a<\/p>\n<pre><code>sudo apt update\nsudo apt install mysql-server<\/code><\/pre>\n<h3 id=\"3-%e9%85%8d%e7%bd%aemysql%e9%9b%86%e7%be%a4-XpKigDIdhF\">3. \u914d\u7f6eMySQL\u96c6\u7fa4<\/h3>\n<p>\u5728\u6bcf\u53f0\u670d\u52d9\u5668\u4e0a\u914d\u7f6eMySQL\uff0c\u4ee5\u4fbf\u5b83\u5011\u53ef\u4ee5\u76f8\u4e92\u901a\u4fe1\u3002\u9019\u5305\u62ec\u8a2d\u7f6e\u4e3b\u5f9e\u8907\u88fd\u6216\u4f7f\u7528MySQL Cluster\u6280\u8853\u3002\u4ee5\u4e0b\u662f\u8a2d\u7f6e\u4e3b\u5f9e\u8907\u88fd\u7684\u57fa\u672c\u6b65\u9a5f\uff1a<\/p>\n<ul>\n<li>\u5728\u4e3b\u670d\u52d9\u5668\u4e0a\uff0c\u7de8\u8f2fMySQL\u914d\u7f6e\u6587\u4ef6\uff08\u901a\u5e38\u4f4d\u65bc\/etc\/mysql\/my.cnf\uff09\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/li>\n<pre><code>[mysqld]\nserver-id=1\nlog_bin=mysql-bin<\/code><\/pre>\n<li>\u91cd\u555fMySQL\u670d\u52d9\uff1a<\/li>\n<pre><code>sudo systemctl restart mysql<\/code><\/pre>\n<li>\u5728\u5f9e\u670d\u52d9\u5668\u4e0a\uff0c\u7de8\u8f2f\u914d\u7f6e\u6587\u4ef6\uff0c\u8a2d\u7f6eserver-id\uff1a<\/li>\n<pre><code>[mysqld]\nserver-id=2<\/code><\/pre>\n<li>\u91cd\u555f\u5f9e\u670d\u52d9\u5668\u7684MySQL\u670d\u52d9\u3002<\/li>\n<\/ul>\n<h3 id=\"4-%e9%85%8d%e7%bd%ae%e8%b2%a0%e8%bc%89%e5%9d%87%e8%a1%a1-XpKigDIdhF\">4. \u914d\u7f6e\u8ca0\u8f09\u5747\u8861<\/h3>\n<p>\u53ef\u4ee5\u4f7f\u7528\u591a\u7a2e\u5de5\u5177\u4f86\u5be6\u73feMySQL\u7684\u8ca0\u8f09\u5747\u8861\uff0c\u4f8b\u5982HAProxy\u6216ProxySQL\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528HAProxy\u7684\u57fa\u672c\u914d\u7f6e\u793a\u4f8b\uff1a<\/p>\n<pre><code>frontend mysql_front\n    bind *:3306\n    default_backend mysql_back\n\nbackend mysql_back\n    balance roundrobin\n    server mysql1 192.168.1.1:3306 check\n    server mysql2 192.168.1.2:3306 check<\/code><\/pre>\n<p>\u9019\u6bb5\u914d\u7f6e\u5c07\u8acb\u6c42\u5747\u52fb\u5730\u5206\u914d\u5230\u5169\u53f0MySQL\u670d\u52d9\u5668\u4e0a\u3002<\/p>\n<h2 id=\"%e7%9b%a3%e6%8e%a7%e8%88%87%e7%b6%ad%e8%ad%b7-XpKigDIdhF\">\u76e3\u63a7\u8207\u7dad\u8b77<\/h2>\n<p>\u90e8\u7f72\u5b8c\u6210\u5f8c\uff0c\u6301\u7e8c\u76e3\u63a7MySQL\u96c6\u7fa4\u7684\u6027\u80fd\u81f3\u95dc\u91cd\u8981\u3002\u53ef\u4ee5\u4f7f\u7528\u5de5\u5177\u5982Prometheus\u548cGrafana\u4f86\u76e3\u63a7\u6578\u64da\u5eab\u7684\u6027\u80fd\u6307\u6a19\uff0c\u4e26\u53ca\u6642\u767c\u73fe\u6f5b\u5728\u554f\u984c\u3002\u6b64\u5916\uff0c\u5b9a\u671f\u5099\u4efd\u6578\u64da\u548c\u9032\u884c\u7dad\u8b77\u4e5f\u662f\u78ba\u4fdd\u7cfb\u7d71\u7a69\u5b9a\u904b\u884c\u7684\u91cd\u8981\u63aa\u65bd\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-XpKigDIdhF\">\u7e3d\u7d50<\/h2>\n<p>\u5177\u5099\u8ca0\u8f09\u5747\u8861\u529f\u80fd\u7684MySQL\u670d\u52d9\u5668\u96c6\u7fa4\u80fd\u5920\u986f\u8457\u63d0\u9ad8\u6578\u64da\u5eab\u7684\u6027\u80fd\u548c\u53ef\u7528\u6027\u3002\u901a\u904e\u5408\u7406\u7684\u90e8\u7f72\u548c\u914d\u7f6e\uff0c\u4f01\u696d\u53ef\u4ee5\u78ba\u4fdd\u5176\u61c9\u7528\u7a0b\u5e8f\u5728\u9ad8\u8ca0\u8f09\u60c5\u6cc1\u4e0b\u4ecd\u80fd\u7a69\u5b9a\u904b\u884c\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u53ef\u7528\u6027\u548c\u6027\u80fd\u7684\u696d\u52d9\uff0c\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002\u4e86\u89e3\u66f4\u591a\u95dc\u65bc <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u548c <a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a> \u7684\u4fe1\u606f\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u5177\u5099\u8ca0\u8f09\u5747\u8861\u529f\u80fd\u7684MySQL\u670d\u52d9\u5668\u96c6\u7fa4\u90e8\u7f72\u8207\u5be6\u73fe\uff0c\u63d0\u5347\u6578\u64da\u8655\u7406\u6548\u7387\u8207\u7cfb\u7d71\u7a69\u5b9a\u6027\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-164613","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/164613","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=164613"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/164613\/revisions"}],"predecessor-version":[{"id":164614,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/164613\/revisions\/164614"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=164613"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=164613"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=164613"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}