一、rsyslog
此服务是用来采集系统日志的,他不生产日志,只是起到采集作用.
二、rsyslog的管理
/var/log/messages ## 服务信息日志
/var/log/secure ## 系统登陆日志
/var/log/cron ## 定时任务日志
/var/log/maillog ## 邮件日志
/var/log/boot.log ## 系统启动日志
三、日志管理服务
1、指定日志的采集路径
指定日志的采集路径
vim /etc/rsyslog.conf ##主配置文件
服务.日志级别 /存放文件
*.* /var/log/westos
2、日志类型分为:
auth ##pam产生的日志
authpriv ##ssh,ftp等登陆信息的验证信息
cron ##时间任务相关
kern ##内核
lpr ##打印
mail ##邮件
mark(syslog)-rsyslog ##服务内部的信息,时间标识
news ##新闻组
user ##用户程序产生的相关信息
uucp ##unix to unix copy,unix主机之间相关的通讯
local 1~7 ##自定义的日志设备
四、日志的远程同步
1、在日志发送方:
- systemctl stop firewalld ##关闭火墙
- systemctl disable firewalld ##设定火墙开机关闭
- vim /etc/rsyslog.conf
*.*
@172.25.254.128 ##‘@’表示udp协议发送,‘@@’表示tcp协议发送 - systemctl restart rsyslog
2、在日志接收方:
- systemctl stop firewalld ##关闭火墙
- systemctl disable firewalld ##设定火墙开机关闭
- vim /etc/rsyslog.conf
15 $ModLoad imudp ##日志接收模块
16 $UDPServerRun 514 ##开启接收端口
- systemctl restart rsyslog ##重启rsyslog服务
3、测试:
在发送方和接收方都清空日志文件
> /var/log/messages在日志的发送方输入
logger test
五、日志采集格式的设定
在接收方:
vim /etc/rsyslog.conf
$template LOGFMT, "%timegenerated% %FROMHOST-IP% %syslogtag% %msg%\n"
*.* /var/log/westos;LOGFMT
%timegenerated% ##显示日志时间
%FROMHOST-IP% ##显示主机ip
%syslogtag% ##日志记录目标
%msg% ##日志内容
\n ##换行temctl restart rsyslog
cat /var/log/westos
六、时间同步服务
服务名称: chronyd
在服务端:把时间共享出去给别人
- vim /etc/chrony.conf
- systemctl restart chronyd ##重启chronyd服务
- timedatectl set-timezone Asia/Shanghai ##更改当前时区为东8区
在客户端: - vim /etc/chrony.conf
- server 172.25.254.228 iburst ##本机立即同步228主机的时间
- systemctl restart chronyd ##重启chronyd服务
- timedatectl set-timezone Asia/Shanghai ##更改当前时区为东8区
测试:
在客户端:chronyc sources -v
七、timedatectl命令
timedatectl ## 管理系统时间
timedatectl status ## 显示当前时间信息
set-time ## 设定当前时间
set-timezone ## 设定当前时区
set-local-rtc 0|1 ## 设定是否支持UTC时间
list-timezone ## 查看支持的所有时区
八、journal
journalctl ##日志查看工具
journalctl -n 3 ##查看最近3条日志
journalctl -p err ##查看错误日志
journalctl -o verbose ##查看日志的详细参数
journalctl --since ##查看从什么时间开始的日志
journalctl --until ##查看到什么时间为止的日志
如何使用systemd-journald保存系统日志
默认systemd-journald时不保存系统日志到硬盘的
那么关机后再次开机只能看到本次开机之后的日志
上一次关机之前的日志是无法查看的
mkdir /var/log/journal
chgrp systemd-journal /var/log/journal
chmod g+s /var/log/journal
killall -1 systemd-journald
ls /var/log/journal
946cb0e817ea4adb916183df8c4fc817
完事用journal查看