当前位置:网站首页>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 !
边栏推荐
- Merge and migrate data from small data volume, sub database and sub table Mysql to tidb
- 使用 Abp.Zero 搭建第三方登录模块(一):原理篇
- Life is a process of continuous learning
- How does win7 solve the problem that telnet is not an internal or external command
- 从 Amazon Aurora 迁移数据到 TiDB
- 多线程与高并发(7)——从ReentrantLock到AQS源码(两万字大章,一篇理解AQS)
- 技术管理进阶——你了解成长的全貌吗?
- PHP notes are super detailed!!!
- Skywalking8.7 source code analysis (II): Custom agent, service loading, witness component version identification, transform workflow
- Maximum likelihood estimation, divergence, cross entropy
猜你喜欢
Deep learning, thinking from one dimensional input to multi-dimensional feature input
Apache+php+mysql environment construction is super detailed!!!
Pytorch builds the simplest version of neural network
卷积神经网络CNN中的卷积操作详解
深入解析kubernetes controller-runtime
使用 Abp.Zero 搭建第三方登录模块(一):原理篇
[minesweeping of two-dimensional array application] | [simple version] [detailed steps + code]
Method of converting GPS coordinates to Baidu map coordinates
Personal outlook | looking forward to the future from Xiaobai's self analysis and future planning
Kubernetes notes (II) pod usage notes
随机推荐
Personal outlook | looking forward to the future from Xiaobai's self analysis and future planning
Phpstudy setting items can be accessed by other computers on the LAN
Kubernetes notes (V) configuration management
How to create your own repository for software packages on Debian
Complete set of C language file operation functions (super detailed)
[teacher Zhao Yuqiang] kubernetes' probe
深度学习,从一维特性输入到多维特征输入引发的思考
Understand one-way hash function
ThreadLocal的简单理解
理解 期望(均值/估计值)和方差
Pytorch dataloader implements minibatch (incomplete)
Exception when introducing redistemplate: noclassdeffounderror: com/fasterxml/jackson/core/jsonprocessingexception
[teacher Zhao Yuqiang] use Oracle's tracking file
Oauth2.0 - Introduction and use and explanation of authorization code mode
Simple handwritten ORM framework
1. Sum of two numbers
pytorch 搭建神经网络最简版
Common exceptions when Jenkins is released (continuous update...)
MySQL帶二進制的庫錶導出導入
项目总结--01(接口的增删改查;多线程的使用)