久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

怎么在k8s上部署mysql 8.0 MGR

135次閱讀
沒有評論

共計 12975 個字符,預計需要花費 33 分鐘才能閱讀完成。

本篇內容介紹了“怎么在 k8s 上部署 mysql 8.0 MGR”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓丸趣 TV 小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!

一。環境概述

  k8s 環境:1 臺 master 節點,3 臺 node 節點。

  在三個節點上搭建 MGR 集群。mysql 的數據文件是掛載在本地存儲,在鏡像制作完成后,需要把初始化后的數據文件 copy 到三個節點本地的掛載點 /data/mysql/data/,另外需要修改 auto.cnf 里面的 uuid,讓三個節點的 uuid 不同。

二。搭建步驟

制作 mysql 8.0.15 鏡像

此步驟略過,參照 mysql 官方的二進制包安裝步驟,
https://dev.mysql.com/doc/refman/8.0/en/binary-installation.html。
  安裝完畢后制作成鏡像。

準備生成三個節點 pod 的相關 yaml 文件。

— 創建 namespace 的文件 namespace.yaml:

apiVersion: v1
kind: Namespace
metadata:
  name: mysqldb

— 節點 1 的 configmap 文件 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/16,172.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

— 節點 2 的 configmap 文件 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/16,172.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

— 節點 3 的 configmap 文件 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/16,172.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

—- 節點 1 的 pod 的 yaml 文件:
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
—- 節點 2 的 pod 的 yaml 文件:

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

— 節點 3 的 pod 的 yaml 文件:

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

— 為三個 pod 創建的 service 的 yaml 文件

apiVersion: v1
kind: Service
metadata:
  name: mgrtest
  namespace: mysqldb
spec:
  selector:
  name: mysql-mgr
  clusterIP:  None
  ports:
  – name:  foo
  port:  3306
  targetPort: 3306

  創建 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

創建后如下圖所示:

  配置節點 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!@#
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;

配置節點 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;

  配置節點 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;

 

總結:

(1)節點之間是通過域名互相通訊,域名的構成: hostname.service.namespace.svc.cluster.local.

(2)注意在每個節點的配置文件里配置 report_host 為該節點的域名,也就是 hostname.service.namespace.svc.cluster.local。否則會報錯:

2019-04-10T09:16:53.607069+08:00 55 [ERROR] [MY-010584] [Repl] Slave I/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.

“怎么在 k8s 上部署 mysql 8.0 MGR”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注丸趣 TV 網站,丸趣 TV 小編將為大家輸出更多高質量的實用文章!

正文完
 
丸趣
版權聲明:本站原創文章,由 丸趣 2023-08-01發表,共計12975字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網絡搜集發布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 新丰县| 蒙阴县| 高碑店市| 沭阳县| 苍溪县| 冕宁县| 牟定县| 柏乡县| 陇西县| 会同县| 德保县| 绍兴县| 台北市| 双桥区| 同江市| 姚安县| 杭锦旗| 恩施市| 社会| 株洲市| 巴塘县| 潞城市| 常山县| 内乡县| 南溪县| 安西县| 玉门市| 瑞丽市| 元朗区| 武川县| 榆社县| 朔州市| 东乡族自治县| 临桂县| 四川省| 勃利县| 兴宁市| 烟台市| 尖扎县| 长岛县| 遂宁市|