当前位置:网站首页>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 !
边栏推荐
- [trivia of two-dimensional array application] | [simple version] [detailed steps + code]
- [advanced pointer (2)] | [function pointer, function pointer array, callback function] key analysis + code explanation
- Jedis source code analysis (II): jediscluster module source code analysis
- If function of MySQL
- Apache+php+mysql environment construction is super detailed!!!
- Bernoulli distribution, binomial distribution and Poisson distribution, and the relationship between maximum likelihood (incomplete)
- Life is a process of continuous learning
- [teacher Zhao Yuqiang] use the catalog database of Oracle
- arcgis创建postgre企业级数据库
- Apple submitted the new MAC model to the regulatory database before the spring conference
猜你喜欢

最大似然估计,散度,交叉熵

深度学习,从一维特性输入到多维特征输入引发的思考
![[teacher Zhao Yuqiang] redis's slow query log](/img/a7/2140744ebad9f1dc0a609254cc618e.jpg)
[teacher Zhao Yuqiang] redis's slow query log
![[set theory] relational closure (reflexive closure | symmetric closure | transitive closure)](/img/c8/2995c503e9dabae4e2cc704449e04f.jpg)
[set theory] relational closure (reflexive closure | symmetric closure | transitive closure)

JDBC connection database steps

Alibaba cloud OOS file upload
![[teacher Zhao Yuqiang] use Oracle's tracking file](/img/0e/698478876d0dbfb37904d7b9ff9aca.jpg)
[teacher Zhao Yuqiang] use Oracle's tracking file

Clickhouse learning notes (I): Clickhouse installation, data type, table engine, SQL operation
![[branch and cycle] | | super long detailed explanation + code analysis + a trick game](/img/aa/543d4f0dcbcd664be963579af77ec9.jpg)
[branch and cycle] | | super long detailed explanation + code analysis + a trick game

Kubernetes notes (II) pod usage notes
随机推荐
Intel's new GPU patent shows that its graphics card products will use MCM Packaging Technology
为什么网站打开速度慢?
MySQL带二进制的库表导出导入
Jackson: what if there is a lack of property- Jackson: What happens if a property is missing?
@Import annotation: four ways to import configuration classes & source code analysis
Solve the problem of automatic disconnection of SecureCRT timeout connection
How to create your own repository for software packages on Debian
轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
【系统设计】邻近服务
Multithreading and high concurrency (7) -- from reentrantlock to AQS source code (20000 words, one understanding AQS)
Method of finding prime number
[teacher Zhao Yuqiang] use Oracle's tracking file
Oauth2.0 - explanation of simplified mode, password mode and client mode
Use telnet to check whether the port corresponding to the IP is open
Deep learning, thinking from one dimensional input to multi-dimensional feature input
Disruptor learning notes: basic use, core concepts and principles
Clickhouse learning notes (I): Clickhouse installation, data type, table engine, SQL operation
Txt document download save as solution
智牛股--03
[teacher Zhao Yuqiang] MySQL high availability architecture: MHA