当前位置:网站首页>17、 MySQL - high availability + read / write separation + gtid + semi synchronous master-slave replication cluster
17、 MySQL - high availability + read / write separation + gtid + semi synchronous master-slave replication cluster
2022-07-06 23:46:00 【Seven peanuts】
Catalog
Catalog
2 Taichung middleware server ( No installation required MySQL):
1 platform client Customer service machine ( Need to install MySQL, Used to simulate access ):
1. First, set up 2 platform MySQL Master slave replication on the server
( Default 2 Taiwan machine MySQL Make data consistent through backup )
①、 stay master Upper /etc/my.cnf File configuration :
②、 stay slave Upper /etc/my.cnf File configuration :
③、 stay master Create one for slave The authorized account used
④、 stay slave Upper MySQL Modify the configuration in ( Failure words stop slave Try again. )
⑤、 Still in slave On the input start slave Turn on slave, Input show slave status\G Text view
⑥、 Verify whether the master-slave service is effective
⑦、 Verify whether the semi synchronization is effective
( All installed by default mysqlrouter)
①、 To configure MASTER Upper /etc/mysqlrouter/mysqlrouter.conf
②、 To configure BACKUP Upper /etc/mysqlrouter/mysqlrouter.conf and MASTER Same configuration
3. Configure the high availability function of two middleware keepalived
( All installed by default keepalived)
①、 Configure the first instance vip
②、 Configure the second instance vip
4. Successful cluster construction
Project layout :
Project name :
Build a high availability based on binlog+gtid Realize read-write separation and semi synchronous master-slave replication
Project environment :
2 platform MySQL The server :
master:192.168.2.129 CentOS Linux release 7.9.2009 (Core)、MySQL5.7.34
slave:192.168.2.204 CentOS Linux release 7.9.2009 (Core)、MySQL5.7.34
2 Taichung middleware server ( No installation required MySQL):
master:192.168.2.100 CentOS Linux release 7.9.2009 (Core)、MySQL Router Ver 8.0.28 for Linux on x86_64 (MySQL Community - GPL)、Keepalived v1.3.5 (03/19,2017)
slave:192.168.126 CentOS Linux release 7.9.2009 (Core)、MySQL Router Ver 8.0.28 for Linux on x86_64 (MySQL Community - GPL)、Keepalived v1.3.5 (03/19,2017)
1 platform client Customer service machine ( Need to install MySQL, Used to simulate access ):
client:192.168.2.128 CentOS Linux release 7.9.2009 (Core)、MySQL5.7.34
Project steps :
1. First, set up 2 platform MySQL Master slave replication on the server
( Default 2 Taiwan machine MySQL Make data consistent through backup )
①、 stay master Upper /etc/my.cnf File configuration :
[mysqld]
socket=/data/mysql/mysql.sock
log_bin # Start database update binary logging , The prefix of log file name is default , You can set it yourself
server_id = 1 # The host to 1, Unique identification
gtid-mode=on # The main library generates GTID Business , From the library can only be GTID Business . by off Anonymous transaction
enforce-gtid-consistency=on# Only execution is allowed and can be used GTID Security record statements to enforce GTID Uniformity
rpl_semi_sync_master_enabled=1# Turn on semi synchronous mode
rpl_semi_sync_master_timeout=1000 # Set the timeout to 1s, exceed 1s Switch to asynchronous mode
port = 3306 #MySQL port
open_files_limit = 8192 # Maximum concurrency
innodb_buffer_pool_size = 512M #innodb Cache pool size
character-set-server=utf8 # Character set format
# Remember to restart after configuration mysql service , Make it effective
②、 stay slave Upper /etc/my.cnf File configuration :
[mysqld]
socket=/data/mysql/mysql.sock
log_bin # Turn on binary log
server_id = 2 # The host to 2, Unique identification
gtid-mode=on # Modify anonymous transaction to GTID Business
log_slave_updates=on # Binary logs from the master server , Update to your binary log
enforce-gtid-consistency=on # Uniformity
port = 3306
open_files_limit = 8192
innodb_buffer_pool_size = 512M
character-set-server=utf8
# Remember to restart after configuration mysql service , Make it effective
③、 stay master Create one for slave The authorized account used
grant all on *.* to 'sc'@'%' identified by '123456'
④、 stay slave Upper MySQL Modify the configuration in ( Failure words stop slave Try again. )
CHANGE MASTER TO MASTER_HOST='192.168.2.129', # Fill in your own masterIP Address
MASTER_USER='sc', # The account just authorized
MASTER_PASSWORD='123456', # Password of the account
MASTER_PORT=3306,# Port number
MASTER_AUTO_POSITION = 1; #gtid from 1 Start , It doesn't need to be modified
⑤、 Still in slave On the input start slave Turn on slave, Input show slave status\G Text view
[email protected](none) 23:57 mysql>show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.2.129
Master_User: sc
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000007
Read_Master_Log_Pos: 390
Relay_Log_File: slave-relay-bin.000003
Relay_Log_Pos: 525
Relay_Master_Log_File: master-bin.000007
Slave_IO_Running: Yes #
Slave_SQL_Running: Yes # These two lines are YES It indicates that the master-slave copy setting is successful
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 390
Relay_Log_Space: 947
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: 45f9f58e-8a77-11ec-a98d-000c293c0ce3
Master_Info_File: /data/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 45f9f58e-8a77-11ec-a98d-000c293c0ce3:5
Executed_Gtid_Set: 45f9f58e-8a77-11ec-a98d-000c293c0ce3:1-5,
89592241-8a7e-11ec-bd5b-000c29248fa7:1-3
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)ERROR:
No query specified
⑥、 Verify whether the master-slave service is effective
stay master Create a library on , stay slave You can also see that it is success
⑦、 Verify whether the semi synchronization is effective
First, in the slave On the input stop slave, And then again master Create a library on , If you get stuck 1s After returning to normal, it will take effect , To turn on semi synchronization again, you only need to slave On the input start slave.
2. To configure 2 Taichung middleware server mysqlrouter Realize the function of reading and writing separation
( All installed by default mysqlrouter)
①、 To configure MASTER Upper /etc/mysqlrouter/mysqlrouter.conf
bind_address = 0.0.0.0 # All on this machine IPV4 All addresses are accessible
bind_port = 7001 # port
mode = read-write # Read and write functions
destinations = 192.168.2.129:3306 # Purpose IP by master The machine 3306 port
max_connections = 65535
max_connect_errors = 100
client_connect_timeout = 9
[routing:read_only]
bind_address = 0.0.0.0 # All on this machine IPV4 All addresses are accessible
bind_port = 7002 # port
mode = read-only # read-only
destinations = 192.168.2.204:3306 # Purpose IP by slave Of 3306 port
max_connections = 65535
max_connect_errors = 100
client_connect_timeout = 9
# Refresh the service to make its configuration effective
②、 To configure BACKUP Upper /etc/mysqlrouter/mysqlrouter.conf and MASTER Same configuration
bind_address = 0.0.0.0
bind_port = 7001
mode = read-write
destinations = 192.168.2.129:3306
max_connections = 65535
max_connect_errors = 100
client_connect_timeout = 9
[routing:read_only]
bind_address = 0.0.0.0
bind_port = 7002
mode = read-only
destinations = 192.168.2.204:3306
max_connections = 65535
max_connect_errors = 100
client_connect_timeout = 9
Refresh the service to make its configuration effective
③、 Verify that it works
Use client machine (IP:192.168.2.128):
[[email protected] ~]# mysql -h 192.168.2.100 -P 7001 -usc -p'123456'
[[email protected] ~]# mysql -h 192.168.2.100 -P 7002 -usc -p'123456'
# Input show processlist; Show Host All are middleware MASTER Of IP Address is success
[[email protected] ~]# mysql -h 192.168.2.126 -P 7001 -usc -p'123456'
[[email protected] ~]# mysql -h 192.168.2.126 -P 7002 -usc -p'123456'
# Input show processlist; Show Host All are middleware BACKUP Of IP Address is success
# I am here master and slave All created sc Account and password are '123456', Can be from any IP Come on .
3. Configure the high availability function of two middleware keepalived
( All installed by default keepalived)
①、 Configure the first instance vip
MASTER:
global_defs {
notification_email {
[email protected]
[email protected]
[email protected]
}
notification_email_from [email protected]
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
# vrrp_strict # Comment out this parameter
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state MASTER # The first instance is mainly configured
interface ens33 # Bind network card , Use ip add View NIC
virtual_router_id 151 # only vrid
priority 120 # Set permissions higher
advert_int 1
authentication {
auth_type PASS
auth_pass 1111 # The default password is ok
}
virtual_ipaddress {
192.168.2.16 #vip fictitious IP
}
}
# Delete all subsequent lines , We only use keepalived High availability of , It doesn't need to keepalived Load balancing of
# Remember to refresh keepalived service , Make configuration effective
BACKUP:
global_defs {
notification_email {
[email protected]
[email protected]
[email protected]
}
notification_email_from [email protected]
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
# vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state BACKUP # Set as standby
interface ens33 # adapter name
virtual_router_id 151 # and MASTER Must be consistent , Otherwise, there will be brain cracking
priority 100 # Authority ratio MASTER low
advert_int 1
authentication {
auth_type PASS
auth_pass 1111 # The password defaults
}
virtual_ipaddress {
192.168.2.16 # and MASTER The same vip
}
}
# Delete all subsequent lines , We only use keepalived High availability of , It doesn't need to keepalived Load balancing of
# Remember to refresh keepalived service , Make configuration effective
Verify that it works
stay MASTER End input ip add
stay BACKUP End input ip add
# stay MASTER The end appears , stay BACKUP It is normal if it does not appear , At the same time, it is called Split brain The phenomenon , But it doesn't matter
②、 Configure the second instance vip
MASTER: Add an instance on the last side vrrp_instance VI_2
vrrp_instance VI_2 {
state BACKUP # Set as standby
interface ens33
virtual_router_id 153 # Need and instance 1 Of 151 Different
priority 100 # Priority is set to 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.2.18 3 # Need and instance 1 Of vip Distinguish , Set separately
}
}
# Refresh keepalived service , Make configuration effective
BACKUP: Add an instance on the last side vrrp_instance VI_2
vrrp_instance VI_2 {
state MASTER # Set as primary
interface ens33
virtual_router_id 153 # And MASTER The machines are the same
priority 120 # Priority is set to 120, Make this one BACKUP The machine is in charge
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.2.18 # and MASTER Keep the machine consistent
}
}
# Refresh keepalived service , Make configuration effective
Verify that it works
stay BACKUP You see on the machine
stay MASTER The machine is still before
4. Successful cluster construction
client Use vip1 Connect MASTER Of 7001 port , Reach connection master Of MySQL Database effect
client Use vip1 Connect MASTER Of 7002 port , Reach connection slave Of MySQL Database effect
client Use vip2 To connect BACKUP Of 7001 port , Reach connection master Of MySQL Database effect
client Use vip2 To connect BACKUP Of 7002 port , Reach connection slave Of MySQL Database effect
# Judge the connection is master still slave You can see command Is there one in Binlog Dump GTID Description of , Some for master, If not, it means slave.
边栏推荐
- CRMEB 商城系统如何助力营销?
- Koa2 addition, deletion, modification and query of JSON array
- 问下各位,有没有flink sql生成作业的文档啊或是案列啊知道flink cli可以建表和指定目
- 【无人机】多无人协同任务分配程序平台含Matlab代码
- 氢创未来 产业加速 | 2022氢能专精特新创业大赛报名通道开启!
- 服务器SMP、NUMA、MPP体系学习笔记。
- 达晨史上最大单笔投资,今天IPO了
- B 站弹幕 protobuf 协议还原分析
- Should the jar package of MySQL CDC be placed in different places in the Flink running mode?
- 谁说新消费品牌大溃败?背后有人赢麻了
猜你喜欢
STM32通过串口进入和唤醒停止模式
《数字经济全景白皮书》保险数字化篇 重磅发布
koa2对Json数组增删改查
Please help xampp to do sqlilab is a black
Résumé des connaissances de gradle
每日刷题记录 (十五)
B 站弹幕 protobuf 协议还原分析
Rider离线使用Nuget包的方法
How to find out if the U disk file of the computer reinstallation system is hidden
Detailed explanation of regular expression (regexp) in MySQL
随机推荐
Yaduo Sangu IPO
Résumé des connaissances de gradle
What does front-end processor mean? What is the main function? What is the difference with fortress machine?
吴恩达2022机器学习课程评测来了!
(1) Chang'an chain learning notes - start Chang'an chain
Restoration analysis of protobuf protocol of bullet screen in station B
Local deployment Zeppelin 0.10.1
The method of reinstalling win10 system is as simple as that
【通信】两层无线 Femtocell 网络上行链路中的最优功率分配附matlab代码
Today's sleep quality record 78 points
Example code of MySQL split string as query condition
【212】php发送post请求有哪三种方法
请问oracle-cdc用JsonDebeziumDeserializationSchema反序列化
Use mitmproxy to cache 360 degree panoramic web pages offline
What should I do if the USB flash disk data is formatted and how can I recover the formatted USB flash disk data?
How does crmeb mall system help marketing?
[OFDM communication] OFDM system signal detection based on deep learning with matlab code
Newsletter L Huobi ventures is in-depth contact with genesis public chain
Cover fake big empty talk in robot material sorting
Where does this "judge the operation type according to the op value and assemble SQL by yourself" mean? It means simply using Flink tab