CentOS8で構築したWebサイトが最近なぜか重く感じるようになりました。
アクセスしても表示されるのが著しく遅いので、サーバーを確認してみるとCPUが高騰し、100%近くで張り付いている状況でした。
今回の問題を解決したのでメモをしておきます。
「CentOS8」systemd+というユーザーがCPU使用率が高騰する問題を解決
事象は以下の状態となりますう。
topコマンドを実行した際、「syytemd+」というユーザーがCPU使用率をほとんど使用している状態となっています。
$ top
top - 21:06:50 up 63 days,  5:04,  1 user,  load average: 1.83, 1.84, 1.92
Tasks: 110 total,   1 running, 109 sleeping,   0 stopped,   0 zombie
%Cpu(s): 97.0 us,  2.0 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.7 hi,  0.3 si,  0.0 st
MiB Mem :    477.5 total,      5.4 free,    375.5 used,     96.6 buff/cache
MiB Swap:   2048.0 total,   1616.5 free,    431.5 used.     88.4 avail Mem
  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
 2622 systemd+  20   0  306068 264112      4 S  94.4  54.0  14568:36 ei74G1
30728 root      20   0  622060  13988      0 S   4.7   2.9 305:10.66 python
 5710 root      20   0   63336   4404   3632 R   0.3   0.9   0:00.01 top
    1 root      20   0   94340  10612   8188 S   0.0   2.2   4:39.94 systemd
    2 root      20   0       0      0      0 S   0.0   0.0   0:00.95 kthreadd
上記で「systemd+」のCPU使用率が頭打ちしているので、以下の対応をしました。
暫定対応
一時的な対応として、systemctlのサービス再起動を実施しました。
このコマンドはサービスに影響がないということもあり、サービス影響に支障なく対応したい場合に使用します。
ちなみに、私のwebサーバーでは一時的に効果はありました。
$ systemctl daemon-reexec
恒久対応
恒久対応は、systemdをアップデートします。
いろいろと調べてみると、systemdのバグがあるようで、アップデートすることで改善されているようです。
以下で、「yum info」コマンドを実施した際の例となります。
$ yum info installed systemd
Failed to set locale, defaulting to C.UTF-8
Modular dependency problem:
 Problem: conflicting requests
  - nothing provides module(perl:5.26) needed by module perl-DBI:1.641:8010020191113222731:16b3ab4d-0.x86_64
Installed Packages
Name         : systemd
Version      : 239
Release      : 18.el8_1.5
Architecture : x86_64
Size         : 16 M
Source       : systemd-239-18.el8_1.5.src.rpm
Repository   : @System
From repo    : BaseOS
Summary      : System and Service Manager
URL          : http://www.freedesktop.org/wiki/Software/systemd
License      : LGPLv2+ and MIT and GPLv2+
Description  : systemd is a system and service manager that runs as PID 1 and starts
             : the rest of the system. It provides aggressive parallelization
             : capabilities, uses socket and D-Bus activation for starting services,
             : offers on-demand starting of daemons, keeps track of processes using
             : Linux control groups, maintains mount and automount points, and
             : implements an elaborate transactional dependency-based service control
             : logic. systemd supports SysV and LSB init scripts and works as a
             : replacement for sysvinit. Other parts of this package are a logging daemon,
             : utilities to control basic system configuration like the hostname,
             : date, locale, maintain a list of logged-in users, system accounts,
             : runtime directories and settings, and daemons to manage simple network
             : configuration, network time synchronization, log forwarding, and name
             : resolution.
systemdをアップデートできそうなので実施します。
$ yum update systemd
最後にOSの再起動もしておきます。
$ shutdown -r now
「systemd」アップデート後に事象改善
「systemd」アップデート後のCPU使用率ですが、以下の通り、CPUの頭打ちはなくなり、Webサーバーの動作も軽くなりました。
top - 00:23:05 up  2:49,  1 user,  load average: 0.08, 0.08, 0.02
Tasks: 122 total,   2 running, 120 sleeping,   0 stopped,   0 zombie
%Cpu(s):  1.3 us,  1.3 sy,  0.0 ni, 97.2 id,  0.0 wa,  0.2 hi,  0.0 si,  0.0 st
MiB Mem :    821.3 total,     95.7 free,    288.2 used,    437.4 buff/cache
MiB Swap:   2048.0 total,   2039.2 free,      8.8 used.    385.8 avail Mem
    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
   5766 root      20   0  277312  43968  12704 S   5.0   5.2   9:00.15 python
   6550 root      20   0   67424   4952   4176 R   0.3   0.6   0:00.06 top
      1 root      20   0  176748  10776   8296 S   0.0   1.3   0:01.44 systemd
      2 root      20   0       0      0      0 S   0.0   0.0   0:00.00 kthreadd
      3 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 rcu_gp
      4 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 rcu_par+
      6 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 kworker+
      8 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 mm_perc+
今回の件とは違いますが、以下参考URLを参考にしました。
https://yomon.hatenablog.com/entry/2017/03/23/103419
systemd+CPU高騰再発
上記を実施しましたが、また再発をしたので以下を実施してみました。
$ vim /etc/systemd/resolved.conf DNSStubListener=no
上記設定後、再起動を実施
$ service systemd-resolved restart
これでいったん様子見してみます。
参考URL:
https://itectec.com/ubuntu/ubuntu-systemd-resolve-high-cpu-usage-after-update-to-17-04/
CentOS8でsystemdでCPUが頭打ちしている方は参考にしてください。

ITエンジニアの開発・検証・学習としてインターネット上で専用のサーバ(VPS)を利用しましょう!
実務経験はVPSで学べます。
			
 をチェック
エンジニア必見! 技術力を伸ばすVPS徹底比較
>>>
をチェック
エンジニア必見! 技術力を伸ばすVPS徹底比較
>>> 
	
コメント