Mysql5.7 MGR cluster creation

Source: Internet
Author: User
Tags change settings dedicated server kibana

Mysql5.7 MGR cluster creation
Recently I checked that the MGR cluster of mysql5.7 is quite good, with single-master and multi-master modes. As a result, the setup and testing results are quite good. I mean that the setup and maintenance are relatively simple. The vast majority of the online models are single-master mode. Of course, I am also here. In order to deepen my impression, I will record the building process and try the multi-master mode later, I believe that the bottleneck of the database is basically writing. Although read/write splitting is a feasible solution, if the data volume is large, there will be problems like writing, although some solutions can deploy multiple master nodes for simultaneous read/write operations, split-brain is a serious problem, therefore, the MGR cluster has built-in automatic split-brain protection mechanism, which has been favored by many people, MGR (MySQL Group Replication) is a new high availability and high scalability solution officially launched by MySQL in December 2016. Note that this article will not elaborate on principles.
Note: I will use the compilation and installation method here. If you want to simply install mysql5.7 using yum, the disk space required for mysql compilation and installation is still relatively large, generally around 7 GB, therefore, it is necessary to plan in advance, use three nodes closer to the production environment, and make them clearer.
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. Prepare three machines
 
 
  1. rpm -qa mysql mariadb
If yes, uninstall it!
Write the hosts file ing relationship.
192.168.2.25 apache
192.168.2.26 nginx
192.168.2.30 kibana
2. Install the dependency package
 
 
  1. yum install gcc gcc-c++ncurses-devel -y
3, install cmake,: https://cmake.org/download/
 
 
  1. tar zxvf cmake-3.7.2.tar.gz
  2. cd make-3.7.2
  3. ./configure
  4. gmake && gmake install
4. Install boost because mysql5.7 is required. Note that the downloaded version is ipv59_0 and mysql. If your MySQL version is different from mine, if the-DWITH_BOOST parameter is not added, an error is reported to indicate which version of boost is to be downloaded.
 
 
  1. tar zxvf boost_1_59_0.tar.gz
  2. cp -r boost_1_59_0 /usr/local/boost
5. Install and initialize mysql5.7.17.
 
 
  1. Groupadd mysql
  2. Useradd-M-s/sbin/nologin mysql-g mysql
  3. Tar zxvf mysql-5.7.17.tar.gz
  4. Cd mysql-5.7.17
  5. Cmake-DCMAKE_INSTALL_PREFIX =/data/mysql-DSYSCONFDIR =/etc-DDEFAULT_CHARSET = utf8-DDEFAULT_COLLATION = utf8_general_ci-keys = all-DWITH_BOOST =/usr/local/boost
  6. Make
  7. Make install
  8. Chown-R mysql. mysql/data/mysql
  9. Mv/etc/my. cnf/etc/my. cnf. default
  10. Cp/data/mysql/support-files/my-default.cnf/etc/my. cnf
  11. /Data/mysql/bin/mysqld -- initialize -- user = mysql -- basedir =/data/mysql -- datadir =/data/mysql/data // note that a random password will be generated during initialization., remember
  12. Echo "PATH = $ PATH:/data/mysql/bin">/etc/profile
  13. Source/etc/profile
  14. Cp/data/mysql/support-files/mysql. server/etc/rc. d/init. d/mysqld
  15. Chmod + x/etc/rc. d/init. d/mysqld
The preceding steps must be performed on all three machines.
6. Start to build the MGR Cluster Environment and modify the my. cnf file of the first node. The content is as follows:
 
 
  1. # For advice on how to change settings please see
  2. # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
  3. # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
  4. # *** default location during install, and will be replaced if you
  5. # *** upgrade to a newer version of MySQL.
  6. [mysqld]
  7. # Remove leading # and set to the amount of RAM for the most important data
  8. # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
  9. # innodb_buffer_pool_size = 128M
  10. # Remove leading # to turn on a very important data integrity option: logging
  11. # changes to the binary log between backups.
  12. # log_bin
  13. # These are commonly set, remove the # and set as required.
  14. basedir = /data/mysql
  15. datadir = /data/mysql/data
  16. port = 3306
  17. socket = /data/mysql/data/mysql.sock
  18. log-error = /data/mysql/data/mysqld.log
  19. pid-file = /data/mysql/data/mysqld.pid
  20. # Remove leading # to set options mainly useful for reporting servers.
  21. # The server defaults are faster for transactions and fast SELECTs.
  22. # Adjust sizes as needed, experiment to find the optimal values.
  23. # join_buffer_size = 128M
  24. # sort_buffer_size = 2M
  25. # read_rnd_buffer_size = 2M
  26. sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
  27. # Group Replication
  28. server_id = 1
  29. gtid_mode = ON
  30. enforce_gtid_consistency = ON
  31. master_info_repository = TABLE
  32. relay_log_info_repository = TABLE
  33. binlog_checksum = NONE
  34. log_slave_updates = ON
  35. log_bin = binlog
  36. binlog_format= ROW
  37. transaction_write_set_extraction = XXHASH64
  38. loose-group_replication_group_name = 'ce9be252-2b71-11e6-b8f4-00212844f856'
  39. loose-group_replication_start_on_boot = off
  40. loose-group_replication_local_address = '192.168.2.25:33061'
  41. loose-group_replication_group_seeds ='192.168.2.25:33061,192.168.2.26:33061,192.168.2.30:33061'
  42. loose-group_replication_bootstrap_group = off
  43. [client]
  44. socket = /data/mysql/data/mysql.sock
