当前位置:网站首页>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 !
边栏推荐
- phpstudy设置项目可以由局域网的其他电脑可以访问
- Kubernetes notes (VII) kuberetes scheduling
- Loss function in pytorch multi classification
- Installation du plug - in CAD et chargement automatique DLL, Arx
- Exportation et importation de tables de bibliothèque avec binaires MySQL
- 伯努利分布,二项分布和泊松分布以及最大似然之间的关系(未完成)
- BeanDefinitionRegistryPostProcessor
- Cesium 点击获三维坐标(经纬度高程)
- Solve the problem that Anaconda environment cannot be accessed in PowerShell
- [escape character] [full of dry goods] super detailed explanation + code illustration!
猜你喜欢

Loss function in pytorch multi classification

Kubernetes notes (III) controller

pytorch 搭建神经网络最简版

理解 期望(均值/估计值)和方差
![[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]

Redhat7系统root用户密码破解

Oauth2.0 - explanation of simplified mode, password mode and client mode

卷积神经网络CNN中的卷积操作详解

Convolution operation in convolution neural network CNN

Disruptor learning notes: basic use, core concepts and principles
随机推荐
Oauth2.0 - use database to store client information and authorization code
Oauth2.0 - using JWT to replace token and JWT content enhancement
Alibaba cloud OOS file upload
轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
Apt update and apt upgrade commands - what is the difference?
[set theory] relational closure (reflexive closure | symmetric closure | transitive closure)
Download the corresponding version of chromedriver
If function of MySQL
多线程与高并发(7)——从ReentrantLock到AQS源码(两万字大章,一篇理解AQS)
Kubernetes notes (III) controller
Detailed explanation of iptables (1): iptables concept
从 Amazon Aurora 迁移数据到 TiDB
Oauth2.0 - Introduction and use and explanation of authorization code mode
Kubernetes cluster environment construction & Deployment dashboard
Apache+php+mysql environment construction is super detailed!!!
Personal outlook | looking forward to the future from Xiaobai's self analysis and future planning
Leetcode solution - 01 Two Sum
深度学习,从一维特性输入到多维特征输入引发的思考
Code generator - single table query crud - generator
Sorry, this user does not exist!