mysql group replication 安装配置详解
一、原起:
之前也有寫過mysql-group-replication (mgr) 相關(guān)的文章、那時也沒有什么特別的動力要寫好它、主要是因為在
mysql-5.7.20 之前的版本的mgr都有著各種各樣的問題、感覺像是一個半成品、但是5.7.20這個版本的mgr已經(jīng)基本
可用了。所以接下來打算把整個mgr系列寫完。
?
?
二、mysql-group-replication 安裝環(huán)境規(guī)劃:
主名 ip地址 在mgr中的角色
mtls17 10.186.19.17 primary
mtls18 10.186.19.18 seconde
mtls19 10.186.19.19 seconde
也就是說我打算在mtls17\18\19這三臺主機上安裝一套mgr數(shù)據(jù)集群環(huán)境、我打算用mtls17主機做主庫(primary)
另外兩臺主機做從庫(seconde)
?
別外、還有一件事我想了很久、就是要不要不mysql的安裝過程也加到博客里面、如果加的話就會顯得博客特別長、
沒有辦法凸出重點;可是如果只寫mgr相關(guān)內(nèi)容的話、一來讀者可能不一定能把環(huán)境搭建起來、二來影響博客的質(zhì)量
思量再三還是決定把mysql安裝的相應(yīng)步驟寫進來。
?
三、下載mysql-5.7.20社區(qū)版:
由于三臺機器上都要安裝、下面的命令要在三臺主機上執(zhí)行
cd /tmp/ wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz?
四、安裝mysql:
由于三臺主機上都要安裝、下面的命令要在三臺主機上執(zhí)行
cd /tmp/ tar -xvf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz -C /usr/local/cd /usr/local/ ln -s mysql-5.7.20-linux-glibc2.12-x86_64 mysql注意這里并沒有完成mysql的安裝、更準(zhǔn)確的說、這里只是把mysql安裝包解壓到了/usr/local而已 。要完成mysql
的安裝還有一系列的步驟。
?
?
五、創(chuàng)建mysql數(shù)據(jù)目錄 與 增加系統(tǒng)用戶mysql:
由于三臺主機上都要安裝、下面的命令要在三臺主機上執(zhí)行
mkdir -p /database/mysql/data/3306useradd mysqlchown -R mysql:mysql /database/mysql/data/3306 chown -R mysql:mysql /usr/local/mysql*?
?六、增加mysql的配置文件:
由于三臺主機上都要安裝、所以每臺主機上都要加
touch /etc/my.cnf1、mtls17的配置文件內(nèi)容如下
[mysqld] basedir=/usr/local/mysql/ datadir=/database/mysql/data/3306 port=3306 socket=/tmp/mysql.sockserver_id=17 gtid_mode=on enforce_gtid_consistency=on master_info_repository=table relay_log_info_repository=table binlog_checksum=none log_slave_updates=on log_bin=mysql-bin binlog_format=rowtransaction_write_set_extraction=XXHASH64 loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" loose-group_replication_start_on_boot=off loose-group_replication_local_address= "10.186.19.17:33060" loose-group_replication_group_seeds= "10.186.19.17:33060,10.186.19.18:33060,10.186.19.19:33060" loose-group_replication_bootstrap_group= off? 2、mtls18的配置文件的內(nèi)容如下
[mysqld] basedir=/usr/local/mysql/ datadir=/database/mysql/data/3306 port=3306 socket=/tmp/mysql.sockserver_id=18 gtid_mode=on enforce_gtid_consistency=on master_info_repository=table relay_log_info_repository=table binlog_checksum=none log_slave_updates=on log_bin=mysql-bin binlog_format=rowtransaction_write_set_extraction=XXHASH64 loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" loose-group_replication_start_on_boot=off loose-group_replication_local_address= "10.186.19.18:33060" loose-group_replication_group_seeds= "10.186.19.17:33060,10.186.19.18:33060,10.186.19.19:33060" loose-group_replication_bootstrap_group= off3、mtls19的配置文件如下
[mysqld] basedir=/usr/local/mysql/ datadir=/database/mysql/data/3306 port=3306 socket=/tmp/mysql.sockserver_id=19 gtid_mode=on enforce_gtid_consistency=on master_info_repository=table relay_log_info_repository=table binlog_checksum=none log_slave_updates=on log_bin=mysql-bin binlog_format=rowtransaction_write_set_extraction=XXHASH64 loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" loose-group_replication_start_on_boot=off loose-group_replication_local_address= "10.186.19.19:33060" loose-group_replication_group_seeds= "10.186.19.17:33060,10.186.19.18:33060,10.186.19.19:33060" loose-group_replication_bootstrap_group= off? 在這里有一些技術(shù)細節(jié)要說明一下:
上面的三個配置文件省略了所有不必要的配置項、但是看起來還是有點多、這些都是mgr環(huán)境要求的。
server_id 每個實例都要不要樣
loose-group_replication_group_name:為mgr高可用組起一個名字,這個名字一定要是uuid格式的。
loose-group_replication_local_address:mgr各實例之前都是要進行通信的、這個配置項設(shè)置的就是本
實例所監(jiān)聽的ip:端口
loose-group_replication_group_seeds:各mgr實例所監(jiān)聽的ip:端口信息
?
?
七、初始化mysql數(shù)據(jù)庫:
這個在三臺主機上都要執(zhí)行
cd /usr/local/mysql/ ./bin/mysqld --defaults-file=/etc/my.cnf --datadir=/database/mysql/data/3306/ --user=mysql --initialize-insecure?
?
八、配置mysql與systemd結(jié)合:
? 在redhat-7.x 與服務(wù)啟動相關(guān)的腳本、不在是之前的/etc/init.d/目錄的下腳本。而是一個/usr/lib/systemd/system/目錄
下配置文件。由于三臺主機上的mysql都要開機啟動、所以三臺主機上都要執(zhí)行如下的操作。
1、增加systemd相關(guān)的配置文件/usr/lib/systemd/system/mysql.service
touch /usr/lib/systemd/system/mysql.servicemysql.service 的內(nèi)容如下
[Unit] Description=MySQL Server Documentation=man:mysqld(8) Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html After=network.target After=syslog.target[Install] WantedBy=multi-user.target[Service] User=mysql Group=mysql ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf #LimitNOFILE = 5000 #Restart=on-failure #RestartPreventExitStatus=12、設(shè)置mysql開機啟動
systemctl enable mysql? 3、如果你使用的是redhat-6.x 那么上面的兩步可以用以下命令來完成
#配置開機啟動 cd /usr/local/mysql/ cp support-files/mysql.server /etc/init.d/mysqld chkconfig mysqld on#啟動mysql服務(wù) service mysqld start?
?
九、啟動mysql:
systemctl start mysql?
?
十、為了方便使用重新設(shè)置一下PATH環(huán)境變量:
echo 'PATH=/usr/local/mysql/bin/:$PATH' >>/etc/profilesource /etc/profile?
?
十一、配置mgr的第一個結(jié)點:
mgr中所有的結(jié)點都屬于一個邏輯上的組、這個組就像是QQ群一樣、是由群主建起來的、有了這個上組之后、
其它的結(jié)點就可以加入到這個組中來了。?mtls17來建群
以下步驟在mtls17主機上的mysql中執(zhí)行
第一步:創(chuàng)建用于復(fù)制的用戶
set sql_log_bin=0;create user mgruser@'%' identified by 'mtls@352';grant replication slave,replication client on *.* to mgruser@'%';create user mgruser@'127.0.0.1' identified by 'mtls@352';grant replication slave,replication client on *.* to mgruser@'127.0.0.1';create user mgruser@'localhost' identified by 'mtls@352';grant replication slave,replication client on *.* to mgruser@'localhost'; set sql_log_bin=1;第二步:配置復(fù)制所使用的用戶
change master to master_user='mgruser',master_password='mtls@352'for channel 'group_replication_recovery';第三步:安裝mysql group replication 這個插件
install plugin group_replication soname 'group_replication.so';第四步:建個群(官方點的說法就是初始化一個復(fù)制組)
set global group_replication_bootstrap_group=on; start group_replication; set global group_replication_bootstrap_group=off;以下是我完成這四步的過程:
[root@mtls17 mysql]# mysql -uroot Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.20-log MySQL Community Server (GPL)Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> set sql_log_bin=0; Query OK, 0 rows affected (0.00 sec)mysql> create user mgruser@'%' identified by 'mtls@352'; Query OK, 0 rows affected (0.01 sec)mysql> grant replication slave,replication client on *.* to mgruser@'%'; Query OK, 0 rows affected (0.00 sec)mysql> create user mgruser@'127.0.0.1' identified by 'mtls@352'; Query OK, 0 rows affected (0.00 sec)mysql> grant replication slave,replication client on *.* to mgruser@'127.0.0.1'; Query OK, 0 rows affected (0.00 sec)mysql> create user mgruser@'localhost' identified by 'mtls@352'; Query OK, 0 rows affected (0.00 sec)mysql> grant replication slave,replication client on *.* to mgruser@'localhost'; Query OK, 0 rows affected (0.00 sec)mysql> set sql_log_bin=1; Query OK, 0 rows affected (0.00 sec)mysql> mysql> mysql> change master to -> master_user='mgruser',-> master_password='mtls@352'-> for channel 'group_replication_recovery'; Query OK, 0 rows affected, 2 warnings (0.10 sec)mysql> mysql> mysql> install plugin group_replication soname 'group_replication.so'; Query OK, 0 rows affected (0.01 sec)mysql> mysql> mysql> set global group_replication_bootstrap_group=on; Query OK, 0 rows affected (0.00 sec)mysql> start group_replication; Query OK, 0 rows affected (2.11 sec)mysql> set global group_replication_bootstrap_group=off; Query OK, 0 rows affected (0.00 sec)?
?
十二、配置mgr的第二個結(jié)點:
第二個結(jié)點和第一個結(jié)點唯一的不同在于它不在要自己去建一個群了、它只要加入第一個結(jié)點建的群就可以了
第一步:創(chuàng)建用于復(fù)制的用戶
set sql_log_bin=0;create user mgruser@'%' identified by 'mtls@352';grant replication slave,replication client on *.* to mgruser@'%';create user mgruser@'127.0.0.1' identified by 'mtls@352';grant replication slave,replication client on *.* to mgruser@'127.0.0.1';create user mgruser@'localhost' identified by 'mtls@352';grant replication slave,replication client on *.* to mgruser@'localhost'; set sql_log_bin=1;第二步:配置復(fù)制所要的用戶
change master to master_user='mgruser',master_password='mtls@352'for channel 'group_replication_recovery';第三步:安裝組復(fù)制插件
install plugin group_replication soname 'group_replication.so';第四步:加入前面創(chuàng)建好的復(fù)制組
start group_replication;? 以下是我完成這四步的過程
[root@mtsl18 mysql]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.20-log MySQL Community Server (GPL)Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> set sql_log_bin=0; Query OK, 0 rows affected (0.00 sec)mysql> create user mgruser@'%' identified by 'mtls@352'; Query OK, 0 rows affected (0.00 sec)mysql> grant replication slave,replication client on *.* to mgruser@'%'; Query OK, 0 rows affected (0.00 sec)mysql> create user mgruser@'127.0.0.1' identified by 'mtls@352'; Query OK, 0 rows affected (0.00 sec)mysql> grant replication slave,replication client on *.* to mgruser@'127.0.0.1'; Query OK, 0 rows affected (0.00 sec)mysql> create user mgruser@'localhost' identified by 'mtls@352'; Query OK, 0 rows affected (0.00 sec)mysql> grant replication slave,replication client on *.* to mgruser@'localhost'; Query OK, 0 rows affected (0.00 sec)mysql> set sql_log_bin=1; Query OK, 0 rows affected (0.00 sec)mysql> mysql> mysql> change master to -> master_user='mgruser',-> master_password='mtls@352'-> for channel 'group_replication_recovery'; Query OK, 0 rows affected, 2 warnings (0.02 sec)mysql> mysql> mysql> install plugin group_replication soname 'group_replication.so'; Query OK, 0 rows affected (0.01 sec)mysql> mysql> start group_replication; Query OK, 0 rows affected (6.60 sec)?
?
?十三、配置mgr的其它結(jié)點:
邏輯上第二個結(jié)點與第三、第四、第五 ... 等等結(jié)點有著一樣的邏輯角色、就也是說它們都不是群主;所以它們的配置
方式和第二個結(jié)點是一樣的。
以下是我配置第三個結(jié)點時的過程
[root@mtls19 mysql]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.20-log MySQL Community Server (GPL)Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> set sql_log_bin=0; Query OK, 0 rows affected (0.00 sec)mysql> create user mgruser@'%' identified by 'mtls@352'; Query OK, 0 rows affected (0.01 sec)mysql> grant replication slave,replication client on *.* to mgruser@'%'; Query OK, 0 rows affected (0.00 sec)mysql> create user mgruser@'127.0.0.1' identified by 'mtls@352'; Query OK, 0 rows affected (0.00 sec)mysql> grant replication slave,replication client on *.* to mgruser@'127.0.0.1'; Query OK, 0 rows affected (0.00 sec)mysql> create user mgruser@'localhost' identified by 'mtls@352'; Query OK, 0 rows affected (0.00 sec)mysql> grant replication slave,replication client on *.* to mgruser@'localhost'; Query OK, 0 rows affected (0.00 sec)mysql> set sql_log_bin=1; Query OK, 0 rows affected (0.00 sec)mysql> mysql> mysql> change master to -> master_user='mgruser',-> master_password='mtls@352'-> for channel 'group_replication_recovery'; Query OK, 0 rows affected, 2 warnings (0.12 sec)mysql> mysql> mysql> install plugin group_replication soname 'group_replication.so'; Query OK, 0 rows affected (0.02 sec)mysql> mysql> start group_replication; Query OK, 0 rows affected (3.23 sec)?
?
十四、驗證mgr各個結(jié)點是否正常:
mysql> select * from performance_schema.replication_group_members ; +---------------------------+--------------------------------------+-------------+-------------+--------------+ | CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | +---------------------------+--------------------------------------+-------------+-------------+--------------+ | group_replication_applier | 34760575-c607-11e7-96e3-9a17854b700d | mtls17 | 3306 | ONLINE | | group_replication_applier | 8816fee3-c77d-11e7-832c-1e1b3511358e | mtsl18 | 3306 | ONLINE | | group_replication_applier | 8dfc74c1-c77d-11e7-9447-8a7c439b72d9 | mtls19 | 3306 | ONLINE | +---------------------------+--------------------------------------+-------------+-------------+--------------+ 3 rows in set (0.00 sec)結(jié)論:3個結(jié)點的狀態(tài)都是online 說明它們是正常的、進一步說明mgr的安裝成功了。
?
?
十五、對于mgr配置過程中一些要點問題的回答:
1、官方說mgr是與mysql replication 完全不同的一種數(shù)據(jù)同步技術(shù)、為什么還要加一個復(fù)制用戶?
(這個上問題針對的是第十二節(jié)的第一步&第二步)
答:
? ?一個節(jié)點在加入mgr組時、這個加入的過程在邏輯上可以分成兩個階段、第一個階段基于傳統(tǒng)的gtid的復(fù)制
方式把這個上結(jié)點落下的數(shù)據(jù)補上去;假設(shè)這個階段用時30分鐘、這30分鐘內(nèi)mgr集群還是可以接受數(shù)據(jù)寫入的。
那這30分鐘的數(shù)據(jù)通過什么方式補呢?答案就是這30分鐘的數(shù)據(jù)在第二階段補、第二階段就是用的mgr的方式同步
的了、在把數(shù)據(jù)補上之后就個結(jié)點就成功的加入的mgr集群、并為online狀態(tài)。
?
2、為什么要安裝插件
答:
? ?因為mgr功能是一個插件實現(xiàn)的。
?
?
十六、更多:
1、如果你感覺手動安裝配置mgr比較費事、我做了一個mysql dba的工具、它能完成myql-group-replication的自動
安裝配置 工具的地址:https://github.com/Neeky/mysqltools#mysql-group-replication環(huán)境的安裝
2、這里只介紹了mgr的安裝與配置、并沒有對mgr的功能進行測試、是因為我已經(jīng)寫了一份關(guān)于mgr功能的測試的報告
測試報告地址:http://www.cnblogs.com/JiangLe/p/7809229.html
?
?
?
?
?
?----
轉(zhuǎn)載于:https://www.cnblogs.com/JiangLe/p/6727281.html
總結(jié)
以上是生活随笔為你收集整理的mysql group replication 安装配置详解的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Html5音乐可视化之音乐的获取和播放
- 下一篇: vue项目在移动端(手机)调试