日志服务器-概念
1、相关概念
日志:历史事件日志
历史事件:
时间,事件
事件级别(日志级别):事件的关键性程度
事件:系统引导启动、应用程序启动、应用程序尤其是服务类应用程序运行过程中的一些事件
系统日志服务:
1 、syslog:
syslogd:system
klogd:kernel
2 、事件格式较为简单时,可统一由syslog进行记录:
事件产生的日期时间 主机 进程[ pid] :事件内容
3 、支持C / S 架构:可通过UDP 或TCP 协议提供日志记录服务;
2、rsyslog 介绍
[ root@neo ~ ] # yum info rsyslog
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors. huaweicloud. com
* extras: mirrors. huaweicloud. com
* updates: mirrors. huaweicloud. com
Installed Packages
Name : rsyslog
Arch : x86_64
Version : 8.24 .0
Release : 41. el7_7
Size : 1.9 M
Repo : installed
From repo : updates
Summary : Enhanced system logging and kernel message trapping daemon
URL : http: / /www.rsyslog.com/
License : ( GPLv3+ and ASL 2.0 )
Description : Rsyslog is an enhanced, multi- threaded syslog daemon. It supports MySQL,
: syslog/ TCP , RFC 3195 , permitted sender lists, filtering on any message part,
: and fine grain output format control. It is compatible with stock sysklogd
: and can be used as a drop- in replacement. Rsyslog is simple to set up, with
: advanced features suitable for enterprise- class , encryption- protected syslog
: relay chains.
[ root@neo ~ ] # rpm - ql rsyslog
/ etc/ rsyslog. conf
... ...
/ usr/ sbin/ rsyslogd
3、Rsyslog 特性
多线程
UDP,TCP,SSL,TLS,RELP
存储日志信息于MySQL、PGSQL、Oracle等数据管理系统
强大的过滤器,实现过滤日志信息中任何部分的内容
自定义输出格式
4、Rsyslog 重要术语
facility:设施,从功能或程序上对日志收集进行分类
auth, authpriv, cron, daemon, kern, lpr, mail, mark, news, security, user, uucp, local0- local7, syslog
priority:优先级,日志级别
debug, info, notice, warn ( warning) , err ( error) , crit ( critical) , alert, emerg ( panic)
指定级别:
* # 所有级别
none # 没有级别
priority # 此级别以高于此级别的所有级别
=priorty # 仅此级别
5、 Rsyslog 程序环境
主程序:rsyslogd
主配置文件:/etc/rsyslog.conf,/etc/rsyslog.d/*.conf
服务脚本(centos6):/etc/rc.d/init.d/rsyslog
Unit File(CentOS 7):/usr/lib/systemd/system/rsyslog.service
6、Rsyslog 配置文件格式(rsyslog.conf)
主要由三部分组成:
MODULES
GLOBAL DRICTIVES
RULES
RULES :
facilty. priority target
target:
文件:记录日志事件于指定的文件中;通常应该位于/ var / log目录下;文件路径之前的"-" 表示异步写入;
用户:将日志事件通知给指定的用户;是通过将信息发送给登录到系统上的用户的终端进行的;
日志服务器:@host,把日志送往指定的服务器主机;
host:即日志服务器地址,监听在tcp或udp协议的514 端口以提供服务;
管道: | COMMAND
rsyslog服务器相关设置:
# Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514
# Provides TCP syslog reception
$ModLoad imtcp
$InputTCPServerRun 514
rsyslog客户端 相关设置:
* . info; mail. none; authpriv. none; cron. none @rsyslog_server_IP
# 具体安装到日志服务器的什么目录下,根据本地 conf 文件的定义路径进行日志保存
7、Rsyslog 相关模块
[ root@Tang- Neo ~ ] # yum list all | grep rsyslog
rsyslog. x86_64 8.24 .0 - 41. el7_7 @updates
pcp- pmda- rsyslog. x86_64 4.3 .2 - 2. el7 base
rsyslog- crypto. x86_64 8.24 .0 - 41. el7_7 updates
rsyslog- doc. noarch 8.24 .0 - 41. el7_7 updates
rsyslog- elasticsearch. x86_64 8.24 .0 - 41. el7_7 updates
rsyslog- gnutls. x86_64 8.24 .0 - 41. el7_7 updates
rsyslog- gssapi. x86_64 8.24 .0 - 41. el7_7 updates
rsyslog- kafka. x86_64 8.24 .0 - 41. el7_7 updates
rsyslog- libdbi. x86_64 8.24 .0 - 41. el7_7 updates
rsyslog- mmaudit. x86_64 8.24 .0 - 41. el7_7 updates
rsyslog- mmjsonparse. x86_64 8.24 .0 - 41. el7_7 updates
rsyslog- mmkubernetes. x86_64 8.24 .0 - 41. el7_7 updates
rsyslog- mmnormalize. x86_64 8.24 .0 - 41. el7_7 updates
rsyslog- mmsnmptrapd. x86_64 8.24 .0 - 41. el7_7 updates
rsyslog- mysql. x86_64 8.24 .0 - 41. el7_7 updates
rsyslog- pgsql. x86_64 8.24 .0 - 41. el7_7 updates
rsyslog- relp. x86_64 8.24 .0 - 41. el7_7 updates
rsyslog- snmp. x86_64 8.24 .0 - 41. el7_7 updates
rsyslog- udpspoof. x86_64 8.24 .0 - 41. el7_7 updates
8、其它日志文件
其它日志文件:
/ var / log/ wtmp:当前系统成功登录系统的日志
需要使用last命令查看
/ var / log/ btmp:当前系统尝试登录系统失败相关的日志
需要使用lastb命令查看
lastlog:显示当前系统上的所有用户最近一次登录系统的时间
/ var / log/ dmesg:系统引导过程中的日志信息
也可以使用dmesg命令进行查看
日志服务器-示例
1、日志服务器设置
[ root@Tang- Neo ~ ] # cat / etc/ rsyslog. conf
#### MODULES ####
# Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514
# Provides TCP syslog reception
$ModLoad imtcp
$InputTCPServerRun 514
[ root@Tang- Neo ~ ] # systemctl restart rsyslog. service # 进行服务重启
[ root@Tang- Neo ~ ] # ss - tunl | grep