zoukankan      html  css  js  c++  java
  • k8s 运行 mysql 报错 initialize specified but the data directory has files in it

    最近在 k8s 上面运行 mysql 报错

    $ kubectl -n devops logs mysql-679745f64f-4cdzc 
    2021-12-10 01:18:26+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.36-1debian10 started.
    2021-12-10 01:18:26+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
    2021-12-10 01:18:26+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.36-1debian10 started.
    2021-12-10 01:18:26+00:00 [Note] [Entrypoint]: Initializing database files
    2021-12-10T01:18:26.354668Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2021-12-10T01:18:26.355814Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
    2021-12-10T01:18:26.355851Z 0 [ERROR] Aborting
    

    提示数据目录非空,什么鬼,好吧,我们先运行一个 initContainers 看看目录里面到底有啥

          initContainers:
          - name: init-data-path
            image: hub.leffss.com/library/busybox:v1.28.4
            imagePullPolicy: IfNotPresent
            command: ["sh", "-c", "ls -l /var/lib/mysql"]
            securityContext:
              privileged: true
            volumeMounts:
            - name: mysql-pvc
              mountPath: /var/lib/mysql
    
    # 查看 initContainers 的日志
    kubectl -n devops logs mysql-679745f64f-4cdzc -c init-data-path
    total 16
    drwx------    2 root     root         16384 Dec 10 01:18 lost+found
    

    原来是 lost+found,这个目录啥东西,有啥用这里就不介绍了,自己百度,反正以我工作这么多年的经验来说,没啥用

    为啥会有这个目录呢?因为我们 pvc 使用的是 ceph 的 rbd,每次创建时都会格式化,就会产生这个,如果使用 cephfs 或者 nfs 的话,不会有这个目录

    好吧,既然没用,那就盘它:

          initContainers:
          - name: init-data-path
            image: hub.leffss.com/library/busybox:v1.28.4
            imagePullPolicy: IfNotPresent
            command: ["sh", "-c"]
            args:
            - |
              if [[ -d /var/lib/mysql/lost+found ]];then
                echo "rm -rf /var/lib/mysql/lost+found"
                rm -rf /var/lib/mysql/lost+found
              else
                echo "/var/lib/mysql/lost+found not exist"
              fi
            securityContext:
              privileged: true
            volumeMounts:
            - name: mysql-pvc
              mountPath: /var/lib/mysql
    

    删除,整个世界清净了!

    $ kubectl -n devops get pod
    NAME                     READY   STATUS    RESTARTS   AGE
    mysql-774868b794-8d258   1/1     Running   0          13m
    redis-7b4c48fd74-g99zg   1/1     Running   0          32m
    
  • 相关阅读:
    Visual Studio一直弹出“未将对象引用设置到对象的实例”对话框的处理
    C#如何将十六进制数字符串转byte[]?
    steam游戏存档迁移
    Java实现行列式计算
    Python中单引号、双引号、三引号的区别
    git基本使用方法
    windows(hexo)使用git时出现:warning: LF will be replaced by CRLF
    steam相关插件
    linux的后台运行相关命令
    Ubuntu下启动/重启/停止apache服务器
  • 原文地址:https://www.cnblogs.com/leffss/p/15670341.html
Copyright © 2011-2022 走看看