Centos7 periodic task log rotation, filtering, and core compression implementations
Example of implementation of Cron script and its invocation script in 1.centos7
[Email protected]cron.d]# pwd
/etc/cron.d
[Email protected]cron.d]# cat syslog
#Run Mysys Activity Accounting tool every minutes
*/5* * * * root/usr/sbin/mysyslog.sh 2>&1 >>/var/log/mysys.log
#0 * * * * ROOT/USR/LIB64/SA/SA1 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. Implementing log rotation and its related scripts
[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
}
Updates to the 3.rsyslog.conf rule
Add support for Ceph-fuse logs:
: Syslogtag,contains, "Ceph-fuse"/var/log/lsd/ceph-fuse.log
Add output to the application that needs to crawl the staging 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. Modify the way the kernel panic to generate the core
1) Enter ulimit-c in terminal if the result is 0, the system does not generate coredumpwhen the program crashes.
2) Use the ulimit-c Unlimited command to turn on the coredump feature and not limit the size of the generated coredump file. If you need a limit, add a numeric limit. ulimit-c 1024x768
3) refer to the following command to achieve core compression:
Modify/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
This article is from the "Store Chef" blog, so be sure to keep this source http://xiamachao.blog.51cto.com/10580956/1882049
Centos 7 Implementation of recurring tasks, log rotation, filtering, and core compression