OpenShift OKD下MySQL持久化部署启动失败求助
搞定OpenShift OKD里MySQL持久化存储启动失败的问题
看了你的日志,核心问题很明确——InnoDB的核心数据文件ibdata1损坏了,头部全是0字节,导致引擎初始化直接崩溃。临时存储能正常运行是因为每次都是全新的文件系统,没有残留问题,权限也都是容器默认配置好的,但持久化存储就容易踩权限或数据残留的坑。
下面给你几个靠谱的解决步骤,按顺序尝试:
第一步:检查并修复存储卷的权限
MySQL容器默认使用mysql用户运行(UID通常是27),如果你的持久化存储卷不是这个用户能读写的,初始化时写入文件就会出问题,最终生成损坏的文件。
操作步骤:
- 先删除当前出问题的PersistentVolumeClaim(PVC)和对应的PersistentVolume(PV)(如果是静态PV的话)
- 重新创建PVC后,启动一个调试容器挂载它修改权限:
oc run debug-pod --image=busybox --command -- sleep 3600 oc rsh debug-pod chown -R 27:27 /var/lib/mysql # 注意:这里的路径要和MySQL容器里的挂载路径完全一致 exit oc delete pod debug-pod - 重新部署MySQL,此时应该能正常初始化数据库。
第二步:清理存储卷里的残留损坏数据
如果之前部署失败后,存储卷里留下了损坏的InnoDB文件(比如ibdata1、ib_logfile*这类核心文件),哪怕权限正确,MySQL启动时读取这些坏文件还是会崩溃。
操作步骤:
- 同样用调试容器挂载PVC:
oc run debug-pod --image=busybox --command -- sleep 3600 oc rsh debug-pod rm -rf /var/lib/mysql/* # 确认路径正确再执行,避免误删其他数据 exit oc delete pod debug-pod - 重新部署MySQL,让它从头初始化数据库。
第三步:检查存储类的兼容性
有些存储类(比如部分NFS存储)可能不支持MySQL需要的文件系统特性(比如直接IO、文件锁),这也会导致InnoDB初始化失败。
操作步骤:
- 查看你当前使用的存储类配置:
oc get storageclass oc describe storageclass <你的存储类名称> - 如果是NFS存储,检查NFS服务器的权限配置,确保支持必要的文件系统特性。如果问题依旧,可以尝试更换存储类(比如本地存储或块存储类型的存储类)。
附:你提供的错误日志
=> sourcing http://20-validate-variables.sh ... => sourcing http://25-validate-replication-variables.sh ... => sourcing http://30-base-config.sh ... ---> 01:27:23 Processing basic MySQL configuration files ... => sourcing http://60-replication-config.sh ... => sourcing http://70-s2i-config.sh ... ---> 01:27:23 Processing additional arbitrary MySQL configuration provided by s2i ... => sourcing 10-mysql57.cnf ... => sourcing 40-paas.cnf ... => sourcing 50-my-tuning.cnf ... ---> 01:27:23 Initializing database ... ---> 01:27:24 Running /opt/rh/rh-mysql57/root/usr/libexec/mysqld --initialize --datadir=/var/lib/mysql/data --ignore-db-dir=lost+found ---> 01:27:24 Starting MySQL server with disabled networking ... ---> 01:27:24 Waiting for MySQL to start ... 2019-03-30T01:27:24.466755Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2019-03-30T01:27:24.584395Z 0 [Note] /opt/rh/rh-mysql57/root/usr/libexec/mysqld (mysqld 5.7.24) starting as process 40 ... 2019-03-30T01:27:24.774993Z 0 [Note] InnoDB: PUNCH HOLE support available 2019-03-30T01:27:24.775057Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2019-03-30T01:27:24.775068Z 0 [Note] InnoDB: Uses event mutexes 2019-03-30T01:27:24.775075Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier 2019-03-30T01:27:24.775761Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.7 2019-03-30T01:27:24.775809Z 0 [Note] InnoDB: Using Linux native AIO 2019-03-30T01:27:24.777416Z 0 [Note] InnoDB: Number of pools: 1 2019-03-30T01:27:24.778012Z 0 [Note] InnoDB: Not using CPU crc32 instructions 2019-03-30T01:27:24.784562Z 0 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M 2019-03-30T01:27:24.841105Z 0 [Note] InnoDB: Completed initialization of buffer pool 2019-03-30T01:27:24.852695Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority(). 2019-03-30T01:27:25.019343Z 0 [ERROR] InnoDB: Header page consists of zero bytes in datafile: ./ibdata1, Space ID:0, Flags: 0. Please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting-datadict.html … for how to resolve the issue. 2019-03-30T01:27:25.019422Z 0 [ERROR] InnoDB: Corrupted page [page id: space=0, page number=0] of datafile './ibdata1' could not be found in the doublewrite buffer. 2019-03-30T01:27:25.019473Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Data structure corruption ---> 01:27:25 Waiting for MySQL to start ... 2019-03-30T01:27:25.520693Z 0 [ERROR] Plugin 'InnoDB' init function returned error. 2019-03-30T01:27:25.520749Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed. 2019-03-30T01:27:25.520763Z 0 [ERROR] Failed to initialize builtin plugins. 2019-03-30T01:27:25.520772Z 0 [ERROR] Aborting 2019-03-30T01:27:25.521120Z 0 [Note] Binlog end 2019-03-30T01:27:25.521862Z 0 [Note] Shutting down plugin 'CSV' 2019-03-30T01:27:25.530469Z 0 [Note] /opt/rh/rh-mysql57/root/usr/libexec/mysqld: Shutdown complete
内容的提问来源于stack exchange,提问作者user1859366
相关产品推荐
相关产品推荐

