如何修复mysql错误日志中的“mbind:不允许操作”

gam*_*ual 57 nginx docker mysql-8.0 ubuntu-18.04

我的 MySQL 错误日志有问题,目前主要由“mbind:不允许操作”行组成(见下文)。为什么会发生,我该如何解决?

这是困扰我的“主要”部分。正如您在下面看到的,并非所有行都是“mbind:不允许操作”。我怀疑 MySQL 查询错误应该是而不是那行,但由于某种原因它们不能写入文件。

MySQL 本身是一个 Docker 容器,其中的日志文件通过以下方式进行处理:

volumes:
- ./mysql/log:/var/log/mysql
Run Code Online (Sandbox Code Playgroud)

有趣的是:

  • “docker logs mysql_container”什么也没显示...
  • 驻留在同一个卷文件夹中的slow.log 完全没问题,并且里面有真正的慢日志行,没有任何“mbind:不允许操作”!
  • 与slow.log 转到general.log 相同——这里也没有问题

有任何想法吗?先感谢您。

2019-04-07T12:56:22.478504Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2019-04-07T12:56:22.478533Z 0 [Warning] [MY-011068] [Server] The syntax 'expire-logs-days' is deprecated and will be removed in a future release. Please use binlog_expire_logs_seconds instead.
2019-04-07T12:56:22.478605Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.15) starting as process 1
2019-04-07T12:56:22.480115Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2019-04-07T12:56:22.480122Z 0 [Warning] [MY-013244] [Server] --collation-server: 'utf8_general_ci' is a collation of the deprecated character set UTF8MB3. Please consider using UTF8MB4 with an appropriate collation instead.
mbind: Operation not permitted
mbind: Operation not permitted
mbind: Operation not permitted
mbind: Operation not permitted
mbind: Operation not permitted
mbind: Operation not permitted
mbind: Operation not permitted
mbind: Operation not permitted
mbind: Operation not permitted
mbind: Operation not permitted
mbind: Operation not permitted
mbind: Operation not permitted
mbind: Operation not permitted
mbind: Operation not permitted
mbind: Operation not permitted
mbind: Operation not permitted
mbind: Operation not permitted
mbind: Operation not permitted
[same line goes forever]
Run Code Online (Sandbox Code Playgroud)

PS MySQL 启动并运行良好,没有问题。正是这个 error.log 一直困扰着我并阻止我看到实际的错误。

Lau*_*lin 85

将功能添加CAP_SYS_NICE到您的容器,直到 MySQL 服务器可以“静默”处理错误。

service:
  mysql:
    image: mysql:8.0.15
    # ...
    cap_add:
      - SYS_NICE  # CAP_SYS_NICE
Run Code Online (Sandbox Code Playgroud)

如果你没有docker-compose,那么你可以定义CAP_SYS_NICE通过

docker run --cap-add=sys_nice -d mysql
Run Code Online (Sandbox Code Playgroud)

参考:

  • 如果没有启用 CAP_SYS_NICE,MySQL 将无法处理线程优先级,我猜你会失去 MySQL 8 引入的新功能(我相信资源组 https://dev.mysql.com/doc/refman/8.0/ en/resource-groups.html)。MySQL 应该在启动期间警告我们*一次*。相反(不确定现在是否仍然如此),它会用此消息填充磁盘。 (7认同)
  • 如果您使用 Docker Stack/Swarm,则不支持 `cap_add`/`security_opt` (https://github.com/moby/moby/issues/25885)。 (5认同)
  • 一般来说,当一个进程被允许改变其优先级或友好性时,它可以将自己设置为超高优先级,并且比所有其他进程更频繁地在 CPU 上进行调度。因此,是的,当优先级/友善度选择不当时,该进程可能会导致主机上的其他进程挨饿。但到目前为止我在MySQL上还没有遇到过这样的问题。也许我没有使用需要这个的功能? (4认同)
  • 为什么会发生这种情况?我过去使用 mysql 没有出现问题,而且解决方案似乎不安全,是 docker mysql image v8 的具体问题吗?以后会有更好的解决方案吗?这是一个快速修复吗? (4认同)
  • 有人知道这个解决方案有什么问题吗?这会导致硬件设备(而不是容器)完全挂起/崩溃吗?我可以看到这允许MySQL从https://unix.stackexchange.com/questions/455084/giving-users-scheduling-privileges挂起系统 (2认同)
  • 所以我使用 MySQL 8.0 并且错误消息仍然存在...此解决方案仅适用于 5.7 吗?有人知道另一个 CAP 是否可以解决这个问题吗? (2认同)

gam*_*ual 8

security_opt在 docker-compose.yml 中添加选项有助于解决这个问题:

database:
  image: mysql:latest
  container_name: mysql_0
  ports:
    - "3306:3306"
  security_opt:
    - seccomp:unconfined
Run Code Online (Sandbox Code Playgroud)

  • 我会避免完全禁用安全配置文件并添加最低限度的额外权限 (7认同)
  • 添加最低限度的额外权利是什么样子@LaurentGosselin (2认同)