{"id":1472,"date":"2020-06-04T00:09:07","date_gmt":"2020-06-03T16:09:07","guid":{"rendered":"http:\/\/39.97.231.10\/?p=1472"},"modified":"2020-06-04T00:09:07","modified_gmt":"2020-06-03T16:09:07","slug":"mysql-mgr-%e9%9b%86%e7%be%a4%e9%83%a8%e7%bd%b2","status":"publish","type":"post","link":"http:\/\/www.weijing.co\/?p=1472","title":{"rendered":"MySQL MGR \u96c6\u7fa4\u90e8\u7f72"},"content":{"rendered":"<div>\n<h2>1. MySQL MGR\u4ecb\u7ecd<\/h2>\n<p>MySQL Group Replication\uff08MGR\uff09\u662fMySQL\u5b98\u65b9\u57285.7.17\u7248\u672c\u5f15\u8fdb\u7684\u4e00\u4e2a\u6570\u636e\u5e93\u9ad8\u53ef\u7528\u4e0e\u9ad8\u6269\u5c55\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u4ee5\u63d2\u4ef6\u5f62\u5f0f\u63d0\u4f9b\uff0c\u5b9e\u73b0\u4e86\u5206\u5e03\u5f0f\u4e0b\u6570\u636e\u7684\u6700\u7ec8\u4e00\u81f4\u6027\uff0cMGR\u7279\u70b9\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\u9ad8\u4e00\u81f4\u6027\uff1a\u57fa\u4e8e\u5206\u5e03\u5f0fpaxos\u534f\u8bae\u5b9e\u73b0\u7ec4\u590d\u5236\uff0c\u4fdd\u8bc1\u6570\u636e\u4e00\u81f4\u6027\uff1b<\/li>\n<li>\u9ad8\u5bb9\u9519\u6027\uff1a\u81ea\u52a8\u68c0\u6d4b\u673a\u5236\uff0c\u53ea\u8981\u4e0d\u662f\u5927\u591a\u6570\u8282\u70b9\u90fd\u5b95\u673a\u5c31\u53ef\u4ee5\u7ee7\u7eed\u5de5\u4f5c\uff0c\u5185\u7f6e\u9632\u8111\u88c2\u4fdd\u62a4\u673a\u5236\uff1b<\/li>\n<li>\u9ad8\u6269\u5c55\u6027\uff1a\u8282\u70b9\u7684\u589e\u52a0\u4e0e\u79fb\u9664\u4f1a\u81ea\u52a8\u66f4\u65b0\u7ec4\u6210\u5458\u4fe1\u606f\uff0c\u65b0\u8282\u70b9\u52a0\u5165\u540e\uff0c\u81ea\u52a8\u4ece\u5176\u4ed6\u8282\u70b9\u540c\u6b65\u589e\u91cf\u6570\u636e\uff0c\u76f4\u5230\u4e0e\u5176\u4ed6\u8282\u70b9\u6570\u636e\u4e00\u81f4\uff1b<\/li>\n<li>\u9ad8\u7075\u6d3b\u6027\uff1a\u63d0\u4f9b\u5355\u4e3b\u6a21\u5f0f\u548c\u591a\u4e3b\u6a21\u5f0f\uff0c\u5355\u4e3b\u6a21\u5f0f\u5728\u4e3b\u5e93\u5b95\u673a\u540e\u80fd\u591f\u81ea\u52a8\u9009\u4e3b\uff0c\u6240\u6709\u5199\u5165\u90fd\u5728\u4e3b\u8282\u70b9\u8fdb\u884c\uff0c\u591a\u4e3b\u6a21\u5f0f\u652f\u6301\u591a\u8282\u70b9\u5199\u5165\u3002<\/li>\n<\/ul>\n<h2>2. \u73af\u5883\u8bf4\u660e\uff1a<\/h2>\n<p>MySQL\u7248\u672c\uff1a8.0.11<br \/>\nOS\u7cfb\u7edf\u7248\u672c\uff1aCentOS 7.3<br \/>\nIP\u5730\u5740\u89c4\u5212\uff1a<\/p>\n<ul>\n<li>192.168.56.101<\/li>\n<li>192.168.56.102<\/li>\n<li>192.168.56.103<\/li>\n<\/ul>\n<h2>3. \u5b89\u88c5\u6b65\u9aa4<\/h2>\n<h3>3.1 \u5b89\u88c5MySQL8.0<\/h3>\n<p>MySQL\u5b98\u65b9\u72488.0.11\uff0c\u91c7\u7528Linux Generic\u5b89\u88c5\u65b9\u5f0f\uff0c\u76f4\u63a5\u4e0b\u8f7d\u538b\u7f29\u5305\uff0c\u89e3\u538b\u5230\u76ee\u5f55\/usr\/local\/mysql8.0\u3002<\/p>\n<h3>3.2 \u4fee\u6539\u914d\u7f6e\u6587\u4ef6<\/h3>\n<p>\u7f16\u8f91\u914d\u7f6e\u6587\u4ef6 \/home\/mysql\/etc\/my_mgr_8.0.cnf\uff0c3\u4e2a\u8282\u70b9\u9664\u4e86server_id\u3001loose-group_replication_local_address\u3001report_host \u4e09\u4e2a\u53c2\u6570\u4e0d\u4e00\u6837\u5916\uff0c\u5176\u4ed6\u4fdd\u6301\u4e00\u81f4\u3002<\/p>\n<div>\n<pre># \/home\/mysql\/etc\/my_mgr_8.0.cnf\n[mysqld]\nport=3306\nbasedir=\/usr\/local\/mysql8.0\ndatadir=\/mysql\/data_mgr_8.0\/\nsocket=\/mysql\/data_mgr_8.0\/mysql.sock\npid_file=\/mysql\/data_mgr_8.0\/mysql.pid\nserver_id=1\ngtid_mode=ON\nenforce_gtid_consistency=ON\nbinlog_checksum=NONE\nlog_bin=binlog\nlog_slave_updates=ON\nbinlog_format=ROW\nmaster_info_repository=TABLE\nrelay_log_info_repository=TABLE\ntransaction_write_set_extraction=XXHASH64\nloose-group_replication_group_name=\\\"aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa\\\"\nloose-group_replication_start_on_boot=OFF\nloose-group_replication_local_address= \\\"192.168.56.101:33061\\\"\nloose-group_replication_group_seeds= \\\"192.168.56.101:33061,192.168.56.102:33061,192.168.56.103:33061\\\"\nloose-group_replication_bootstrap_group=OFF\nreport_host=192.168.56.101\nreport_port=3306\n<\/pre>\n<\/div>\n<h3><\/h3>\n<h3>3.3 \u521d\u59cb\u5316\u6570\u636e\u5e93\uff08\u6240\u6709\u8282\u70b9\u6267\u884c\uff09<\/h3>\n<div>\n<pre>useradd mysql\nmkdir -p \/mysql\/data_mgr_8.0\nsudo chown -R mysql.mysql \/mysql\/data_mgr_8.0\/\nsudo chown -R mysql.mysql \/home\/mysql\/etc\/\n\/usr\/local\/mysql8.0\/bin\/mysqld --initialize-insecure --basedir=\/usr\/local\/mysql8.0 --datadir=\/mysql\/data_mgr_8.0 --user=mysql\n<\/pre>\n<\/div>\n<h3><\/h3>\n<h3>3.4 \u542f\u52a8\u6570\u636e\u5e93\uff0c\u5b89\u88c5MGR\u63d2\u4ef6\uff0c\u8bbe\u7f6e\u590d\u5236\u8d26\u53f7\uff08\u6240\u6709\u8282\u70b9\u6267\u884c\uff09<\/h3>\n<div>\n<pre># \u542f\u52a8\u6570\u636e\u5e93\nsu - mysql -c \\\"\/usr\/local\/mysql8.0\/bin\/mysqld_safe --defaults-file=\/home\/mysql\/etc\/my_mgr_8.0.cnf &amp;\\\"\n# \u767b\u5f55\u6570\u636e\u5e93\n\/usr\/local\/mysql8.0\/bin\/mysql -S \/mysql\/data_mgr_8.0\/mysql.sock\n# \u5b89\u88c5MGR\u63d2\u4ef6\nmysql&gt;INSTALL PLUGIN group_replication SONAME \\'group_replication.so\\';\n#\u8bbe\u7f6e\u590d\u5236\u8d26\u53f7\nmysql&gt; SET SQL_LOG_BIN=0;\nmysql&gt; CREATE USER repl@\\'%\\' IDENTIFIED BY \\'repl\\';\nmysql&gt; GRANT REPLICATION SLAVE ON *.* TO repl@\\'%\\';\nmysql&gt; FLUSH PRIVILEGES;\nmysql&gt; SET SQL_LOG_BIN=1;\nmysql&gt; CHANGE MASTER TO MASTER_USER=\\'repl\\', MASTER_PASSWORD=\\'repl\\' FOR CHANNEL \\'group_replication_recovery\\';\n<\/pre>\n<\/div>\n<h3><\/h3>\n<h3>3.5 \u542f\u52a8MGR\u5355\u4e3b\u6a21\u5f0f<\/h3>\n<div>\n<pre># \u542f\u52a8MGR\uff0c\u5728\u4e3b\u5e93(192.168.56.101)\u4e0a\u6267\u884c\nmysql&gt; SET GLOBAL group_replication_bootstrap_group=ON;\nmysql&gt; START GROUP_REPLICATION;\nmysql&gt; SET GLOBAL group_replication_bootstrap_group=OFF;\n# \u67e5\u770bMGR\u7ec4\u4fe1\u606f\nmysql&gt; SELECT * FROM performance_schema.replication_group_members;\n+---------------------------+--------------------------------------+------------------------+-------------+--------------+-------------+----------------+\n| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST    | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION |\n+---------------------------+--------------------------------------+------------------------+-------------+--------------+-------------+----------------+\n| group_replication_applier | 8cb3f19b-8414-11e8-9d34-fa163eda7360 | 192.168.56.101 |        3306 | ONLINE       | PRIMARY     | 8.0.11         |\n+---------------------------+--------------------------------------+------------------------+-------------+--------------+-------------+----------------+\n1 row in set (0.01 sec)\n# \u5176\u4ed6\u8282\u70b9\u52a0\u5165MGR\uff0c\u5728\u4ece\u5e93\uff08192.168.56.102\uff0c192.168.56.103\uff09\u4e0a\u6267\u884c\nmysql&gt; START GROUP_REPLICATION;\n# \u67e5\u770bMGR\u7ec4\u4fe1\u606f\nmysql&gt; SELECT * FROM performance_schema.replication_group_members;\n+---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+----------------+\n| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST  | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION |\n+---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+----------------+\n| group_replication_applier | 5254cf46-8415-11e8-af09-fa163eab3dcf | 192.168.56.102 |        3306 | ONLINE       | SECONDARY   | 8.0.11         |\n| group_replication_applier | 601a4025-8415-11e8-b2b6-fa163e767b9a | 192.168.56.103 |        3306 | ONLINE       | SECONDARY   | 8.0.11         |\n| group_replication_applier | 8cb3f19b-8414-11e8-9d34-fa163eda7360 | 192.168.56.101 |        3306 | ONLINE       | PRIMARY     | 8.0.11         |\n+---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+----------------+\n3 rows in set (0.00 sec)\n<\/pre>\n<\/div>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c3\u4e2a\u8282\u70b9\u72b6\u6001\u4e3aonline\uff0c\u5e76\u4e14\u4e3b\u8282\u70b9\u4e3a192.168.56.101\uff0c\u53ea\u6709\u4e3b\u8282\u70b9\u53ef\u4ee5\u5199\u5165\uff0c\u5176\u4ed6\u8282\u70b9\u53ea\u8bfb\uff0cMGR\u5355\u4e3b\u6a21\u5f0f\u642d\u5efa\u6210\u529f\u3002<\/p>\n<h3>3.6 \u5207\u6362\u5230\u591a\u4e3b\u6a21\u5f0f<\/h3>\n<p>MGR\u5207\u6362\u6a21\u5f0f\u9700\u8981\u91cd\u65b0\u542f\u52a8\u7ec4\u590d\u5236\uff0c\u56e0\u4e9b\u9700\u8981\u5728\u6240\u6709\u8282\u70b9\u4e0a\u5148\u5173\u95ed\u7ec4\u590d\u5236\uff0c\u8bbe\u7f6e group_replication_single_primary_mode=OFF \u7b49\u53c2\u6570\uff0c\u518d\u542f\u52a8\u7ec4\u590d\u5236\u3002<\/p>\n<div>\n<pre># \u505c\u6b62\u7ec4\u590d\u5236(\u6240\u6709\u8282\u70b9\u6267\u884c)\uff1a\nmysql&gt; stop group_replication;\nmysql&gt; set global group_replication_single_primary_mode=OFF;\nmysql&gt; set global group_replication_enforce_update_everywhere_checks=ON;\n# \u968f\u4fbf\u9009\u62e9\u67d0\u4e2a\u8282\u70b9\u6267\u884c\nmysql&gt; SET GLOBAL group_replication_bootstrap_group=ON;\nmysql&gt; START GROUP_REPLICATION;\nmysql&gt; SET GLOBAL group_replication_bootstrap_group=OFF;\n# \u5176\u4ed6\u8282\u70b9\u6267\u884c\nmysql&gt; START GROUP_REPLICATION;\n# \u67e5\u770b\u7ec4\u4fe1\u606f\uff0c\u6240\u6709\u8282\u70b9\u7684 MEMBER_ROLE \u90fd\u4e3a PRIMARY\nmysql&gt; SELECT * FROM performance_schema.replication_group_members;\n+---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+----------------+\n| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST  | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION |\n+---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+----------------+\n| group_replication_applier | 5254cf46-8415-11e8-af09-fa163eab3dcf | 192.168.56.102 |        3306 | ONLINE       | PRIMARY     | 8.0.11         |\n| group_replication_applier | 601a4025-8415-11e8-b2b6-fa163e767b9a | 192.168.56.103 |        3306 | ONLINE       | PRIMARY     | 8.0.11         |\n| group_replication_applier | 8cb3f19b-8414-11e8-9d34-fa163eda7360 | 192.168.56.101 |        3306 | ONLINE       | PRIMARY     | 8.0.11         |\n+---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+----------------+\n3 rows in set (0.00 sec)\n<\/pre>\n<\/div>\n<p>\u53ef\u4ee5\u770b\u5230\u6240\u6709\u8282\u70b9\u72b6\u6001\u90fd\u662fonline\uff0c\u89d2\u8272\u90fd\u662fPRIMARY\uff0cMGR\u591a\u4e3b\u6a21\u5f0f\u642d\u5efa\u6210\u529f\u3002<\/p>\n<h3>3.7 \u5207\u56de\u5355\u4e3b\u6a21\u5f0f<\/h3>\n<div>\n<pre># \u6240\u6709\u8282\u70b9\u6267\u884c\nmysql&gt; stop group_replication;\nmysql&gt; set global group_replication_enforce_update_everywhere_checks=OFF;\nmysql&gt; set global group_replication_single_primary_mode=ON;\n# \u4e3b\u8282\u70b9\uff08192.168.56.101\uff09\u6267\u884c\nSET GLOBAL group_replication_bootstrap_group=ON;\nSTART GROUP_REPLICATION;\nSET GLOBAL group_replication_bootstrap_group=OFF;\n# \u4ece\u8282\u70b9\uff08192.168.56.102\u3001192.168.56.103\uff09\u6267\u884c\nSTART GROUP_REPLICATION;\n# \u67e5\u770bMGR\u7ec4\u4fe1\u606f\nmysql&gt; SELECT * FROM performance_schema.replication_group_members;\n+---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+----------------+\n| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST  | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION |\n+---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+----------------+\n| group_replication_applier | 5254cf46-8415-11e8-af09-fa163eab3dcf | 192.168.56.102 |        3306 | ONLINE       | SECONDARY   | 8.0.11         |\n| group_replication_applier | 601a4025-8415-11e8-b2b6-fa163e767b9a | 192.168.56.103 |        3306 | ONLINE       | SECONDARY   | 8.0.11         |\n| group_replication_applier | 8cb3f19b-8414-11e8-9d34-fa163eda7360 | 192.168.56.101 |        3306 | ONLINE       | PRIMARY     | 8.0.11         |\n+---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+----------------+\n3 rows in set (0.00 sec)<\/pre>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. MySQL MGR\u4ecb\u7ecd MySQL Group Replication\uff08MGR\uff09\u662fMySQL\u5b98\u65b9\u57285.7 &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/www.weijing.co\/?p=1472\"> <span class=\"screen-reader-text\">MySQL MGR \u96c6\u7fa4\u90e8\u7f72<\/span> \u67e5\u770b\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[90],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"mailpoet_newsletter_max":false,"woocommerce_thumbnail":false,"woocommerce_single":false,"woocommerce_gallery_thumbnail":false,"shop_catalog":false,"shop_single":false,"shop_thumbnail":false},"uagb_author_info":{"display_name":"weijing","author_link":"http:\/\/www.weijing.co\/?author=4"},"uagb_comment_info":0,"uagb_excerpt":"1. MySQL MGR\u4ecb\u7ecd MySQL Group Replication\uff08MGR\uff09\u662fMySQL\u5b98\u65b9\u57285.7&hellip;","_links":{"self":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/1472"}],"collection":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1472"}],"version-history":[{"count":0,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/1472\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1472"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}