在体验腾讯云TKE服务,偶然间进行部署个官方 Docker Hub镜像里的mysql 5.7以上镜像,并配置pvc进行数据持久化存储,将对应挂载点绑定在/var/lib/mysql路径,但无法启动
报错:
[ERROR] --initialize specified but the data directory has files in it. Aborting.
意思对应磁盘目录有文件无法进行初始化,检查对应挂载目录:只有lost+found
lost+found作用:
lost+found目录的文件通常是未链接的文件(名字已经被删除),但是这些文件还被一些进程使用(数据没有删除),在突然关机时(内核panic或者突然断电)出现,这些文件系统会自动删除,当因为软件或者硬件出现错误,导致文件系统不一致,也有可能把有问题的文件放到lost+found目录。
它提供了恢复丢失文件的一种方法:用来存放fsck过程中部分修复的文件的。
既然这个目录是在linux系统每个目录下都有的,那就不应该是磁盘的问题。
查阅文档:
github issue中:https://github.com/docker-library/mysql/issues/69
https://github.com/docker-library/mysql/issues/186
new ext4 disk partition is not usually empty; there is a lost+found directory, which mysql is known to choke on. You could try adding --ignore-db-dir=lost+found to the CMD to know for sure
在看mysql官方文档:https://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_ignore-db-dir
属于mysql 5.7 以上版本特性,如对应初始化的路径不是空目录,会影响mysql初始化。
解决方法:添加参数:--ignore-db-dir=lost+found 在yaml文件中,忽略对应lost+found目录
yaml文件实例:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
description: add --ignore-db-dir=lost+found
creationTimestamp: null
generation: 2
labels:
k8s-app: mysql-0
qcloud-app: mysql-0
name: mysql-0
namespace: cmcc
spec:
replicas: 1
selector:
matchLabels:
k8s-app: mysql-0
qcloud-app: mysql-0
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
k8s-app: mysql-0
qcloud-app: mysql-0
spec:
containers:
- env:
- name: MYSQL_ROOT_PASSWORD
value: "123456"
image: mysql:5.7.28
imagePullPolicy: IfNotPresent
name: mysql-0
args:
- "--ignore-db-dir=lost+found"
resources:
limits:
cpu: 500m
memory: 1Gi
requests:
cpu: 250m
memory: 256Mi
securityContext:
privileged: false
procMount: Default
volumeMounts:
- mountPath: /var/lib/mysql
name: pvc
dnsPolicy: ClusterFirst
imagePullSecrets:
- name: qcloudregistrykey
- name: tencenthubkey
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
volumes:
- name: pvc
persistentVolumeClaim:
claimName: pvc
status: {}
---
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
name: mysql-0
namespace: cmcc
spec:
ports:
- name: tcp-3306-3306
nodePort: 0
port: 3306
protocol: TCP
targetPort: 3306
selector:
k8s-app: mysql-0
qcloud-app: mysql-0
type: ClusterIP
status:
loadBalancer: {}
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。