起因
在使用寶塔面板升級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=yes
,MemoryMax=80M
,MemoryHigh=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
, auto
andnone
,但是,默認的是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
的時候,你可以使用!