Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deploy mysql 8.0 MGR on K8s

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the knowledge of "how to deploy mysql 8.0 MGR on K8s". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

one. Overview of the environment

K8s environment: 1 master node, 3 node nodes.

Set up a MGR cluster on three nodes. The data files of mysql are mounted and stored locally. After the creation of the image, you need to copy the initialized data files to the local mount point / data/mysql/data/, of the three nodes. In addition, you need to modify the uuid in the auto.cnf to make the uuid of the three nodes different.

two. Building steps

Make a mysql 8.0.15 image

Skip this step and refer to mysql's official binary package installation step, https://dev.mysql.com/doc/refman/8.0/en/binary-installation.html. After installation, it is made into an image.

Prepare to generate the related yaml file for the three-node pod.

-create the file namespace.yaml of namespace:

ApiVersion: v1

Kind: Namespace

Metadata:

Name: mysqldb

-Node 1 configmap file mysql-mgr-cnf-0.yaml:

ApiVersion: v1

Data:

Mysql-mgr-0.cnf: |

[mysqld]

Port = 3306

Character_set_server = utf8

Socket = / tmp/mysql.sock

Basedir = / usr/local/mysql

Log-error = / data/mysql/data/mysql.err

Pid-file = / data/mysql/data/mysql.pid

Datadir = / data/mysql/data

Server_id = 092832

Log_bin = mysql-bin

Relay-log = relay-bin

# back_log = 500

# max_connections = 3000

# wait_timeout = 5022397

Interactive_timeout = 5022397

Max_connect_errors = 1000

Relay-log-recovery=1

# max_allowed_packet = 32m

Sort_buffer_size = 4m

Read_buffer_size = 4m

Join_buffer_size = 8m

Thread_cache_size = 64

# tmp_table_size = 256m

Log_slave_updates=1

Long_query_time = 1

Slow_query_log = 1

Slow_query_log_file = / data/mysql/data/slow_sql.log

Skip-name-resolve

Sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

Innodb_buffer_pool_size=700M

# innodb_data_file_path = ibdata1:1024M:autoextend

Innodb_flush_log_at_trx_commit=1

Innodb_log_buffer_size = 16m

Innodb_log_file_size = 256m

Innodb_log_files_in_group = 2

Innodb_max_dirty_pages_pct = 50

Sync_binlog=1

Master_info_repository=TABLE

Relay_log_info_repository=TABLE

Log_timestamps=SYSTEM

Gtid_mode = ON

Enforce_gtid_consistency = ON

Master_info_repository = TABLE

Relay_log_info_repository = TABLE

Log_slave_updates = ON

Binlog_checksum = NONE

Log_slave_updates = ON

Slave_parallel_type=LOGICAL_CLOCK

Slave_parallel_workers=8

Slave-preserve-commit-order=on

# group_replication_compression_threshold=200000

Transaction_write_set_extraction = XXHASH64

Loose-group_replication_group_name= "01e5fb97-be64-41f7-bafd-3afc7a6ab555"

Loose-group_replication_start_on_boot=off

Loose-group_replication_local_address= "mysql-mgr-0.mgrtest.mysqldb.svc.cluster.local.:13306"

Loose-group_replication_group_seeds= "mysql-mgr-0.mgrtest.mysqldb.svc.cluster.local.:13306,mysql-mgr-1.mgrtest.mysqldb.svc.cluster.local.:13306,mysql-mgr-2.mgrtest.mysqldb.svc.cluster.local.:13306"

Loose-group_replication_bootstrap_group = off

Loose-group_replication_ip_whitelist='10.244.0.0/16172.17.0.0/16,10.229.0.0/16,10.228.0.0/16'

Report_host = mysql-mgr-0.mgrtest.mysqldb.svc.cluster.local

[mysqldump]

Quick

Max_allowed_packet = 32m

Kind: ConfigMap

Metadata:

Name: mysql-mgr-0-cnf

Namespace: mysqldb

-Node 2 configmap file mysql-mgr-cnf-1.yaml:

ApiVersion: v1

Data:

Mysql-mgr-1.cnf: |

[mysqld]

Port = 3306

Character_set_server = utf8

Socket = / tmp/mysql.sock

Basedir = / usr/local/mysql

Log-error = / data/mysql/data/mysql.err

Pid-file = / data/mysql/data/mysql.pid

Datadir = / data/mysql/data

Server_id = 092231

Log_bin = mysql-bin

Relay-log = relay-bin

# back_log = 500

# max_connections = 3000

# wait_timeout = 5022397

Interactive_timeout = 5022397

Max_connect_errors = 1000

Relay-log-recovery=1

# max_allowed_packet = 32m

Sort_buffer_size = 4m

Read_buffer_size = 4m

Join_buffer_size = 8m

