helm安装mysql8.0集群模式

1.安装operator:MysqlCluster

https://github.com/radondb/radondb-mysql-kubernetes.git

复制代码
#设置repo
helm repo add radondb https://radondb.github.io/radondb-mysql-kubernetes/
#拉取operator,可进行修改
helm pull radondb/mysql-operator --version=3.0
#安装operator
helm install demo ../mysql-operator

#已将修改后的operator上传到harbor
helm repo add  gwhelm https://harbor.goldwind.com/chartrepo/helm-repo  --ca-file xx.crt --cert-file xx.crt --key-file xx.key  --username 'xx' --password 'xx'
#下载安装helm
helm pull gwhelm/mysql-cluster
复制代码

 

2.使用operator安装mysql8.0集群

版本信息:https://github.com/radondb/radondb-mysql-kubernetes/releases

创建mysql8集群yaml:   https://github.com/radondb/radondb-mysql-kubernetes/releases/download/v3.0.0/mysql_v1alpha1_mysqlcluster_mysql8.yaml

复制代码
apiVersion: mysql.radondb.com/v1alpha1
kind: MysqlCluster
metadata:
  name: mysql-cluster
spec:
  replicas: 3
  mysqlVersion: "8.0"
  # the backupSecretName specify the secret file name which store S3 information,
  # if you want S3 backup or restore, please create backup_secret.yaml, uncomment below and fill secret name:
  # backupSecretName: 
  
  # if you want create mysqlcluster from S3, uncomment and fill the directory in S3 bucket below:
  # restoreFrom: 
  
  mysqlOpts:
    image: harbor.goldwind.com/library/percona/percona-server:8.0.25
    user: project_user
    password: wHrr*48+M
    database: project_database
    ## tokudb is not supported in mysql8.
    # initTokuDB: false

    # A simple map between string and string.
    # Such as:
    #    mysqlConf:
    #      expire_logs_days: "7"
    mysqlConf: {}

    resources:
      requests:
        cpu: 256m
        memory: 256Mi
      limits:
        cpu: 1000m
        memory: 1Gi

  xenonOpts:
    image: harbor.goldwind.com/library/radondb/xenon:v2.3.0
    admitDefeatHearbeatCount: 5
    electionTimeout: 10000

    resources:
      requests:
        cpu: 50m
        memory: 128Mi
      limits:
        cpu: 100m
        memory: 256Mi

  metricsOpts:
    enabled: false
    image: harbor.goldwind.com/library/prom/mysqld-exporter:v0.12.1

    resources:
      requests:
        cpu: 10m
        memory: 32Mi
      limits:
        cpu: 100m
        memory: 128Mi

  podPolicy:
    imagePullPolicy: IfNotPresent
    sidecarImage: harbor.goldwind.com/library/radondb/mysql80-sidecar:v2.3.0
    busyboxImage: harbor.goldwind.com/library/busybox:1.32

    slowLogTail: false
    auditLogTail: false

    labels: {}
    annotations: {}
    affinity: 
      podAntiAffinity:
        requiredDuringSchedulingIgnoredDuringExecution:
        - labelSelector:
            matchExpressions:
            - key: app.kubernetes.io/name
              operator: In
              values:
              - mysql
          topologyKey: "kubernetes.io/hostname"
    priorityClassName: ""
    tolerations: []
    schedulerName: ""
    # extraResources defines quotas for containers other than mysql or xenon.
    extraResources:
      requests:
        cpu: 10m
        memory: 32Mi
      limits:
        cpu: 100m
        memory: 125Mi

  persistence:
    enabled: true
    accessModes:
    - ReadWriteOnce
    storageClass: "managed-nfs-storage"
    size: 20Gi
复制代码

可以在harbor的右上角的kubectl shell中vim写mysql.yaml文件,然后kubectl apply -f mysql.yaml

常见问题:

