首页 > 数据库 >关于在CentOS7的docker容器下启动MySQL5.7.44卡住的问题的解决办法

关于在CentOS7的docker容器下启动MySQL5.7.44卡住的问题的解决办法

时间:2024-04-30 23:13:33浏览次数:20  
标签:systemd service MySQL5.7 mysql CentOS7 mysqld cgroup MySQL docker

最近想在docker中跑一个MySQL5.7版本的服务,而且要基于CentOS,所以着手自己构建镜像。

容器的构建参照下面这篇文章
基于CentOS7镜像容器的MySQL环境构筑 - sxb_sunday - 博客园 (cnblogs.com)

构建完成后,用下面命令启动MySQL服务的时候,启动进程一直卡住没有反应,只能CTRL+C强制停止。

systemctl start mysqld

查看服务状态如下

[root@1a6bce4f17af /]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: activating (start) since Tue 2024-04-30 14:31:10 UTC; 5min ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 250 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 235 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
   CGroup: /docker/1a6bce4f17af7952758dbf3666ac5505500cddd656b37fd134ab13c0a86b7bc1/system.slice/mysqld.service
           └─252 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Apr 30 14:31:10 1a6bce4f17af systemd[1]: Starting MySQL Server...
Apr 30 14:31:11 1a6bce4f17af systemd[1]: New main PID 252 does not belong to service, and PID file is not owned by root. Refusing.
Apr 30 14:31:11 1a6bce4f17af systemd[1]: New main PID 252 does not belong to service, and PID file is not owned by root. Refusing.

New main PID 252 does not belong to service, and PID file is not owned by root. Refusing.

找了很久都是下面这种解决方案

把容器的cgroup目录挂载到宿主机的cgroup目录,如下在启动容器的时候,增加文件卷挂载命令

docker run -itd --name centos-mysql --privileged=true centos:centos7.9.2009 -v /sys/fs/cgroup:/sys/fs/cgroup /usr/sbin/init

cgroup(Control Groups)是 Linux 内核提供的一个功能,用于限制、控制和监视进程的资源使用(如 CPU、内存、磁盘 I/O 等)。cgroup 目录是用于管理这些 cgroup 的文件系统目录,通常挂载在 /sys/fs/cgroup 下。通过在 cgroup 目录中的文件进行读写操作,可以实现对进程组的资源分配、限制和监控。

但这只适用于Linux系统下的docker容器,如果是Windows下,就不存在显式的控制组目录了(Windows下的docker是基于WSL的,一个虚拟Linux内核),那应该怎么办呢?

下面说明一种解决办法,这种方法可以正常启动mysql服务,但对于实际使用有没有影响有待检证。

查看mysql服务单元文件

 

[root@1a6bce4f17af /]# cat /usr/lib/systemd/system/mysqld.service
# Copyright (c) 2015, 2023, Oracle and/or its affiliates.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation.  The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
#
# systemd service file for MySQL forking server
#

