LoginSignup
0
0

More than 1 year has passed since last update.

(WSL2)Distrodを導入したCentOS7を再起動すると、ApacheとMySQLがエラーで起動しない場合の対応

Posted at

はじめに

CentOS7にDistrodを導入後、再起動するとApacheとMySQLが起動しませんでした。原因と対応方法を記載します。

原因と対策

  • 原因

    • サービスsystemd-tmpfiles-setupの設定ファイルが間違っており、起動時に必要なディレクトリが作成されないことが原因です(Distrodのバグっぽい)
  • 対策

    • 別途、設定を上書きするためにファイルを作成し、そこに記載します
# mkdir /etc/systemd/system/systemd-tmpfiles-setup.service.d
# cat << EOF > /etc/systemd/system/systemd-tmpfiles-setup.service.d/exclude_wslg_sockets.conf
[Service]
ExecStart=systemd-tmpfiles --clean --exclude-prefix=/tmp/.X11-unix
EOF 

調査、対応手順

起動時にエラーとなっていたため、ログファイルでエラーを確認

Apacheのエラー(/var/log/httpd/error_log)

Failed to create shared memory segment on file /run/httpd/authdigest_shm.590

MySQLのエラー(/var/logmysqld.log)

[ERROR] [MY-011300] [Server] Plugin mysqlx reported: 'Setup of socket: '/var/run/mysqld/mysqlx.sock' failed, can't create lock file
  • /var/runに必要なディレクトリが作成されてないためエラーとなっている模様

  • /var/runのファイルシステムはtmpfsのため、再起動毎にクリアされるが、サービスsystemd-tmpfiles-setupにより、apacheやMySQLに必要なディレクトリは作成されるはず
    • 起動時にエラーが発生していたた
$ systemctl status systemd-tmpfiles-setup
● systemd-tmpfiles-setup.service - Create Volatile Files and Directories
Loaded: error (Reason: Invalid argument)
Drop-In: /run/systemd/system/systemd-tmpfiles-setup.service.d
└─exclude_wslg_sockets.conf
Active: inactive (dead)
Docs: man:tmpfiles.d(5)
man:systemd-tmpfiles(8)
  • 'exclude_wslg_sockets.conf`ファイルを開いて内容を確認
    • ExecStart=行が不要と思われる
# This file is part of Distrod.
#
# Do not edit this file directly. This file can be overwritten when Distrod is updated.
# Instead, create /etc/systemd/system/systemd-tmpfiles-clean.service.d/exclude_wslg_sockets.conf,
# systemd will load it.

# avoid `/tmp/.X11-unix` to be cleaned up by systemd
[Service]
ExecStart=
ExecStart=systemd-tmpfiles --clean --exclude-prefix=/tmp/.X11-unix
  • コメントに従い、直接修正するのではなく/etc/systemd/system/systemd-tmpfiles-clean.service.d/exclude_wslg_sockets.confを作成してそこに記載する
# mkdir /etc/systemd/system/systemd-tmpfiles-setup.service.d
# cat << EOF > /etc/systemd/system/systemd-tmpfiles-setup.service.d/exclude_wslg_sockets.conf
[Service]
ExecStart=systemd-tmpfiles --clean --exclude-prefix=/tmp/.X11-unix
EOF 

OS再起動(wsl --shutdown)後、Apacheが起動していることを確認

$ systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2022-08-28 18:08:58 JST; 5min ago
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0