Thread_cache_size = 64

# tmp_table_size = 256m

Log_slave_updates=1

Long_query_time = 1

Slow_query_log = 1

Slow_query_log_file = / data/mysql/data/slow_sql.log

Skip-name-resolve

Sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

Innodb_buffer_pool_size=700M

# innodb_data_file_path = ibdata1:1024M:autoextend

Innodb_flush_log_at_trx_commit=1

Innodb_log_buffer_size = 16m

Innodb_log_file_size = 256m

Innodb_log_files_in_group = 2

Innodb_max_dirty_pages_pct = 50

Sync_binlog=1

Master_info_repository=TABLE

Relay_log_info_repository=TABLE

Log_timestamps=SYSTEM

Gtid_mode = ON

Enforce_gtid_consistency = ON

Master_info_repository = TABLE

Relay_log_info_repository = TABLE

Log_slave_updates = ON

Binlog_checksum = NONE

Log_slave_updates = ON

Slave_parallel_type=LOGICAL_CLOCK

Slave_parallel_workers=8

Slave-preserve-commit-order=on

# group_replication_compression_threshold=200000

Transaction_write_set_extraction = XXHASH64

Loose-group_replication_group_name= "01e5fb97-be64-41f7-bafd-3afc7a6ab555"

Loose-group_replication_start_on_boot=off

Loose-group_replication_local_address= "mysql-mgr-1.mgrtest.mysqldb.svc.cluster.local.:13306"

Loose-group_replication_group_seeds= "mysql-mgr-0.mgrtest.mysqldb.svc.cluster.local.:13306,mysql-mgr-1.mgrtest.mysqldb.svc.cluster.local.:13306,mysql-mgr-2.mgrtest.mysqldb.svc.cluster.local.:13306"

Loose-group_replication_bootstrap_group = off

Loose-group_replication_ip_whitelist='10.244.0.0/16172.17.0.0/16,10.229.0.0/16,10.228.0.0/16'

Report_host = mysql-mgr-1.mgrtest.mysqldb.svc.cluster.local

[mysqldump]

Quick

Max_allowed_packet = 32m

Kind: ConfigMap

Metadata:

Name: mysql-mgr-1-cnf

Namespace: mysqldb

-Node 3 configmap file mysql-mgr-cnf-2.yaml:

ApiVersion: v1

Data:

Mysql-mgr-2.cnf: |

[mysqld]

Port = 3306

Character_set_server = utf8

Socket = / tmp/mysql.sock

Basedir = / usr/local/mysql

Log-error = / data/mysql/data/mysql.err

Pid-file = / data/mysql/data/mysql.pid

Datadir = / data/mysql/data

Server_id = 092132

Log_bin = mysql-bin

Relay-log = relay-bin

# back_log = 500

# max_connections = 3000

# wait_timeout = 5022397

Interactive_timeout = 5022397

Max_connect_errors = 1000

Relay-log-recovery=1

# max_allowed_packet = 32m

Sort_buffer_size = 4m

Read_buffer_size = 4m

Join_buffer_size = 8m

Thread_cache_size = 64

# tmp_table_size = 256m

Log_slave_updates=1

Long_query_time = 1

Slow_query_log = 1

Slow_query_log_file = / data/mysql/data/slow_sql.log

Skip-name-resolve

Sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

Innodb_buffer_pool_size=700M

# innodb_data_file_path = ibdata1:1024M:autoextend

Innodb_flush_log_at_trx_commit=1

Innodb_log_buffer_size = 16m

Innodb_log_file_size = 256m

Innodb_log_files_in_group = 2

Innodb_max_dirty_pages_pct = 50

Sync_binlog=1

Master_info_repository=TABLE

Relay_log_info_repository=TABLE

Log_timestamps=SYSTEM

Gtid_mode = ON

Enforce_gtid_consistency = ON

Master_info_repository = TABLE

Relay_log_info_repository = TABLE

Log_slave_updates = ON

Binlog_checksum = NONE

Log_slave_updates = ON

Slave_parallel_type=LOGICAL_CLOCK

Slave_parallel_workers=8

Slave-preserve-commit-order=on

# group_replication_compression_threshold=200000

Transaction_write_set_extraction = XXHASH64

Loose-group_replication_group_name= "01e5fb97-be64-41f7-bafd-3afc7a6ab555"

Loose-group_replication_start_on_boot=off

Loose-group_replication_local_address= "mysql-mgr-2.mgrtest.mysqldb.svc.cluster.local.:13306"

Loose-group_replication_group_seeds= "mysql-mgr-0.mgrtest.mysqldb.svc.cluster.local.:13306,mysql-mgr-1.mgrtest.mysqldb.svc.cluster.local.:13306,mysql-mgr-2.mgrtest.mysqldb.svc.cluster.local.:13306"