Start mysql Service
/Etc/init. d/mysqld start
 
 
  1. set sql_log_bin=0;
  2. create user rpl_user@'%';
  3. grant replication slave on *.* to rpl_user@'%' identified by 'rpl_pass';
  4. flush privileges;
  5. set sql_log_bin=1;
  6. change master to master_user='rpl_user',master_password='rpl_pass' for channel 'group_replication_recovery';
  7. install PLUGIN group_replication SONAME 'group_replication.so';
  8. set global group_replication_bootstrap_group=ON;
  9. start group_replication;
  10. set global group_replication_bootstrap_group=OFF;
  11. select * from performance_schema.replication_group_members;
The result is as follows:

If ONLINE occurs, it means it is normal. This is the master node, and two slave nodes are created.
7. Add the second node to the cluster and copy the master configuration file my. cnf of the first node. You only need to modify the configuration file in red.
 
 
  1. # For advice on how to change settings please see
  2. # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
  3. # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
  4. # *** default location during install, and will be replaced if you
  5. # *** upgrade to a newer version of MySQL.
  6. [mysqld]
  7. # Remove leading # and set to the amount of RAM for the most important data
  8. # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
  9. # innodb_buffer_pool_size = 128M
  10. # Remove leading # to turn on a very important data integrity option: logging
  11. # changes to the binary log between backups.
  12. # log_bin
  13. # These are commonly set, remove the # and set as required.
  14. basedir = /data/mysql
  15. datadir = /data/mysql/data
  16. port = 3306
  17. socket = /data/mysql/data/mysql.sock
  18. log-error = /data/mysql/data/mysqld.log
  19. pid-file = /data/mysql/data/mysqld.pid
  20. # Remove leading # to set options mainly useful for reporting servers.
  21. # The server defaults are faster for transactions and fast SELECTs.
  22. # Adjust sizes as needed, experiment to find the optimal values.
  23. # join_buffer_size = 128M
  24. # sort_buffer_size = 2M
  25. # read_rnd_buffer_size = 2M
  26. sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
  27. # Group Replication
  28. server_id = 2
  29. gtid_mode = ON
  30. enforce_gtid_consistency = ON
  31. master_info_repository = TABLE
  32. relay_log_info_repository = TABLE
  33. binlog_checksum = NONE
  34. log_slave_updates = ON
  35. log_bin = binlog
  36. binlog_format= ROW
  37. transaction_write_set_extraction = XXHASH64
  38. loose-group_replication_group_name = 'ce9be252-2b71-11e6-b8f4-00212844f856'
  39. loose-group_replication_start_on_boot = off
  40. loose-group_replication_local_address = '192.168.2.26:33061'
  41. loose-group_replication_group_seeds ='192.168.2.25:33061,192.168.2.26:33061,192.168.2.30:33061'
  42. loose-group_replication_bootstrap_group = off
  43. [client]
  44. socket = /data/mysql/data/mysql.sock
Run the following command on the second node:
 
 
  1. set sql_log_bin=0;
  2. create user rpl_user@'%';
  3. grant replication slave on *.* to rpl_user@'%' identified by 'rpl_pass';
  4. set sql_log_bin=1;
  5. change master to master_user='rpl_user',master_password='rpl_pass' for channel 'group_replication_recovery';
  6. install plugin group_replication SONAME 'group_replication.so';
  7. set global group_replication_allow_local_disjoint_gtids_join=ON;
  8. startgroup_replication;
The result is as follows:

Similarly, adding a third node is the same as adding a second node.
As follows:

Query which is the master node:

Obviously, the apache host is the master node.
Test procedure:
1. Create a database in the master database, create a table, and query data synchronization between the two slave databases?
2. Can I query only two slave databases?
2. manually close the master database and check whether one of the two slave databases changes to the master database? What is the master database of MEMBER_ID sorted by priority by the first letter?
Routine maintenance steps:
1. If a slave database node is closed
 
 
  1. start group_replication;
2. If all databases are closed, the first database is executed as the master database first.
 
 
  1. set global group_replication_bootstrap_group=ON;
  2. start group_replication;
Execute the remaining databases directly!
 
 
  1. start group_replication;
3. If the master database fails, one master database is automatically selected from the two slave databases. After the master database is started, the following command is executed again and then changed to the slave database.
 
 
  1. start group_replication;






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.