怎么在k8s上布局mysql 8.0 MGR
发布时间:2022-01-19 13:39:43 所属栏目:MySql教程 来源:互联网
导读:本篇内容介绍了怎么在k8s上部署mysql 8.0 MGR的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成! 一。环境概述 k8s环境:1台master节点,3台node节点。
本篇内容介绍了“怎么在k8s上部署mysql 8.0 MGR”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成! 一。环境概述 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 (编辑:武汉站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |