1、top查看
? ? 使用top命令查看系統(tǒng)的狀態(tài),M--按內(nèi)存占用率排序
2、ps查看按內(nèi)存排序的前2個進程
ps auxw|head -1;ps auxw|sort -rn -k4|head -2
[root@VM_42_193_tlinux /var/log]# ps auxw|head -1;ps auxw|sort -rn -k4|head -2
USER? ? ? PID %CPU %MEM? ? VSZ? RSS TTY? ? ? STAT START? TIME COMMAND
root? ? 21049? 0.1 59.5 9664240 9625952 ?? ? Ss? ? 2021 645:18 /usr/lib/systemd/systemd-journald
root? ? ? 4426? 0.0 31.4 5453296 5079852 ?? ? Ssl? 2020 718:59 /usr/sbin/rsyslogd -n
從上面可以看出是systemd-journald和rsyslogd兩個進程最占內(nèi)存。
查看當(dāng)前配置:
*****************rsyslog*****************
[root@VM_17_95_tlinux ~]# cat /usr/lib/systemd/system/rsyslog.service
[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
[Install]
WantedBy=multi-user.target
;Alias=syslog.service
*****************systemd-journald*****************
[root@VM_17_95_tlinux ~]# cat /etc/systemd/journald.conf | grep Storage
#Storage=auto
[root@VM_17_95_tlinux ~]# ll /var/log/journal
ls: cannot access /var/log/journal: No such file or directory
從上面配置可以看出:
1)沒有限制rsyslogd服務(wù)的內(nèi)存使用率。
2)systemd-journald的Storage配置為默認的auto,且沒有journal目錄,這種情況下,表示日志存在內(nèi)存中。
3、rsyslogd優(yōu)化
新增配置到/usr/lib/systemd/system/rsyslog.service的[Service]中,再重啟服務(wù):
[root@VM_17_95_tlinux ~]# cat/usr/lib/systemd/system/rsyslog.service | grep Memory
MemoryAccounting=yes
MemoryMax=80M
MemoryHigh=8M
[root@VM_17_95_tlinux ~]# systemctl daemon-reload
[root@VM_17_95_tlinux ~]# systemctl restart rsyslog
4、systemd-journald優(yōu)化
首先了解Storage配置的各個選項含義:
# man 5 journald.conf
通過查看man手冊,你會發(fā)現(xiàn),Storage=的值可以是volatile、persistent、auto、none,但是,默認的是auto。
volatile代表日志只存在內(nèi)存中,即/run/log/journal/
persistent代表日志只存在磁盤中,即/var/log/journal/
auto代表日志存在磁盤中,或者內(nèi)存中,這個取決于你是否創(chuàng)建/var/log/journal/目錄!!這個也算是一個坑吧,看來大家都需要手動mkdir-p /var/log/journal/,systemctl restart systemd-journald來解放自己的內(nèi)存了!!!
none,表示,日志不保留,全部drop,只有當(dāng)你決定不使用systemd-journald的時候,你可以使用!
Storage=auto,根據(jù)需要,我們把日志改為存在磁盤中,只需要創(chuàng)建目錄/var/log/journal,然后重啟服務(wù)即可:
[root@VM_17_95_tlinux ~]# mkdir -p/var/log/journal/
[root@VM_17_95_tlinux ~]# systemctl restart systemd-journald
5、處理記錄如下: