MySQL 5.7: 使用組複製(MySQL Group Replication)
MySQL 5.7: 使用MySQL Router實現應用程序的高可用
MySQL 5.7: 把現有的複製組遷移到InnoDB Cluster
MySQL 5.7: 使用PMM監視和管理數據庫html
每一個節點執行以下命令安裝官方倉庫的MySQL Servernode
apt-get update cd /tmp wget https://dev.mysql.com/get/mysql-apt-config_0.8.9-1_all.deb dpkg -i mysql-apt-config_0.8.9-1_all.deb apt-get update aptitude install -y mysql-server
驗證複製插件是否存在:mysql
root@iZwz98pmxwulw67n9gxnl2Z:/etc/mysql# ll /usr/lib/mysql/plugin/ total 4120 drwxr-xr-x 3 root root 4096 Nov 11 11:14 ./ drwxr-xr-x 3 root root 4096 Nov 11 11:14 ../ ... -rw-r--r-- 1 root root 1751560 Sep 14 01:01 group_replication.so ...
注意: 不要安裝Ubuntu 16.04自帶的MySQL, 16.04自帶的MySQL安裝後沒有 group_replication.so 這個東西, 必定要經過 mysql-apt-config_0.8.9-1_all.deb 提供的倉庫安裝. MySQL 官方版本的最新版本的倉庫能夠在這裏下載: https://dev.mysql.com/downloa...git
該倉庫提供了下面的Linux發佈版的MySQL軟件包:github
- Debian - 7
- Debian - 8
- Debian - 9
- Ubuntu - 14.04 LTS
- Ubuntu - 16.04 LTS
- Ubuntu - 17.04
- Ubuntu - 17.10
該倉庫包含下列MySQL軟件包和相關工具:sql
- MySQL 8.0 (Development)
- MySQL 5.7 (GA)
- MySQL 5.6 (GA)
- MySQL Cluster 7.5 (GA)
- MySQL Cluster 7.6 (Development)
- MySQL Workbench 6.3 (GA) - Ubuntu Only
- MySQL Router (GA and preview)
- MySQL Utilities
- MySQL Connector / Python
- MySQL Shell (GA and preview)
每一個節點建立目錄, 用於放置MGR(MySQL Group Replication)的配置文件數據庫
mkdir /etc/mysql/mgr.d
配置文件在本文Git倉庫Markdown文件相同目錄下, 文件名稱依次爲:bootstrap
mgr-01.conf mgr-02.conf mgr-03.conf
修改上述三個文件對應的IP地址, 詳細的說明參考: https://www.howtoing.com/how-...ubuntu
生成複製組所須要的UUID備用.segmentfault
root# uuidgen 00d17eae-73c8-4a7d-abf5-051bb68a9d7d
用上面生成的UUID替換 loose-group_replication_group_name
https://github.com/developerw...
#!/bin/bash # mkdir /etc/mysql/mgr.d scp mgr-01.conf root@172.18.149.213:/etc/mysql/mgr.d/mgr.cnf scp mgr-02.conf root@172.18.149.214:/etc/mysql/mgr.d/mgr.cnf scp mgr-03.conf root@172.18.149.215:/etc/mysql/mgr.d/mgr.cnf
在每個節點的 /etc/mysql/my.cnf 文件最後一行添加以下指令:
!includedir /etc/mysql/mgr.d/
雙十一新購了3臺本地SSD的ECS, 想把MySQL的數據目錄移動到獨立的SSD(/dev/vdb)上. 格式化磁盤, 建立文件系統, 並移動數據目錄:
fdisk /dev/vdb
建立掛載點
mkdir /data
建立文件系統
mkfs.ext4 /dev/vdb1
查看磁盤UUID
blkid
複製 /dev/vdb1 的UUID, 在 /etc/fstab 下添加:
UUID=${UUID} /data ext4 errors=remount-ro 0 1
用你本身的磁盤UUID替換 ${UUID}
掛載文件系統
mount /dev/vdb1 /data
建立軟鏈接並啓動MySQL
mv /var/lib/mysql /data ln -s /data/mysql /var/lib/mysql systemctl start mysql
啓動數據庫查看日誌(tail -f /var/log/mysql/error.log)發現以下錯誤消息:
2017-11-11T03:24:49.003621Z 0 [ERROR] InnoDB: The innodb_system data file 'ibdata1' must be writable 2017-11-11T03:24:49.003637Z 0 [ERROR] InnoDB: The innodb_system data file 'ibdata1' must be writable 2017-11-11T03:24:49.003642Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error 2017-11-11T03:24:49.604050Z 0 [ERROR] Plugin 'InnoDB' init function returned error. 2017-11-11T03:24:49.604070Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed. 2017-11-11T03:24:49.604076Z 0 [ERROR] Failed to initialize plugins. 2017-11-11T03:24:49.604079Z 0 [ERROR] Aborting
編輯以下文件
vi /etc/apparmor.d/usr.sbin.mysqld
在文件末尾 } 的上一行添加下面兩行:
/data/mysql/ r, /data/mysql/** rwk,
/data/mysql 爲新的數據目錄路徑. 上面兩行的做用是分配目錄的讀寫權限, Ubuntu 16.04 默認的MySQL數據目錄爲 /var/lib/mysql.
進入MySQL控制檯
mysql -uroot -p
在全部節點執行以下命令:
SET SQL_LOG_BIN=0; CREATE USER 'repl'@'%' IDENTIFIED BY 'password' REQUIRE SSL; GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%'; FLUSH PRIVILEGES; SET SQL_LOG_BIN=1; CHANGE MASTER TO MASTER_USER='repl', MASTER_PASSWORD='password' FOR CHANNEL 'group_replication_recovery'; INSTALL PLUGIN group_replication SONAME 'group_replication.so'; # 驗證插件是否安裝成功 mysql> SHOW PLUGINS; +----------------------------+----------+--------------------+----------------------+---------+ | Name | Status | Type | Library | License | +----------------------------+----------+--------------------+----------------------+---------+ ... | group_replication | ACTIVE | GROUP REPLICATION | group_replication.so | GPL | +----------------------------+----------+--------------------+----------------------+---------+
SET GLOBAL group_replication_bootstrap_group=ON; START GROUP_REPLICATION; SET GLOBAL group_replication_bootstrap_group=OFF;
START GROUP_REPLICATION;
事務問題, 各個節點的事務狀態不一致. 全部節點加入集羣前最好不要修改任何數據, 不然就會出現下面的錯誤.
2017-11-10T19:07:26.918531Z 0 [ERROR] Plugin group_replication reported: 'This member has more > executed transactions than those present in the group. Local transactions: c3c274ff-c63e-11e7-> b339-00163e0c0288:1-4 > Group transactions: 2e6bfa69-0439-41c9-add7-795a9acfd499:1-10, c5898a84-c63e-11e7-bc8b-00163e0af475:1-4'
解決辦法:
http://blog.csdn.net/yuanlin6...
set global group_replication_allow_local_disjoint_gtids_join=ON;
對於一個3節點的單主集羣來講, 當主節點掛了, 另外兩個節點會自動選主. 其中一個會成爲主節點, 並自動切換爲讀寫模式.
由於對於單主模式來講, 只有主節點可以執行寫操做. 那麼咱們如何知道主節點的IP地址呢?
能夠在任意一個MySQL節點上經過以下SQL獲取主節點的IP地址
SELECT * FROM performance_schema.replication_group_members WHERE MEMBER_ID = (SELECT VARIABLE_VALUE FROM performance_schema.global_status WHERE VARIABLE_NAME= 'group_replication_primary_member');
更新2017-11-12:
IP地址的問題參後續文章: MySQL 5.7: 使用MySQL Router實現應用程序的高可用
https://dev.mysql.com/doc/ref...
https://www.howtoing.com/how-...
http://blog.csdn.net/yuanlin6...
https://stackoverflow.com/que...