当前位置:网站首页>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.
边栏推荐
- Wasserstein Slim GAIN with Gradient Penalty(WSGAIN-GP)介绍及代码实现——基于生成对抗网络的缺失数据填补
- The same job has two sources, and the same link has different database accounts. Why is the database list found in the second link the first account
- 服务器SMP、NUMA、MPP体系学习笔记。
- Station B Big utilise mon monde pour faire un réseau neuronal convolutif, Le Cun Forward! Le foie a explosé pendant 6 mois, et un million de fois.
- (LeetCode)两数之和
- Daily question brushing record (XV)
- Résumé des connaissances de gradle
- Efficient ETL Testing
- 快讯 l Huobi Ventures与Genesis公链深入接洽中
- js對JSON數組的增删改查
猜你喜欢
MATLIB reads data from excel table and draws function image
每年 2000 亿投资进入芯片领域,「中国芯」创投正蓬勃
leetcode:236. 二叉树的最近公共祖先
The important data in the computer was accidentally deleted by mistake, which can be quickly retrieved by this method
Close unregistering application XXX with Eureka with status down after Eureka client starts
Résumé des connaissances de gradle
JS addition, deletion, modification and query of JSON array
内网穿透zerotier 外网(手机、电脑等)访问内网设备(树莓派、NAS、电脑等)
app通用功能测试用例
Per capita Swiss number series, Swiss number 4 generation JS reverse analysis
随机推荐
Competition between public and private chains in data privacy and throughput
[system analyst's road] Chapter 7 double disk system design (service-oriented development method)
Unity 颜色板|调色板|无级变色功能
若依请求url中带有jsessionid的解决办法
The programmer refused the offer because of low salary, HR became angry and netizens exploded
Station B Big utilise mon monde pour faire un réseau neuronal convolutif, Le Cun Forward! Le foie a explosé pendant 6 mois, et un million de fois.
自动化测试工具Katalon(Web)测试操作说明
Implementation steps of mysql start log in docker
【系统分析师之路】第七章 复盘系统设计(面向服务开发方法)
Talking about the current malpractice and future development
编译logisim
【通信】两层无线 Femtocell 网络上行链路中的最优功率分配附matlab代码
A novice asks a question. I am now deployed on a single machine. I submitted an SQL job and it runs normally. If I restart the service job, it will disappear and I will have to
B 站弹幕 protobuf 协议还原分析
Cloud native (32) | kubernetes introduction to platform storage system
flinksql select id ,count(*) from a group by id .
One minute to learn how to install the system, win7 XP, win10 and win11 become very simple
The programmer said, "I'm 36 years old, and I don't want to be rolled, let alone cut."
GPT-3当一作自己研究自己,已投稿,在线蹲一个同行评议
服务器SMP、NUMA、MPP体系学习笔记。