当前位置:网站首页>3. install and deploy Mgr cluster | explain Mgr in simple terms
3. install and deploy Mgr cluster | explain Mgr in simple terms
2022-06-23 02:20:00 【Greatsql community】
> * GreatSQL The original content of the community shall not be used without authorization , For reprint, please contact the editor and indicate the source .
- 1. Installation preparation
- 2. initialization MySQL Server
- 3. initialization MGR First node
- 4. Continue setting up the other two nodes
- 5. towards MGR Write data to the cluster
- Reference material 、 file
- disclaimer
This article introduces how to use GreatSQL 8.0.25 Build a three node MGR colony .
1. Installation preparation
Prepare the following three servers :
IP | port | role |
|---|---|---|
172.16.16.10 | 3306 | mgr1 |
172.16.16.11 | 3306 | mgr2 |
172.16.16.12 | 3306 | mgr3 |
Ensure that the network between the three nodes can be interconnected , And not targeted 3306 and 33061 Firewall interception rules for ports .
download GreatSQL Binary package , Download address :https://gitee.com/GreatSQL/GreatSQL/releases .
This article takes CentOS x86_64 Environment, for example , The downloaded binary package name is : GreatSQL-8.0.25-15-Linux-glibc2.28-x86_64.tar.xz, Put it in /usr/local Directory and unzip it :
$ cd /usr/local $ tar xf GreatSQL-8.0.25-15-Linux-glibc2.28-x86_64.tar.xz $ cd GreatSQL-8.0.25-15-Linux-glibc2.28-x86_64 $ ls bin COPYING-jemalloc include LICENSE LICENSE-test mysqlrouter-log-rotate README.router run support-files cmake docs lib LICENSE.router man README README-test share var
2. initialization MySQL Server
Get ready first /etc/my.cnf The configuration file :
#/etc/my.cnf [mysqld] user = mysql basedir=/usr/local/GreatSQL-8.0.25-15-Linux-glibc2.28-x86_64 datadir=/data/GreatSQL port=3306 server_id=103306 log-bin log_slave_updates=1 gtid_mode=ON enforce_gtid_consistency=ON
This article can only be started normally MySQL Server And deployment MGR For the purpose , So this configuration file is extremely simple , If you want to use it on a formal occasion , You can refer to This profile .
Initialize first MySQL Server:
$ mkdir -p /data/GreatSQL && chown -R mysql:mysql /data/GreatSQL $ /usr/local/GreatSQL-8.0.25-15-Linux-glibc2.28-x86_64/bin/mysqld --defaults-file=/etc/my.cnf --initialize-insecure
Be careful : Don't use... In a production environment --initialize-insecure Option to initialize the installation , Because if you do this , Super administrator root By default, the account number is blank , Anyone can use this account to log in to the database , There are security risks , This is done for demonstration purposes only in this article .
start-up MySQL Server:
$ /usr/local/GreatSQL-8.0.25-15-Linux-glibc2.28-x86_64/bin/mysqld --defaults-file=/etc/my.cnf &
If nothing goes wrong , It can start normally MySQL Server. Use the same method to initialize the other two nodes .
Besides , Make a proposal to GreatSQL To join the system systemd In service , Easy to manage . For specific methods, please refer to this article : take GreatSQL Add to system systemd service .
3. initialization MGR First node
Next, prepare to initialize MGR The first node of , Also known as Boot node .
modify /etc/my.cnf , Add the following lines and MGR Related configuration parameters :
plugin_load_add='group_replication.so' group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1" group_replication_local_address= "172.16.16.10:33061" group_replication_group_seeds= "172.16.16.10:33061,172.16.16.11:33061,172.16.16.12:33061" report-host=172.16.16.10
Options report-host The role of MGR Other nodes report the addresses used by this node , Avoid multiple host names on a server , May not be able to find the corresponding relationship correctly and make MGR Can't start problem . Besides , Set up report-host after , modify /etc/hosts It is not necessary to add the address and host name of each node to the system file .
in addition , Note that the port configured above is written as 33061 instead of 3306, This is for MGR The service specifies a dedicated communication port , The difference in MySQL Normal read / write service port . there 33061 The port number can be customized , For example, write 12345 It's fine too , Note that this port cannot be blocked by the firewall .
Use this configuration file , restart MySQL Server, After that, you should see that it has been loaded successfully group_replicaiton Plug in :
mysql> show plugins; ... +---------------------------------+----------+--------------------+----------------------+---------+ | Name | Status | Type | Library | License | +---------------------------------+----------+--------------------+----------------------+---------+ ... | group_replication | ACTIVE | GROUP REPLICATION | group_replication.so | GPL | ...
If not loaded correctly , You can also log in MySQL Server Load this manually plugin:
myqsl> install plugin group_replication soname 'group_replication.so';
Next , establish MGR Special account for services , And prepare the configuration MGR Service channel :
# Each node should create a user separately , So there is no need to record this operation binlog And copy to other nodes mysql> set session sql_log_bin=0; mysql> create user [email protected]'%' identified by 'repl'; mysql> GRANT BACKUP_ADMIN, REPLICATION SLAVE ON *.* TO `repl`@`%`; # Continue to enable after the user is created binlog Record mysql> set session sql_log_bin=1; # To configure MGR Service channel # Channel name group_replication_recovery Is constant , Do not modify mysql> CHANGE MASTER TO MASTER_USER='repl', MASTER_PASSWORD='repl' FOR CHANNEL 'group_replication_recovery';
Then execute the following command , Set it to MGR Boot node for ( Only the first node needs to do this ) Then you can start it directly MGR service :
mysql> set global group_replication_bootstrap_group=ON; mysql> start group_replication;
remind : When the whole MGR When the cluster restarts , The first boot node should also be set to boot mode , Then start the other nodes . In addition , Do not set boot mode .
Then , see MGR Service status :
mysql> select * from performance_schema.replication_group_members; +---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+----------------+ | CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION | +---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+----------------+ | group_replication_applier | 4ebd3504-11d9-11ec-8f92-70b5e873a570 | 172.16.16.10 | 3306 | ONLINE | PRIMARY | 8.0.25 | +---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+----------------+
Okay , The first node initialization is completed .
4. Continue setting up the other two nodes
Continue to use the following /etc/my.cnf Profile templates :
#my.cnf [mysqld] user = mysql basedir=/usr/local/GreatSQL-8.0.25-15-Linux-glibc2.28-x86_64 datadir=/data/GreatSQL port=3306 server_id=113306 log-bin log_slave_updates=1 gtid_mode=ON enforce_gtid_consistency=ON #mgr plugin_load_add='group_replication.so' group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1" group_replication_local_address= "172.16.16.11:33061" group_replication_group_seeds= "172.16.16.10:33061,172.16.16.11:33061,172.16.16.12:33061" report-host=172.16.16.11
remind : Of the above options ,server_id、group_replication_local_address and report_host These three options should be modified to the correct values . In a MGR In the cluster , For each node server_id and server_uuid If only , however group_replication_group_name The value of is the same , It's time MGR Unique identity of the cluster .
restart MySQL Server After the instance (report-host Is a read-only option , It needs to be restarted to take effect ), establish MGR Special service account and configuration MGR Service channel :
mysql> set session sql_log_bin=0; mysql> create user [email protected]'%' identified by 'repl'; mysql> GRANT BACKUP_ADMIN, REPLICATION SLAVE ON *.* TO `repl`@`%`; mysql> set session sql_log_bin=1; mysql> CHANGE MASTER TO MASTER_USER='repl', MASTER_PASSWORD='repl' FOR CHANNEL 'group_replication_recovery';
Then you can start directly MGR service ( Except for the first node , Other nodes do not need to set the boot mode ):
mysql> start group_replication;
Look again MGR Node status :
mysql> select * from performance_schema.replication_group_members; +---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+----------------+ | CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION | +---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+----------------+ | group_replication_applier | 4ebd3504-11d9-11ec-8f92-70b5e873a570 | 172.16.16.10 | 3306 | ONLINE | PRIMARY | 8.0.25 | | group_replication_applier | 549b92bf-11d9-11ec-88e1-70b5e873a570 | 172.16.16.11 | 3306 | ONLINE | SECONDARY | 8.0.25 | | group_replication_applier | 5596116c-11d9-11ec-8624-70b5e873a570 | 172.16.16.12 | 3306 | ONLINE | SECONDARY | 8.0.25 | +---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+----------------+
You can see that the cluster above has 3 Nodes are in ONLINE state , among 172.16.16.10 yes PRIMARY node , The other two are SECONDARY node , That is to say, the current cluster adopts Single owner Pattern . If multi master mode is adopted , Then the roles of all nodes are PRIMARY.
5. towards MGR Write data to the cluster
Next we connect to PRIMARY node , Create a test library table and write data :
$mysql -h172.16.16.10 -uroot -Spath/mysql.sock mysql> create database mgr; mysql> use mgr; mysql> create table t1(c1 int unsigned not null primary key); mysql> insert into t1 select rand()*10240; mysql> select * from t1; +------+ | c1 | +------+ | 8078 | +------+
And then connect to one of them SECONDARY node , View just in PRIMARY Whether the written data can be seen :
$mysql -h172.16.16.11 -uroot -Spath/mysql.sock mysql> use mgr; mysql> select * from t1; +------+ | c1 | +------+ | 8078 | +------+
Confirm that the data can be read .
Come here , Three nodes are completed MGR Installation and deployment of cluster .
Reference material 、 file
- MySQL 8.0 Reference Manual
- Database kernel development - Wenzheng Lake
- Group Replication principle - Song libing
disclaimer
Due to limited personal level , There are inevitable mistakes and omissions in the column , Do not directly copy the commands in the document 、 The method is directly applied to the online production environment . Readers must fully understand and verify the test environment before formal implementation , Avoid damaging or damaging the production environment .
边栏推荐
- Browser independent way to detect when image has been loaded
- Understand GB, gbdt and xgboost step by step
- [CodeWars]Matrix Determinant
- what the fuck! If you can't grab it, write it yourself. Use code to realize a Bing Dwen Dwen. It's so beautiful ~!
- Rebirth -- C language and the story I have to tell (text)
- II Data preprocessing
- Problem thinking and analysis process
- Detailed explanation of GCC usage
- Anaconda creates a new environment encounter pit
- Get the structure of the class through reflection, little chestnut
猜你喜欢

