linux日志管理

linux日志管理,第1张

linux日志管理 日志文件目录

/var/log/

日志分类         系统日志  

            /var/log/messages  

Oct 10 09:04:29 localhost kernel: SELinux:  Initializing.
Oct 10 09:04:29 localhost kernel: Yama: becoming mindful.
Oct 10 09:04:29 localhost kernel: Dentry cache hash table entries: 262144 (order: 9, 2097152 bytes)
Oct 10 09:04:29 localhost kernel: Inode-cache hash table entries: 131072 (order: 8, 1048576 bytes)
Oct 10 09:04:29 localhost kernel: Mount-cache hash table entries: 4096 (order: 3, 32768 bytes)
Oct 10 09:04:29 localhost kernel: Mountpoint-cache hash table entries: 4096 (order: 3, 32768 bytes)

        登录日志 

            /var/log/secure

Oct 16 17:02:49 localhost sshd[54297]: Bad protocol version identification '' from 192.168.0.1 port 28077
Oct 16 17:07:40 localhost gdm-password]: pam_unix(gdm-password:auth): conversation failed
Oct 16 17:07:40 localhost gdm-password]: pam_unix(gdm-password:auth): auth could not identify password for [linux]
Oct 16 17:07:40 localhost gdm-password]: gkr-pam: no password is available for user
Oct 16 17:07:46 localhost unix_chkpwd[54356]: password check failed for user (linux)

        邮件日志

            /var/log/maillog

Oct 10 10:09:39 localhost postfix/postfix-script[1780]: starting the Postfix mail system
Oct 10 10:09:39 localhost postfix/master[1810]: daemon started -- version 2.10.1, configuration /etc/postfix
Oct 16 13:49:48 localhost postfix/postfix-script[1718]: starting the Postfix mail system
Oct 16 13:49:48 localhost postfix/master[1729]: daemon started -- version 2.10.1, configuration /etc/postfix
 

        程序日志  

日志的管理服务         日志配置文件解读

                目录/etc/rsyslog.config

rsyslog configuration file   #日志配置文件

# For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html
# If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html

#### MODULES ####    #模块处理日志的木块程序

# The imjournal module bellow is now used as a message source instead of imuxsock.
$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
$ModLoad imjournal # provides access to the systemd journal
#$ModLoad imklog # reads kernel messages (the same are read from journald)
#$ModLoad immark  # provides --MARK-- message capability

# Provides UDP syslog reception   使用udp协议传输
#$ModLoad imudp
#$UDPServerRun 514

# Provides TCP syslog reception   使用tcp协议传输
#$ModLoad imtcp
#$InputTCPServerRun 514


#### GLOBAL DIRECTIVES ####    全局配置

# Where to place auxiliary files
$WorkDirectory /var/lib/rsyslog

# Use default timestamp format      日志的时间格式
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

# File syncing capability is disabled by default. This feature is usually not required,
# not useful and an extreme performance hit
#$ActionFileEnableSync on

# Include all config files in /etc/rsyslog.d/    只要是/eyc/rsyslog.d/目录下以.conf结尾的文件都可以配置日志
$IncludeConfig /etc/rsyslog.d/*.conf

# Turn off message reception via local log socket;
# local messages are retrieved through imjournal now.
$OmitLocalLogging on

# File to store the position in the journal
$IMJournalStateFile imjournal.state


#### RULES ####     日志的规则

# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.*                                                 /dev/console

# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none;cron.none                /var/log/messages

# The authpriv file has restricted access.
authpriv.*                                              /var/log/secure

# Log all the mail messages in one place.
mail.*                                                  -/var/log/maillog


# Log cron stuff
cron.*                                                  /var/log/cron

# Everybody gets emergency messages
*.emerg                                                 :omusrmsg:*

# Save news errors of level crit and higher in a special file.
uucp,news.crit                                          /var/log/spooler

# Save boot messages also to boot.log
local7.*                                                /var/log/boot.log


# ### begin forwarding rule ###   重定向规则
# The statement between the begin ... end define a SINGLE forwarding
# rule. They belong together, do NOT split them. If you create multiple
# forwarding rules, duplicate the whole block!
# Remote Logging (we use TCP for reliable delivery)
#
# An on-disk queue is created for this action. If the remote host is
# down, messages are spooled to disk and sent when it is up again.
#$ActionQueueFileName fwdRule1 # unique name prefix for spool files
#$ActionQueueMaxDiskSpace 1g   # 1gb space limit (use as much as possible)
#$ActionQueueSaveOnShutdown on # save messages to disk on shutdown
#$ActionQueueType linkedList   # run asynchronously
#$ActionResumeRetryCount -1    # infinite retries if host is down
# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional
#*.* @@remote-host:514
# ### end of the forwarding rule ###     

 

日志级别: debug, info, notice, warning, warn (same as warning), err, error (same as err),
       crit, alert, emerg, panic (same as emerg). 
          从前到后越来越严重   

*.info;mail.none;authpriv.none;cron.none                /var/log/messages

上面的配置的意思是除了邮件服务,登录服务,计划服务外的其他所有info级别以上的日志都存在/var/log/messages文件中

其中'.'前面的表示服务,后面的表示级别,none表示不记录,*表示通配所有服务的info级别以上

mail是邮件服务 ,authpriv是登录服务,cron为计划任务服务

配置日志备份 发送端配置

        vim /etc/rsyslog.conf

        配置发往哪里

        authpriv.* @@192.168.36.5:514    

        把登录服务的所有级别的日志发送至192.168.36.5备份服务器

        关闭selinux

        setenforce 0     关闭selinux

        getenforce         查看selinux的状态

        重启日志服务

        service rsyslog restart

接收端配置         打开tcp接受

        # Provides TCP syslog reception   使用tcp协议传输
        #$ModLoad imtcp
        #$InputTCPServerRun 514

       配置接受地址和储存地址

        :formhost-ip,isequal,"192.168.36.5" /var/log/client/192.168.36.5.log     表示接受192.168.36.5的日志并存在/var/log/client/192.168.36.5.log

        重启日志服务

        service rsyslog restart 

        查看514端口是否开启

        ss -antp|grep 514

                     

        

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/3994669.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-10-22
下一篇 2022-10-22

发表评论

登录后才能评论

评论列表(0条)

保存