Loose-group_replication_bootstrap_group = off

Loose-group_replication_ip_whitelist='10.244.0.0/16172.17.0.0/16,10.229.0.0/16,10.228.0.0/16'

Report_host = mysql-mgr-2.mgrtest.mysqldb.svc.cluster.local

[mysqldump]

Quick

Max_allowed_packet = 32m

Kind: ConfigMap

Metadata:

Name: mysql-mgr-2-cnf

Namespace: mysqldb

-the yaml file of the pod of node 1:

ApiVersion: v1

Kind: Pod

Metadata:

Name: mysql-mgr-0

Namespace: mysqldb

Labels:

Name: mysql-mgr

Spec:

Affinity:

NodeAffinity:

RequiredDuringSchedulingIgnoredDuringExecution:

NodeSelectorTerms:

-matchExpressions:

-key: mysqlrole

Operator: In

Values: ["mysql-mgr-0"]

Hostname: mysql-mgr-0

Subdomain: mgrtest

Containers:

-image: 172.16.110.102:5000/mysql8.0:latest

Name: mysql-mgr-0

ImagePullPolicy: IfNotPresent

Command: ["/ bin/bash", "- ce", "cd / usr/local/mysql & & bin/mysqld_safe-- defaults-file=/etc/my.cnf & & tail-f / dev/null"]

# env:

#-name: MYSQL_ROOT_PASSWORD

# value: noc-mysql

Ports:

-containerPort: 3306

VolumeMounts:

-name: tz-config

MountPath: / etc/localtime

-name: mysql-data

MountPath: / data/mysql/data/

-name: mysql-config

MountPath: / etc/my.cnf

SubPath: my.cnf

Env:

-name: INNODB_BUFFER_POOL_SIZE

Value: 500M

#-name: REPORT_HOST

# value: mysql-mgr-0.mgrtest.mysqldb.svc.cluster.local

Volumes:

-name: tz-config

HostPath:

Path: / etc/localtime

-name: mysql-data

HostPath:

Path: / data/mysql/data/

-name: mysql-config

ConfigMap:

Name: mysql-mgr-0-cnf

Items:

-key: mysql-mgr-0.cnf

Path: my.cnf

-the yaml file of the pod of node 2:

ApiVersion: v1

Kind: Pod

Metadata:

Name: mysql-mgr-1

Namespace: mysqldb

Labels:

Name: mysql-mgr

Spec:

Affinity:

NodeAffinity:

RequiredDuringSchedulingIgnoredDuringExecution:

NodeSelectorTerms:

-matchExpressions:

-key: mysqlrole

Operator: In

Values: ["mysql-mgr-1"]

Hostname: mysql-mgr-1

Subdomain: mgrtest

Containers:

-image: 172.16.110.102:5000/mysql8.0:latest

Name: mysql-mgr-1

ImagePullPolicy: IfNotPresent

Command: ["/ bin/bash", "- ce", "cd / usr/local/mysql & & bin/mysqld_safe-- defaults-file=/etc/my.cnf & & tail-f / dev/null"]

# env:

#-name: MYSQL_ROOT_PASSWORD

# value: noc-mysql

Ports:

-containerPort: 3306

VolumeMounts:

-name: tz-config

MountPath: / etc/localtime

-name: mysql-data

MountPath: / data/mysql/data

-name: mysql-config

MountPath: / etc/my.cnf

SubPath: my.cnf

Env:

-name: INNODB_BUFFER_POOL_SIZE

Value: 500M

Volumes:

-name: tz-config

HostPath:

Path: / etc/localtime

-name: mysql-data

HostPath:

Path: / data/mysql/data/

-name: mysql-config

ConfigMap:

Name: mysql-mgr-1-cnf

Items:

-key: mysql-mgr-1.cnf

Path: my.cnf

-yaml file of the pod of node 3:

ApiVersion: v1

Kind: Pod

Metadata:

Name: mysql-mgr-2

Namespace: mysqldb

Labels:

Name: mysql-mgr

Spec:

Affinity:

NodeAffinity:

RequiredDuringSchedulingIgnoredDuringExecution:

NodeSelectorTerms:

-matchExpressions:

-key: mysqlrole

Operator: In

Values: ["mysql-mgr-2"]

Hostname: mysql-mgr-2

Subdomain: mgrtest

Containers:

-image: 172.16.110.102:5000/mysql8.0:latest

Name: mysql-mgr-2

ImagePullPolicy: IfNotPresent

Command: ["/ bin/bash", "- ce", "cd / usr/local/mysql & & bin/mysqld_safe-- defaults-file=/etc/my.cnf & & tail-f / dev/null"]

# env:

#-name: MYSQL_ROOT_PASSWORD

# value: noc-mysql

