rsyslog進程佔用cpu和內存

 

起因

在使用寶塔面板升級MySQL到5.7.29版本時,總是不成功。
查看升級過程發現是內存不足導致編譯過程無法完成。在編譯到building cxx object sql/cmakefiles/sql.dir/item_geofunc.cc.o這一步時無法繼續。
查看內存佔用時,發現rsyslogd內存佔用很高。

 

解決方法(限制服務內存使用率)

 

1、修改rsyslogd服務配置文件

nano /usr/lib/systemd/system/rsyslog.service

Service配置中添加MemoryAccounting=yesMemoryMax=80MMemoryHigh=8M三項如下所示。

[Unit]
Description=System Logging Service
;Requires=syslog.socket
Wants=network.target network-online.target
After=network.target network-online.target
Documentation=man:rsyslogd(8)
Documentation=http://www.rsyslog.com/doc/

[Service]
Type=notify
EnvironmentFile=-/etc/sysconfig/rsyslog
ExecStart=/usr/sbin/rsyslogd -n $SYSLOGD_OPTIONS
Restart=on-failure
UMask=0066
StandardOutput=null
Restart=on-failure
MemoryAccounting=yes
MemoryMax=80M
MemoryHigh=8M

[Install]
WantedBy=multi-user.target
;Alias=syslog.service

通常情況下rsyslogd大小隻有5M,所以將內存上限設置爲8M,然後將絕對內存限制爲80M。

 

2、重啓服務

systemctl daemon-reload
systemctl restart rsyslog
 

根本原因

查看rsyslog輸出的日誌/var/log/

路徑描述
/var/log/messages 服務信息日誌(記錄linux操作系統常見的服務信息和錯誤信息)
/var/log/secure 系統的登陸日誌(記錄用戶和工作組的變化情況,是系統安全日誌,用戶的認證登陸情況
/var/log/maillog 郵件日誌
/var/log/cron 定時任務
/var/log/boot.log 系統啓動日誌

發現/var/log/messages有幾個G的日誌。查看日誌內容發現rsyslog把Journal的log都進行的輸出和彙總。
當容器越多是,log也就會也多,內存佔用也就越多。
同時也可能導致systemd-journald內存佔用過高

 

1、修改Journal的配置/etc/systemd/journald.conf

Storage改爲none,如下

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See journald.conf(5) for details.

[Journal]
Storage=none
#Compress=yes
#Seal=yes
#SplitMode=uid
#SyncIntervalSec=5m
#RateLimitInterval=30s
#RateLimitBurst=1000
SystemMaxUse=16M
#SystemKeepFree=
#SystemMaxFileSize=
#RuntimeMaxUse=
#RuntimeKeepFree=
#RuntimeMaxFileSize=
#MaxRetentionSec=
#MaxFileSec=1month
ForwardToSyslog=no
#ForwardToKMsg=no
#ForwardToConsole=no
#ForwardToWall=yes
#TTYPath=/dev/console
#MaxLevelStore=debug
#MaxLevelSyslog=debug
#MaxLevelKMsg=notice
#MaxLevelConsole=info
#MaxLevelWall=emerg
#LineMax=48K
 

2、重啓生效

systemctl restart systemd-journald
 

3、Storage選項擴展

通過查看man手冊,#man 5 journald.conf 你會發現,Storage=的值可以是volatile,persistent, autoandnone,但是,默認的是auto

  • volatile代表日誌只存在內存中,即/run/log/journal/
  • persistent代表日誌只存在磁盤中,即/var/log/journal/
  • auto代表日誌存在磁盤中,或者內存中,這個取決於你是否創建/var/log/journal/目錄!!這個也算是一個坑吧,看來大家都需要手動mkdir -p /var/log/journal/systemctl restart systemd-journald來解放自己的內存了!!!
  • none,表示,日誌不保留,全部drop,只有當你決定不使用systemd-journald的時候,你可以使用!

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章