01-日志文件和rsyslog系统

@

1. 常用日志

存放位置 /var/log,该目录下目录如下:

1.1 系统日志

./messages 没有明确指明的日志
./secure 安全日志
./dmesg 系统开机相关日志
./audit/audit.log 审计日志
./yum.log yum日志

1.2 服务日志

如:./mysqld.log./httpd/access_log./httpd/error_log

1.2 二进制日志

二进制文件,只能用命令查看

1.2.1 ./wtmp

  • 作用:查看当前登录用户
  • 查看:
[root@harbor ~]# w
22:25:17 up 39 days, 4:41, 1 user, load average: 0.00, 0.10, 0.11
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 10.10.222.191 22:20 5.00s 0.01s 0.00s w

1.2.2 ./btmp

  • 作用:查看最近登录的用户
  • 查看
[root@harbor ~]# last
root pts/0 10.10.222.191 Thu Jul 1 22:20 still logged in
root pts/1 10.10.222.191 Thu Jul 1 20:14 - 21:50 (01:35)
root pts/1 10.10.213.46 Wed Jun 16 16:14 - 16:16 (00:02)
root pts/1 10.10.222.191 Mon May 31 14:33 - 14:58 (00:24)
root pts/1 10.10.222.191 Sun May 30 21:16 - 21:31 (00:15)

1.2.3 ./last.log

  • 作用:所有用户最后一次登录的情况
  • 查看
[root@harbor ~]# lastlog
用户名 端口 来自 最后登陆时间
root pts/0 10.10.222.191 四 7月 1 22:20:56 +0800 2021
bin **从未登录过**
daemon **从未登录过**
adm **从未登录过**
lp **从未登录过**
sync **从未登录过**

2. rsyslog 系统

2.1 本地日志收集:

配置文件: /etc/rsyslog.conf

infn;mail.none;authpriv.none;cron.none /var/log/messages
*.err;kern.debug;daemon.notice /var/adm/messages
# Thr 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

2.2 远程日志收集

2.2.1 日志服务器操作

  • 打开接收功能
    /etc/rsyslog.cof
#去掉注释,打开tcp协议接收日志功能
$ModLoad imtcp
$InputTCPServerRun 514
#打开UDP协议接收日志功能
$ModLoad imudp
$UDPServerRun 514
  • 重启rsyslog,关闭防火墙。

2.2.2 客户机

  • 定义日志
#一个@表示UDP,@@表示tcp
local7.* @@10.10.239.xxx:514
  • 重启rsyslog,关闭防火墙

  • 测试:客户机产生一条日志的方法

# logger -p local6.info -t "标题" “内容”

posted on   运维开发玄德公  阅读(16)  评论(0编辑  收藏  举报  

相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示