Data analysis method - user group analysis

Cmake configuration error, error configuration process, Preject files may be invalid

Docker installs mysql5.7 and mounts the configuration file

CSDN browser assistant for online translation, calculation, learning and removal of all advertisements

Ch340 and PL2303 installation (with link)

Third order magic cube formula

II Data preprocessing

Small knowledge points of asset

2021-11-11

Performance test -- Jenkins environment construction for 15jmeter performance test
随机推荐
Operator part
6. const usage, combination of first and second level pointers
Third order magic cube formula
【CodeWars】 Pete, the baker
C language game minesweeping [simple implementation]
Understand GB, gbdt and xgboost step by step
Branch and loop statements (including goto statements) -part1
4. functions and inline functions with default values for formal parameters
Why is BeanUtils not recommended?
//1.16 getchar function
C language foundation ----- write a function to find the larger value of two unequal integers
Microservice Optimization: internal communication of microservices using grpc
How to make word notes beautiful
Solution to the problem of easycvr switching MySQL database traffic statistics cannot be displayed
Practice and exploration of vivo live broadcast application technology
Custom shapes for ugui skill learning
5g core network and core network evolution
Get the structure of the class through reflection, little chestnut
Ansible practice of Nepal graph
Solve the problem that QQ flash photos cannot be saved