標籤:centos7 log core
Centos7週期性任務日誌rotation、過濾和core壓縮的實現
1.centos7中cron指令碼及其呼叫指令碼的實現樣本
[[email protected]cron.d]# pwd
/etc/cron.d
[[email protected]cron.d]# cat syslog
#Run mysys activity accounting tool every 10 minutes
*/5* * * * root /usr/sbin/mysyslog.sh 2>&1 >>/var/log/mysys.log
#0 * * * * root /usr/lib64/sa/sa1 600 6 &
#Generate a daily summary of process accounting at 23:53
*/5* * * * root /usr/sbin/ipmilog.sh
#5323 * * * root /usr/lib64/sa/sa2 -A
2. 實現日誌rotation及其相關指令碼
[[email protected]logrotate.d]# pwd
/etc/logrotate.d
[[email protected]logrotate.d]# cat selmon
/var/log/ipmi.log{
weekly
copytruncate
compress
missingok
notifempty
rotate200
}
[[email protected]logrotate.d]# cat mysysmon
/var/log/mysys.log{
#weekly
daily
copytruncate
compress
dateext
create644 root root
missingok
notifempty
rotate10
}
[[email protected]logrotate.d]# cat smhmon
/var/sysdbase/eventlog.txt/var/sysdbase/eventlog {
weekly
copytruncate
ccompress
dateext
create644 root root
missingok
notifempty
rotate198
}
3.rsyslog.conf規則的更新
添加對ceph-fuse日誌的支援:
:syslogtag,contains, "ceph-fuse" /var/log/lsd/ceph-fuse.log
添加對需要抓取分級日誌的應用程式的輸出:
#:syslogtag, contains, "gluser-fire" /var/log/log.txt
#action(type="omfile"file="/var/log/log.txt")
if$programname == ‘gluser-fire‘ then {
if$msg contains ‘in print level 0‘ then
action(type="omfile"file="/var/log/log-level0.txt")
if$msg contains ‘in print level 1‘ then
action(type="omfile"file="/var/log/log-level1.txt")
if$msg contains ‘in print level 2‘ then
action(type="omfile"file="/var/log/log-level2.txt")
if$msg contains ‘in print level 3‘ then
action(type="omfile"file="/var/log/log-level3.txt")
if$msg contains ‘in print level 4‘ then
action(type="omfile"file="/var/log/log-level4.txt")
if$msg contains ‘in print level 5‘ then
action(type="omfile"file="/var/log/log-level5.txt")
if$msg contains ‘in print level 6‘ then
action(type="omfile"file="/var/log/log-level6.txt")
if$msg contains ‘in print level 7‘ then
action(type="omfile"file="/var/log/log-level7.txt")
}
4.修改核心panic產生core的方式
1)在終端中輸入ulimit-c 如果結果為0,說明當程式崩潰時,系統並不能產生coredump。
2)使用ulimit-c unlimited命令,開啟coredump功能,並且不限制產生coredump檔案的大小。如果需要限制,加數字限制即可。ulimit- c 1024
3)參考下面的命令實現core 壓縮:
修改/proc/sys/kernel/core_pattern:
[[email protected]~]# cat /usr/sbin/core_compresser
#!/bin/bash
execgzip - > /var/core/app/core-$1-$2-$3.gz
#!/bin/bash
execgzip - > /var/core/app/core-$1-$2-$3.gz
[[email protected]~]# cat /proc/sys/kernel/core_pattern
/var/core/app/core-%e-%p-%t
[[email protected]~]# echo "|/usr/sbin/core_compresser %e %p %t" >/proc/sys/kernel/core_pattern
[[email protected]~]# cat /proc/sys/kernel/core_pattern
|/usr/sbin/core_compresser%e %p %t
本文出自 “儲存之廚” 部落格,請務必保留此出處http://xiamachao.blog.51cto.com/10580956/1882049
Centos 7週期性任務、日誌rotation、過濾和core壓縮的實現