Mysql recurring connection errors
shangdev opened this issue · comments
debug.md 内容:
<details>
<summary>OS Environment Info</summary>
<code>
</code>
<code>Docker version 18.06.1-ce, build e68fc7a</code>
<code>docker-compose version 1.22.0, build f46880fe</code>
</details>
<details>
<summary>Console output</summary>
错误图示:
需求:
可以协助解决一下到底是什么原因导致的吗,,数据库版本我手动切换到了 v5.6.41,这种错误时不时的出现,我不清楚是服务器导致的,还是数据库导致的。
看看MySQL容器是否在运行中。 #599
默认是会自动重启的
-
机器性能没问题?
-
使用 docker container ls -a 查看 mysql 容器运行时间,是否被异常终止。
-
插件问题?
近两天没出现这个问题,我先关闭一下,出现了再打开这个 issue
看一下 mysql 容器的状态。
$ docker container ls -a
机器内存多少。
- 调整一下 PHP 的内存限制。
1核1g的学生机,
内存刚刚够,打开 swap
我觉得是这个问题,你使用的本项目太旧,之前的 PHP 镜像默认不限制内存。
编辑 docker-compose.override.yml
文件
services:
mysql:
restart: "no"
把自动重启禁用了,当再次出现错误时,执行 $docker inspect MYSQL容器ID
,结果贴上来。
不用改,改完之后记得重启。
$ lnmp-docker down
$ lnmp-docker up
问题出现了:
[
{
"Id": "0c486e26e45c276c73a1630164991643d42df7d55002eb00e79de365cd68dbcf",
"Created": "2019-01-10T01:53:07.654743918Z",
"Path": "docker-entrypoint.sh",
"Args": [
"mysqld",
"--character-set-server=utf8mb4",
"--default-authentication-plugin=mysql_native_password"
],
"State": {
"Status": "exited",
"Running": false,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 0,
"ExitCode": 137,
"Error": "",
"StartedAt": "2019-01-10T01:53:08.8226995Z",
"FinishedAt": "2019-01-15T15:56:09.802618948Z"
},
"Image": "sha256:7edb93321b06db3c659d473ade22241b0d2eaa551c8479b9181672456293a0b9",
"ResolvConfPath": "/var/lib/docker/containers/0c486e26e45c276c73a1630164991643d42df7d55002eb00e79de365cd68dbcf/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/0c486e26e45c276c73a1630164991643d42df7d55002eb00e79de365cd68dbcf/hostname",
"HostsPath": "/var/lib/docker/containers/0c486e26e45c276c73a1630164991643d42df7d55002eb00e79de365cd68dbcf/hosts",
"LogPath": "/var/lib/docker/containers/0c486e26e45c276c73a1630164991643d42df7d55002eb00e79de365cd68dbcf/0c486e26e45c276c73a1630164991643d42df7d55002eb00e79de365cd68dbcf-json.log",
"Name": "/lnmp_mysql_1",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": [
"/var/www/lnmp/backup/init:/docker-entrypoint-initdb.d:ro",
"/var/www/lnmp/backup/mysql:/backup:rw",
"/var/www/lnmp/logs/mysql:/var/log/mysql:rw",
"/var/www/lnmp/config/mysql/docker.cnf:/etc/mysql/conf.d/docker.cnf:ro",
"lnmp_mysql-data:/var/lib/mysql:rw"
],
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "lnmp_backend",
"PortBindings": {
"3306/tcp": [
{
"HostIp": "127.0.0.1",
"HostPort": "3306"
}
],
"33060/tcp": [
{
"HostIp": "127.0.0.1",
"HostPort": "33060"
}
]
},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": [],
"CapAdd": null,
"CapDrop": null,
"Dns": null,
"DnsOptions": null,
"DnsSearch": null,
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "shareable",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": null,
"DeviceCgroupRules": null,
"DiskQuota": 0,
"KernelMemory": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": 0,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"Mounts": [
{
"Type": "bind",
"Source": "/var/www/lnmp/secrets/db_root_password.txt",
"Target": "/run/secrets/db_root_password",
"ReadOnly": true
}
],
"MaskedPaths": [
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
],
"ReadonlyPaths": [
"/proc/asound",
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/b1c5e28d809b31f2d78845d2724cd3e0265f3b073c1e5eecc8047cc37a4e53cb-init/diff:/var/lib/docker/overlay2/5f5667f887dcf8f2c1291bd726cb11ca0bdbedd71442806495b1d6f4c979c2aa/diff:/var/lib/docker/overlay2/3355a6c089f5a297ab4f2cb252437821fbf10d406fc36f21f142c8f8c6fc79af/diff:/var/lib/docker/overlay2/59b12cec43b111d6bf0bf6760df4456df3e28d34b0124aa3f1b968e19d734da0/diff:/var/lib/docker/overlay2/8d6ae7041f311fb57b34efdfe7a55c29ab624982097cb55872f57c32b9370b29/diff:/var/lib/docker/overlay2/18e2c5581ebbdac2a47e97330d9f7fcdea1d12e2babbc358e3fb85f4a18bf4b4/diff:/var/lib/docker/overlay2/224a66ca167fa7bd0d57c50c7c7d83164a909b62269826604ea65c9f61537696/diff:/var/lib/docker/overlay2/a537d6ebfa62ae75382629368e1600afe2e49c58564fb1ffe3fb7b27fde745ac/diff:/var/lib/docker/overlay2/fdcd7fb7db08ff3f8b671af04e05b1cd8d9d7981355665711fb2c9422517bf91/diff:/var/lib/docker/overlay2/bd674bcb3cdc726f6fd171e3b35242a8e99de0a947a989316607ade17d7fb8b4/diff:/var/lib/docker/overlay2/0c551ddc9c6ed925643a300db3cb825ad5730124ce3c7213d8047ee392a850d4/diff:/var/lib/docker/overlay2/b130b7f2640bbb986c30507a462abaad67163a1cce244507734d6d4ebc2b1c0b/diff",
"MergedDir": "/var/lib/docker/overlay2/b1c5e28d809b31f2d78845d2724cd3e0265f3b073c1e5eecc8047cc37a4e53cb/merged",
"UpperDir": "/var/lib/docker/overlay2/b1c5e28d809b31f2d78845d2724cd3e0265f3b073c1e5eecc8047cc37a4e53cb/diff",
"WorkDir": "/var/lib/docker/overlay2/b1c5e28d809b31f2d78845d2724cd3e0265f3b073c1e5eecc8047cc37a4e53cb/work"
},
"Name": "overlay2"
},
"Mounts": [
{
"Type": "bind",
"Source": "/var/www/lnmp/backup/init",
"Destination": "/docker-entrypoint-initdb.d",
"Mode": "ro",
"RW": false,
"Propagation": "rprivate"
},
{
"Type": "bind",
"Source": "/var/www/lnmp/backup/mysql",
"Destination": "/backup",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
},
{
"Type": "bind",
"Source": "/var/www/lnmp/logs/mysql",
"Destination": "/var/log/mysql",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
},
{
"Type": "bind",
"Source": "/var/www/lnmp/config/mysql/docker.cnf",
"Destination": "/etc/mysql/conf.d/docker.cnf",
"Mode": "ro",
"RW": false,
"Propagation": "rprivate"
},
{
"Type": "volume",
"Name": "lnmp_mysql-data",
"Source": "/var/lib/docker/volumes/lnmp_mysql-data/_data",
"Destination": "/var/lib/mysql",
"Driver": "local",
"Mode": "rw",
"RW": true,
"Propagation": ""
},
{
"Type": "bind",
"Source": "/var/www/lnmp/secrets/db_root_password.txt",
"Destination": "/run/secrets/db_root_password",
"Mode": "",
"RW": false,
"Propagation": "rprivate"
}
],
"Config": {
"Hostname": "0c486e26e45c",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"3306/tcp": {},
"33060/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"TZ=Asia/Shanghai",
"MYSQL_ROOT_PASSWORD_FILE=/run/secrets/db_root_password",
"MYSQL_DATABASE=test",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"GOSU_VERSION=1.7",
"MYSQL_MAJOR=5.6",
"MYSQL_VERSION=5.6.41-1debian9"
],
"Cmd": [
"mysqld",
"--character-set-server=utf8mb4",
"--default-authentication-plugin=mysql_native_password"
],
"Image": "mysql:5.6.41",
"Volumes": {
"/backup": {},
"/docker-entrypoint-initdb.d": {},
"/etc/mysql/conf.d/docker.cnf": {},
"/var/lib/mysql": {},
"/var/log/mysql": {}
},
"WorkingDir": "",
"Entrypoint": [
"docker-entrypoint.sh"
],
"OnBuild": null,
"Labels": {
"com.docker.compose.config-hash": "ceb659c6bc95a47fb84c4164e99a43df3967a52e36256f51ca7584ccd2f8fdcb",
"com.docker.compose.container-number": "1",
"com.docker.compose.oneoff": "False",
"com.docker.compose.project": "lnmp",
"com.docker.compose.service": "mysql",
"com.docker.compose.version": "1.22.0",
"com.khs1994.lnmp": "true",
"com.khs1994.lnmp.app.env": "development"
}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "8e100d9902c26791f748b0e14fea6fb1b972f55891ab207364ea844a20e3fe2d",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/8e100d9902c2",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"lnmp_backend": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"mysql",
"0c486e26e45c"
],
"NetworkID": "c9c3b8cbd88d64159895e4daa9dd7391644cf7f08a5ad0614c3263625d47c637",
"EndpointID": "",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "",
"DriverOpts": null
}
}
}
}
]
"OOMKilled": false
可以看出不是内存不足的问题,MySQL 日志贴一下 log/mysql
。
2019-01-10 09:53:09 1 [Note] Plugin 'FEDERATED' is disabled.
2019-01-10 09:53:09 1 [Note] InnoDB: Using atomics to ref count buffer pool pages
2019-01-10 09:53:09 1 [Note] InnoDB: The InnoDB memory heap is disabled
2019-01-10 09:53:09 1 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-01-10 09:53:09 1 [Note] InnoDB: Memory barrier is not used
2019-01-10 09:53:09 1 [Note] InnoDB: Compressed tables use zlib 1.2.3
2019-01-10 09:53:09 1 [Note] InnoDB: Using Linux native AIO
2019-01-10 09:53:09 1 [Note] InnoDB: Using CPU crc32 instructions
2019-01-10 09:53:09 1 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2019-01-10 09:53:10 1 [Note] InnoDB: Completed initialization of buffer pool
2019-01-10 09:53:10 1 [Note] InnoDB: Highest supported file format is Barracuda.
2019-01-10 09:53:10 1 [Note] InnoDB: 128 rollback segment(s) are active.
2019-01-10 09:53:10 1 [Note] InnoDB: Waiting for purge to start
2019-01-10 09:53:10 1 [Note] InnoDB: 5.6.41 started; log sequence number 821507901
2019-01-10 09:53:10 1 [Note] Server hostname (bind-address): '*'; port: 3306
2019-01-10 09:53:10 1 [Note] IPv6 is available.
2019-01-10 09:53:10 1 [Note] - '::' resolves to '::';
2019-01-10 09:53:10 1 [Note] Server socket created on IP: '::'.
2019-01-10 09:53:10 1 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2019-01-10 09:53:10 1 [Warning] 'proxies_priv' entry '@ root@xxxxxxxxx' ignored in --skip-name-resolve mode.
2019-01-10 09:53:10 1 [Note] Event Scheduler: Loaded 0 events
2019-01-10 09:53:10 1 [Note] mysqld: ready for connections.
Version: '5.6.41-log' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL
这个是最近的日志,
phpmyadmin/docker#23 (comment)
这个评论你觉得和我的情况有没有关联、、、
现在问题是不清楚mysql容器停止运行的原因,mysql down掉了,肯定连接不上。你增加虚拟内存 swap 了吗