Ports:

-containerPort: 3306

VolumeMounts:

-name: tz-config

MountPath: / etc/localtime

-name: mysql-data

MountPath: / data/mysql/data

-name: mysql-config

MountPath: / etc/my.cnf

SubPath: my.cnf

Env:

-name: INNODB_BUFFER_POOL_SIZE

Value: 500M

Volumes:

-name: tz-config

HostPath:

Path: / etc/localtime

-name: mysql-data

HostPath:

Path: / data/mysql/data/

-name: mysql-config

ConfigMap:

Name: mysql-mgr-2-cnf

Items:

-key: mysql-mgr-2.cnf

Path: my.cnf

-yaml file for the service created for the three pod

ApiVersion: v1

Kind: Service

Metadata:

Name: mgrtest

Namespace: mysqldb

Spec:

Selector:

Name: mysql-mgr

ClusterIP: None

Ports:

-name: foo

Port: 3306

TargetPort: 3306

Create namespace,service,configmap,pod

Kubectl create-f namespace.yaml

Kubectl create-f mysql-mgr-svc.yaml

Kubectl create-f mysql-mgr-cnf-0.yaml

Kubectl create-f mysql-mgr-cnf-1.yaml

Kubectl create-f mysql-mgr-cnf-2.yaml

Kubectl create-f mysql-mgr-0-pod.yaml

Kubectl create-f mysql-mgr-1-pod.yaml

Kubectl create-f mysql-mgr-2-pod.yaml

After creation, it is shown in the following figure:

Configure Node 1:

Root@dkm:/app/mgr# kubectl exec-it mysql-mgr-0-n mysqldb / bin/bash

Root@mysql-mgr-0:/# / usr/local/mysql/bin/mysql-uroot-p

Alter user 'root'@'localhost' identified by' Mysql123 thanks thanks

Set sql_log_bin=0

Create user rpl_user@'%' identified by 'Rpl_pass@123'

Grant replication slave on *. * to rpl_user@'%'

Flush privileges

Set sql_log_bin=1

Change master to master_user='rpl_user',master_password='Rpl_pass@123' for channel 'group_replication_recovery'

Install PLUGIN group_replication SONAME 'group_replication.so'

Reset master

Set global group_replication_single_primary_mode=FALSE

Set global group_replication_enforce_update_everywhere_checks=TRUE

Set global group_replication_bootstrap_group=ON

Start group_replication

Set global group_replication_bootstrap_group=OFF

Select * from performance_schema.replication_group_members

Configure Node 2:

Set sql_log_bin=0

Create user rpl_user@'%' identified by 'Rpl_pass@123'

Grant replication slave on *. * to rpl_user@'%'

Flush privileges

Set sql_log_bin=1

Change master to master_user='rpl_user',master_password='Rpl_pass@123' for channel 'group_replication_recovery'

Install PLUGIN group_replication SONAME 'group_replication.so'

Reset master

Set global group_replication_single_primary_mode=FALSE

Set global group_replication_enforce_update_everywhere_checks=TRUE

Set global group_replication_recovery_get_public_key=on

Start group_replication

Select * from performance_schema.replication_group_members

Configure Node 3:

Set sql_log_bin=0

Create user rpl_user@'%' identified by 'Rpl_pass@123'

Grant replication slave on *. * to rpl_user@'%'

Flush privileges

Set sql_log_bin=1

Change master to master_user='rpl_user',master_password='Rpl_pass@123' for channel 'group_replication_recovery'

Install PLUGIN group_replication SONAME 'group_replication.so'

Reset master

Set global group_replication_single_primary_mode=FALSE

Set global group_replication_enforce_update_everywhere_checks=TRUE

Set global group_replication_recovery_get_public_key=on

Start group_replication

Select * from performance_schema.replication_group_members

Summary:

(1) the nodes communicate with each other through the domain name, the composition of the domain name: hostname.service.namespace.svc.cluster.local.

(2) notice that in the configuration file of each node, report_host is configured as the domain name of that node, that is, hostname.service.namespace.svc.cluster.local. Otherwise, an error will be reported:

2019-04-10T09:16:53.607069+08:00 55 [ERROR] [MY-010584] [Repl] Slave I Slave O for channel 'group_replication_recovery': error connecting to master' rpl_user@mysql-mgr-0:3306'-retry-time: 60 retries: 1, Error_code: MY-002005

...

2019-04-10T09:17:53.682099+08:00 24 [ERROR] [MY-011582] [Repl] Plugin group_replication reported: 'There was an error when connecting to the donor server. Please check that group_replication_recovery channel credentials and all MEMBER_HOST column values of performance_schema.replication_group_members table are correct and DNS resolvable.'

That's all for "how to deploy mysql 8.0 MGR on K8s". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report