当前位置:网站首页>Kubesphere - build MySQL master-slave replication structure
Kubesphere - build MySQL master-slave replication structure
2022-07-03 06:06:00 【Xiao bichao】
One 、KubeSphere
In the last article, we introduced KubeSphere Implementation of multi tenant scenario , In this article, we use KubeSphere build mysql The master-slave structure of , Here is the address of the last article :
Before the experiment , Please make sure that the installation is complete k8s And kubesphere Environmental Science :
Two 、mysql Main node construction
establish PVC Storage volume
First, create the storage volume of the primary node PVC, Store the data files generated by the master node :
Give the configuration file a name and description :
choice Storage mode and size , Then next, create Just Create a master node PVC 了 :

establish my.cnf Prepare a dictionary

Name the preparation , And then the next step , Click add data :
Key can be written my.cnf It is iconic , Values can be filled in the following , Pay attention to change it to your own database name :
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve
server_id=1
log-bin=mysql-bin
# Is it read-only 0=false 1=true
read-only=0
# Databases that need to be synchronized
binlog-do-db=test_db
#binlog-do-db=test_db1
# Exclude synchronized databases
replicate-ignore-db=mysql
replicate-ignore-db=sys
replicate-ignore-db=performance_schema
replicate-ignore-db=information_schema

Then create :
establish mysql master service

Choose stateful Services , You can use headless Generate a stable domain name in k8s Use in cluster :
Also name the service :
Let's choose mysql:5.7 Version of , Use the default port :
The following can be true of cpu And memory , It mainly depends on the preparation of your service , Add... Below root Environment variable for user password :MYSQL_ROOT_PASSWORD
Passwords can be used by referencing confidential dictionaries , It's written directly here .
Next, choose to hang on the storage volume :
Hanging on PVC It's the one created above PVC, Read write mode , The mount directory is :/var/lib/mysql
Then you need to hang it on my.cnf Configuration files :

Or choose the configuration dictionary created above , Hang in the directory as /etc/mysql Under the my.cnf file :
And then the next step , Click create to create mysql service :
You can click to enter , The container list , The terminal that can enter the container :
Here you can enter the just created mysql in :
It is said above that if there is a state, it will pass headless Created a stable domain name , You can see in the service details :
The domain name is mysql-master.test-project This needs to be recorded , You need to use .
3、 ... and 、mysql Build from node
The construction process of the slave node is the same as that of the master node above , First create a slave node PVC, Then create a slave node my.cnf Configuration dictionary , Also create stateful Services , And select mysql:5.7 Image of version , And reference the... Of the slave node PVC And from the node my.cnf Prepare a dictionary :
PVC Storage volume :

my.cnf Prepare a dictionary :

Preparation content , And the master node only server_id Different :
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve
server_id=2
log-bin=mysql-bin
# Is it read-only 0=false 1=true
read-only=1
# Table data that needs to be synchronized
binlog-do-db=test_db
#binlog-do-db=test_db1
# Exclude synchronized table data
replicate-ignore-db=mysql
replicate-ignore-db=sys
replicate-ignore-db=performance_schema
replicate-ignore-db=information_schema
establish slave service :

3、 ... and 、mysql Master slave configuration
Master node configuration
First enter the terminal of the master node , Get into mysql in , Create a user for the slave node :
GRANT REPLICATION SLAVE ON *.* TO 'slave'@'%' IDENTIFIED BY 'slave123';

View the status of the master node , among File Columns need to be recorded :
SHOW MASTER STATUS;

Here is mysql-bin.000003 Later, the slave node will synchronize this log file :
Configure from node
Enter the terminal of the slave node , Enter again mysql in , First, join the synchronization of the master node :
CHANGE MASTER TO MASTER_HOST='mysql-master.test-project',MASTER_USER='slave',MASTER_PASSWORD='slave123',MASTER_LOG_FILE='mysql-bin.000003',MASTER_LOG_POS=0,MASTER_PORT=3306;
Notice the mysql-master.test-project and mysql-bin.000003 , All of them are in the master node above :
Start syncing :
start slave;

View the status of synchronization :
show slave status\G;

Synchronization has been started , Next, test whether the master-slave synchronization is normal :
Four 、 Test master and slave
First create in the master node test_db database , And test_table surface , And write some test data :
create database test_db;
CREATE TABLE `test_table` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
INSERT INTO `test_db`.`test_table`(`id`, `name`) VALUES (1, 'test1');
INSERT INTO `test_db`.`test_table`(`id`, `name`) VALUES (2, 'test2');
View from the node :


Love little buddy can pay attention to my personal WeChat official account. , Get more learning materials !
边栏推荐
- Crontab command usage
- Code generator - single table query crud - generator
- Leetcode solution - 01 Two Sum
- [written examination question analysis] | | get [sizeof and strlen] [pointer and array] graphic explanation + code analysis
- [teacher Zhao Yuqiang] the most detailed introduction to PostgreSQL architecture in history
- Kubesphere - Multi tenant management
- PMP笔记记录
- 88. Merge two ordered arrays
- Apt update and apt upgrade commands - what is the difference?
- [escape character] [full of dry goods] super detailed explanation + code illustration!
猜你喜欢

Merge and migrate data from small data volume, sub database and sub table Mysql to tidb

Code generator - single table query crud - generator

pytorch 搭建神经网络最简版

Personal outlook | looking forward to the future from Xiaobai's self analysis and future planning

为什么网站打开速度慢?

【系统设计】邻近服务

从小数据量分库分表 MySQL 合并迁移数据到 TiDB

Redhat7系统root用户密码破解

多线程与高并发(7)——从ReentrantLock到AQS源码(两万字大章,一篇理解AQS)
![[minesweeping of two-dimensional array application] | [simple version] [detailed steps + code]](/img/b0/aa5dce0bb60c50eea907de9e127d6c.jpg)
[minesweeping of two-dimensional array application] | [simple version] [detailed steps + code]
随机推荐
Oauth2.0 - using JWT to replace token and JWT content enhancement
Convolution operation in convolution neural network CNN
Mysql database table export and import with binary
项目总结--01(接口的增删改查;多线程的使用)
88. 合并两个有序数组
1. Somme des deux nombres
PMP笔记记录
pytorch 多分类中的损失函数
Why is the website slow to open?
The programmer shell with a monthly salary of more than 10000 becomes a grammar skill for secondary school. Do you often use it!!!
Simple solution of small up main lottery in station B
There is no one of the necessary magic skills PXE for old drivers to install!!!
最大似然估计,散度,交叉熵
Strategy pattern: encapsulate changes and respond flexibly to changes in requirements
1. Sum of two numbers
PHP用ENV获取文件参数的时候拿到的是字符串
深度学习,从一维特性输入到多维特征输入引发的思考
项目总结--04
Detailed explanation of findloadedclass
伯努利分布,二项分布和泊松分布以及最大似然之间的关系(未完成)