1)在创建完成后,由于/var/lib/mysql的权限问题 mysql-cluster-2会重复失败重启,此时需要在backup的容器中授权chown -R mysql /var/lib/mysql 因为在backup中使用的是root权限,而在mysql和xenon容器中是mysql权限,且backup容器先创建,所以/var/lib/mysql会是root权限,而mysql和xenon容器对其无权限

2)mysql-cluster-2会报错

get.client.error[dial tcp 10.244.0.35:8801: connect: connection refused]

goroutine 1 [running]:
xbase/xlog.(*Log).Panic(0xc0002062a0, 0x7f67a6, 0x2, 0xc0000f5d08, 0x1, 0x1)
  /go/src/github.com/radondb/xenon/src/xbase/xlog/xlog.go:164 +0x157

查看mysql-cluster-2的日志kubectl logs --tail=3000 -f pod/mysql-cluster-mysql-0 -n demo 可以看到报错
复制代码
2023-07-21T10:52:47.948569+08:00 0 [ERROR] [MY-010544] [Repl] Failed to open the relay log '/var/lib/mysql/mysql-relay-bin.000002' (relay_log_pos 371).
2023-07-21T10:52:47.949938+08:00 0 [ERROR] [MY-011059] [Repl] Could not find target log file mentioned in relay log info in the index file '/var/lib/mysql/mysql-relay-bin.index' during relay log initialization.
2023-07-21T10:52:47.951793+08:00 0 [ERROR] [MY-010426] [Repl] Slave: Failed to initialize the master info structure for channel ''; its record may still be present in 'mysql.slave_master_info' table, consider deleting it.
2023-07-21T10:52:47.953076+08:00 0 [ERROR] [MY-010529] [Repl] Failed to create or recover replication info repositories.
2023-07-21T10:52:48.116508+08:00 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.25-15'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  Percona Server (GPL), Release 15, Revision a558ec2.
2023-07-21T10:52:49.996244+08:00 8 [System] [MY-010597] [Repl] 'CHANGE MASTER TO FOR CHANNEL '' executed'. Previous state master_host='', master_port= 3306, master_log_file='', master_log_pos= 4, master_bind=''. New state master_host='mysql-cluster-mysql-0.mysql-cluster-mysql.wfs-prod', master_port= 3306, master_log_file='', master_log_pos= 4, master_bind=''.
2023-07-21T10:52:50.013805+08:00 10 [Warning] [MY-010897] [Repl] Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
2023-07-21T10:52:50.017150+08:00 10 [System] [MY-010562] [Repl] Slave I/O thread for channel '': connected to master 'radondb_repl@mysql-cluster-mysql-0.mysql-cluster-mysql.wfs-prod:3306',replication started in log 'FIRST' at position 4
2023-07-21T10:53:03.460369+08:00 10 [ERROR] [MY-010557] [Repl] Error reading packet from server for channel '': Lost connection to MySQL server during query (server_errno=2013)
2023-07-21T10:53:03.460500+08:00 10 [Warning] [MY-010897] [Repl] Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
2023-07-21T10:53:03.462175+08:00 10 [ERROR] [MY-010584] [Repl] Slave I/O for channel '': error reconnecting to master 'radondb_repl@mysql-cluster-mysql-0.mysql-cluster-mysql.wfs-prod:3306' - retry-time: 60 retries: 1 message: Can't connect to MySQL server on 'mysql-cluster-mysql-0.mysql-cluster-mysql.wfs-prod:3306' (111), Error_code: MY-002003
复制代码

有时还会出现没有配置账户密码等报错,删除之前的stateful重新建一个新的,问题就会解决

 

3.创建root密码

此operator只支持创建项目账户及数据库,若要使用管理员权限,可以在rancher中service的leader svc中找到mster pod然后执行root改密码的操作

ALTER USER 'root'@'%' IDENTIFIED BY 'xxxx';

4.创建主从节点:leader和follower的nodeport svc

posted @   潇潇暮鱼鱼  阅读(542)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示