650) this.width=650; "Width=" "height=" 621 "src=" https://wuguiyunwei.com/wp-content/uploads/2017/06/ 1200px-mysql.svg_.png "class=" Attachment-full size-full wp-post-image "style=" border:none;vertical-align:middle; height:auto;width:655.771px; "/>
mysql5.7 MGR Cluster build deployment
This article is written by the team member (earnest)
This article is from the Turtle Operation official website wuguiyunwei.com
QQ Group 602183872
Recently looked at the mysql5.7 of the MGR cluster is very good, there are single and multi-master mode, and then set up a test of the effect is good, I mean a good build and maintenance are relatively simple. Most of the internet is a single main mode, of course, I also here, in order to deepen the impression, deliberately record the construction process, and so on to try more than the main mode, I believe we are now the database bottleneck is basically written, read and write separation although is a feasible solution, but if the volume of data is very large, write the same problem, Although some solutions can deploy multiple master nodes, can read and write at the same time, but the brain fissure is a serious problem, so here Mgr Cluster built-in automatic brain crack protection mechanism and got a lot of people's favor, here Mgr short for the MySQL Group Replication is a new high-availability and highly scalable solution that MySQL officially launched in December 2016. Note that this article no longer describes the original rational things.
Note: I use the method of compiling and installing here, if want to simple direct Yum installs mysql5.7 also line, MySQL compile installs need disk space still is relatively big, generally in 7G about, so want to plan well in advance, use three nodes to compare close to production environment, and more direct clear.
Detailed deployment information is as follows:
host name |
ip address |
install software |
purpose |
apache |
192.168.2.25 |
cmake, Boost, MySQL |
node |
nginx |
192.168.2.26 |
cmake, Boost, MySQL |
node |
Kibana |
192.168.2.30 |
CMake, Boost, MySQL |
Node |
1, three machine preparation work
Rpm-qa MySQL mariadb
If there is the uninstall can!
Writes the Hosts file mapping relationship, which is used by the cluster
192.168.2.25 Apache
192.168.2.26 Nginx
192.168.2.30 Kibana
2. Install dependent packages
Yum Install gcc gcc-c++ ncurses-devel-y
3, Installation cmake,:https://cmake.org/download/
Tar zxvf cmake-3.7.2.tar.gz
CD make-3.7.2
./configure
Gmake && gmake Install
4, install boost, because mysql5.7 need, note here download version is 1_59_0 and MySQL version is corresponding, if your MySQL version and my not the same, do not add-dwith_boost this parameter when it will tell you need to download the version of Boost.
Tar zxvf boost_1_59_0.tar.gz
Cp-r Boost_1_59_0/usr/local/boost
5. Installation mysql5.7.17 and initialization operation
Groupadd MySQL
Useradd-m-s/sbin/nologin mysql-g MySQL
Tar zxvf mysql-5.7.17.tar.gz
CD mysql-5.7.17
Cmake-dcmake_install_prefix=/data/mysql-dsysconfdir=/etc-ddefault_charset=utf8-ddefault_collation=utf8_general _ci-dwith_extra_charsets=all-dwith_boost=/usr/local/boost
Make
Make install
Chown-r Mysql.mysql/data/mysql
Mv/etc/my.cnf/etc/my.cnf.default
Cp/data/mysql/support-files/my-default.cnf/etc/my.cnf
/data/mysql/bin/mysqld–initialize–user=mysql–basedir=/data/mysql–datadir=/data/mysql/data//Note initialization generates a Random password, please keep in mind
echo "path= $PATH:/data/mysql/bin" >>/etc/profile
Source/etc/profile
Cp/data/mysql/support-files/mysql.server/etc/rc.d/init.d/mysqld
chmod +x/etc/rc.d/init.d/mysqld
The above steps need to be performed on three machines
6, start to build MGR Cluster environment, modify the first node of the my.cnf file, the contents are as follows:
# for advice The change settings
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# * * * Don't EDIT this FILE. It ' s a template which'll be copied to the
# * * * default location during install, and would be replaced if you
# * * * * Upgrade to a newer version of MySQL.
[Mysqld]
# Remove Leading # and set to the amount of RAM for the most important data
# Cache in MySQL. Start at 70% of all RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove Leading # to turn on a very important data integrity option:logging
# Changes to the binary log between backups.
# Log_bin
# These is commonly set, remove the # and set as required.
Basedir =/data/mysql
DataDir =/data/mysql/data
Port = 3306
Socket =/data/mysql/data/mysql.sock
Log-error =/data/mysql/data/mysqld.log
Pid-file =/data/mysql/data/mysqld.pid
# Remove Leading # To set options mainly useful for reporting servers.
# The server defaults is faster for transactions and fast selects.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
Sql_mode=no_engine_substitution,strict_trans_tables
# Group Replication
server_id = 1
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 = Binlog
binlog_format= ROW
Transaction_write_set_extraction = XXHASH64
Loose-group_replication_group_name = ' ce9be252-2b71-11e6-b8f4-00212844f856 '
Loose-group_replication_start_on_boot = Off
loose-group_replication_local_address = ' 192.168.2.25:33061 '
Loose-group_replication_group_seeds = ' 192.168.2.25:33061,192.168.2.26:33061,192.168.2.30:33061′
Loose-group_replication_bootstrap_group = Off
[Client]
Socket =/data/mysql/data/mysql.sock
start the MySQL service
/etc/init.d/mysqld start
Set sql_log_bin=0;
Create user [email protected] '% ';
Grant Replication Slave on * * to [e-mail protected] '% ' identified by ' rpl_pass ';
Flush privileges;
Set sql_log_bin=1;
Change Master to master_user= ' Rpl_user ', master_password= ' Rpl_pass ' for Channel ' group_replication_recovery ';
Install PLUGIN group_replication SONAME ' group_replication.so ';
Set global group_replication_bootstrap_group=on;
Start group_replication;
Set global Group_replication_bootstrap_group=off;
SELECT * from Performance_schema.replication_group_members;
The results appear as follows:
650) this.width=650; "class=" Alignnone size-full wp-image-837 "src=" http://wuguiyunwei.com/wp-content/uploads/2017/ 06/23916356_14967352001r96.png "width=" 784 "height=" 109 "style=" Border:none;vertical-align:middle;height:auto; margin:5px 0px 20px; "/>
If online is present, it is normal, this is the master node, and then two slave nodes are built.
7, the second node joins the cluster, copy the first node's main configuration file my.cnf, only need to modify two places on the line, has been marked in red
# for advice The change settings
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# * * * Don't EDIT this FILE. It ' s a template which'll be copied to the
# * * * default location during install, and would be replaced if you
# * * * * Upgrade to a newer version of MySQL.
[Mysqld]
# Remove Leading # and set to the amount of RAM for the most important data
# Cache in MySQL. Start at 70% of all RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove Leading # to turn on a very important data integrity option:logging
# Changes to the binary log between backups.
# Log_bin
# These is commonly set, remove the # and set as required.
Basedir =/data/mysql
DataDir =/data/mysql/data
Port = 3306
Socket =/data/mysql/data/mysql.sock
Log-error =/data/mysql/data/mysqld.log
Pid-file =/data/mysql/data/mysqld.pid
# Remove Leading # To set options mainly useful for reporting servers.
# The server defaults is faster for transactions and fast selects.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
Sql_mode=no_engine_substitution,strict_trans_tables
# Group Replication
server_id = 2
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 = Binlog
binlog_format= ROW
Transaction_write_set_extraction = XXHASH64
Loose-group_replication_group_name = ' ce9be252-2b71-11e6-b8f4-00212844f856 '
Loose-group_replication_start_on_boot = Off
loose-group_replication_local_address = ' 192.168.2.26:33061 '
Loose-group_replication_group_seeds = ' 192.168.2.25:33061,192.168.2.26:33061,192.168.2.30:33061′
Loose-group_replication_bootstrap_group = Off
[Client]
Socket =/data/mysql/data/mysql.sock
The second node executes the following command:
Set sql_log_bin=0;
Create user [email protected] '% ';
Grant Replication Slave on * * to [e-mail protected] '% ' identified by ' rpl_pass ';
Set sql_log_bin=1;
Change Master to master_user= ' Rpl_user ', master_password= ' Rpl_pass ' for Channel ' group_replication_recovery ';
Install plugin group_replication SONAME ' group_replication.so ';
Set global group_replication_allow_local_disjoint_gtids_join=on;
Start group_replication;
The results appear as follows:
650) this.width=650; "class=" Alignnone size-full wp-image-838 "src=" http://wuguiyunwei.com/wp-content/uploads/2017/ 06/23916356_1496738002d6j5.png "width=" 782 "height=" "style=" Border:none;vertical-align:middle;height:auto; margin:5px 0px 20px; "/>
Similarly, the third node join operation method is the same as the second node.
As follows:
650) this.width=650; "class=" Alignnone size-full wp-image-839 "src=" http://wuguiyunwei.com/wp-content/uploads/2017/ 06/23916356_1496738093rr66.png "width=" 789 "height=" 141 "style=" Border:none;vertical-align:middle;height:auto; margin:5px 0px 20px; "/>
Query which is the primary node:
650) this.width=650; "class=" Alignnone size-full wp-image-840 "src=" http://wuguiyunwei.com/wp-content/uploads/2017/ 06/23916356_14967381613k9p.png "width=" 865 "height=" 109 "style=" Border:none;vertical-align:middle;height:auto; margin:5px 0px 20px; "/>
It is obvious from the point of view that the Apache host is the master node.
Test steps:
1, create a library on the main library, and then create a table, in two from the library to query whether the data is synchronized?
2, two can only perform query operations from the library?
2, manually close the main library, confirm two from the library will one of them become the main library? And is member_id the first letter prioritized by the takeover Main library?
Routine Maintenance steps:
1. If a node is closed from a library
Start group_replication;
2. If all libraries are closed, the first library is executed as the main library first
Set global group_replication_bootstrap_group=on;
Start group_replication;
The rest of the library can be executed directly!
Start group_replication;
3, if the main library failure, will automatically select a main library from the two libraries, the main library started after the execution of the following command will become from the library
Start group_replication;
mysql5.7 Mgr Cluster construction