从报错来看,大致意思是识别不到PID号99是服务,并且不属于root用户,拒绝使用。
系统 | docker版本 |
CentOS7.6 | 18.09 |
[root@243-ceshi mysql_bakup]# uname -a Linux 243-ceshi 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux [root@243-ceshi mysql_bakup]# docker -v Docker version 18.09.6, build 481bc77156 [root@243-ceshi mysql_bakup]# cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core) [root@243-ceshi mysql_bakup]# docker run -di --privileged=true --name mysql0106 -h vrgv-mysql -p 13306:3306 hub.vrgv.com/devops/mysql:20201109 /usr/sbin/init 8baf1a3adc1af7cf2a7557b6b2c7a4e068c4ba2122709aa3b3d394dc2ac90d01 [root@243-ceshi mysql_bakup]# docker exec -it mysql0106 bash [root@vrgv-mysql /]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.32 MySQL Community Server (GPL) Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> exit Bye [root@vrgv-mysql /]# systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: activating (start) since Wed 2021-01-06 03:05:36 UTC; 1min 27s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 88 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS) Process: 71 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) CGroup: /system.slice/docker-8baf1a3adc1af7cf2a7557b6b2c7a4e068c4ba2122709aa3b3d394dc2ac90d01.scope/system.slice/mysqld.service └─99 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid Jan 06 03:05:36 vrgv-mysql systemd[1]: Starting MySQL Server... Jan 06 03:05:38 vrgv-mysql systemd[1]: New main PID 99 does not belong to service, and PID file is not owned by root. Refusing. Jan 06 03:05:38 vrgv-mysql systemd[1]: New main PID 99 does not belong to service, and PID file is not owned by root. Refusing.
以上信息中,我的容器式可以正常开启的,并且能进入到mysql数据库中,但是服务是暂停的,报
“New main PID 99 does not belong to service, and PID file is not owned by root. Refusing
.”
然后查询资料,查找一个解决办法:
启动容器时,映射cgroup内核限制资源目录,具体原因还未确定
[root@243-ceshi mysql_bakup]# docker run -di --privileged=true --name mysql0106 -h vrgv-mysql -v /sys/fs/cgroup:/sys/fs/cgroup -p 13306:3306 hub.vrgv.com/devops/mysql:20201109 /usr/sbin/init b7548c573fddafbc911918945b7ab3ad412cff1228221f475480ff8e734755c1 [root@243-ceshi mysql_bakup]# docker exec -it mysql0106 bash [root@vrgv-mysql /]# systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: **active (running)** since Wed 2021-01-06 03:18:45 UTC; 11s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 80 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS) Process: 59 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 82 (mysqld) CGroup: /system.slice/docker-b7548c573fddafbc911918945b7ab3ad412cff1228221f475480ff8e734755c1.scope/system.slice/mysqld.service └─82 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid Jan 06 03:18:43 vrgv-mysql systemd[1]: Starting MySQL Server... Jan 06 03:18:45 vrgv-mysql systemd[1]: Started MySQL Server.
启动容器时,添加映射目录参数 -v /sys/fs/cgroup:/sys/fs/cgroup解决此问题。