[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql

Type=forking

PIDFile=/var/run/mysqld/mysqld.pid

# Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0

# Execute pre and post scripts as root
PermissionsStartOnly=true

# Needed to create system tables
ExecStartPre=/usr/bin/mysqld_pre_systemd

# Start main service
ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS

# Use this to switch malloc implementation
EnvironmentFile=-/etc/sysconfig/mysql

# Sets open_files_limit
LimitNOFILE = 5000

Restart=on-failure

RestartPreventExitStatus=1

PrivateTmp=false
将下面这行注释掉
PIDFile=/var/run/mysqld/mysqld.pid

 保存并重新加载服务单元,再重启mysql服务

[root@1a6bce4f17af /]# systemctl daemon-reload
[root@1a6bce4f17af /]# systemctl restart mysqld
[root@1a6bce4f17af /]# 

再次查看MySQL服务状态,可以看到启动成功

 

标签:systemd,service,MySQL5.7,mysql,CentOS7,mysqld,cgroup,MySQL,docker
From: https://www.cnblogs.com/shixiaobin/p/18168850

相关文章

  • CentOS7 磁盘挂载操作
    我们在使用CentOS7时,一般最好把数据都存放在额外挂载的磁盘上,优点就是防止系统磁盘爆满,以及防止数据丢失。目前使用的Linux操作系统,也绝大部分与CentOS7的操作命令一样,包括一些国产Linux系统。因此本篇博客以CentOS7为例,通过vm虚拟机,介绍如何通过命令操作,挂载一块新......
  • CentOS7上的Mysql8.3允许远程连接
    点击查看代码[root@clone2~]#mysql-uroot-pEnterpassword:WelcometotheMySQLmonitor.Commandsendwith;or\g.YourMySQLconnectionidis9Serverversion:8.3.0MySQLCommunityServer-GPLCopyright(c)2000,2024,Oracleand/oritsaffiliates......
  • docker部署MySQL并且外部连接
    我用的是腾讯云轻量级服务器记得去防火墙开启对应的端口一般是3306docker安装就不说了dockerpullmysql直接拉取最新的版本 dockerrun-p3306:3306--namemymysql-v$PWD/conf:/etc/mysql/conf.d-v$PWD/logs:/logs-v$PWD/data:/var/lib/mysql-eMYSQL_ROOT_......
  • 在 .net core 3.1 的 docker 镜像生成的容器中,连接 sql server 2008 r2 版本的数据库,
    错误1:{"ClassName":"System.Data.SqlClient.SqlException","Message":"Aconnectionwassuccessfullyestablishedwiththeserver,butthenanerroroccurredduringthepre-loginhandshake.(provider:TCPProvider,......
  • CentOS7安装NVIDIA GPU驱动程序和CUDA工具包
      1.查看本地环境检查GPU型号lspci|grep-invidia查看linux系统版本uname-m&&cat/etc/redhat-release禁用nouveaulsmod|grepnouveau#打开如下文件sudovim/usr/lib/modprobe.d/dist-blacklist.conf#写入以下内容blacklistnouveauoptionsnouveaumodes......
  • centos7数据盘挂载/硬盘挂载/磁盘挂载
    挂载命令:1、数据盘挂载命令:用“lsblk”命令看数据盘信息,确定设备文件名如:dev目录下的vdb。2、执行fdisk/dev/vdb,按界面提示依次输入“n”(新建分区)、“p”(新建扩展分区)、“1”(使用第1个主分区),两次回车,输入“w”(保存分区表),完成后分区vdb1创建完成。3、使用命令对新分区......
  • docker入门
    docker的安装安装Docker的步骤取决于您的操作系统。以下是在不同操作系统中安装Docker的简要步骤和示例代码:Ubuntusudoapt-getupdatesudoapt-getinstalldocker-cedocker-ce-clicontainerd.ioDebiansudoapt-getupdatesudoapt-getinstalldocker-cedocker-ce-cl......
  • 使用 docker-compose 部署 oracle19c
    目前应该很少有公司再使用oracle11gR2版本了,官方在2020-12-31日后就停止支持和维护了,绝大多数公司应该都升级到oracle19c版本了。因此当前oracle数据库中使用最多的版本就是oracle19c了,但是官方对其支持和维护的截止日期是2026-3-31。其实即使官方停止技术支持和......
  • 使用 docker 部署 AspNetCore 应用:使用alpine镜像并加入健康检查和瘦身
    前言#使用docker部署AspNetCore应用已经是标配了,之前我一直使用mcr.microsoft.com/dotnet/aspnet:8.0这类镜像,简单粗暴,不过可以使用alpine进一步优化镜像大小。很多开源工具的docker都有健康检查,这次我顺便也给加上了。PS:本文的例子项目来自一个差点被砍掉的项目......
  • docker部署jar包
    1、Dockerfile#构建镜像,执行命令:【dockerbuild-tjdk8:1.0.】FROMopenjdk:8-jdkMAINTAINERraorao#设置时区RUNln-sf/usr/share/zoneinfo/Asia/Shanghai/etc/localtimeRUNecho'Asia/Shanghai'>/etc/timezoneENTRYPOINT["java","-serv......