Linux系统日志

####系统的日志管理###
##日志远程同步##
在日志发送方:
vim /etc/rsyslog.conf

. @172.25.254.100 ##@表示udp协议发送,@@表示tcp协议发送
systemctl restart rsyslog
在日志接收方:
vim /etc/rsyslog.conf
15 $ModLoad imudp ##开启接收模块
16 $UDPServerRun 514 ##开启接收端口
systemctl restart rsyslog ##重启
systemctl stop firewalld ##关闭防火墙
systemctl disable firewalld ##设定防火墙开机不启动
在这里插入图片描述

测试:
在日志发送和接收方都清空日志

/var/log/messages
在日志发送方:
logger test
在发送方和接收方都可以查看到日志:
cat /var/log/messages
在这里插入图片描述
###时间同步服务###
服务名称:
chronyd

###在服务端###
vim /etc/chronyd.conf
22 allow 172.25.254.0/24 ###允许哪些客户端来同步本机时间
29 local stratum 10 ###本机不同布任何主机的时间,本机作为时间源
systemctl restart chronyd

##在客户端##
vim /etc/chroney.conf
server 172.25.254.100 iburst ##本机立即同步100这台主机的时间
systemctl restart chronyd

###测试###
在客户端:
.-- Source mode ‘^’ = server, ‘=’ = peer, ‘#’ = local clock.
/ .- Source state ‘*’ = current synced, ‘+’ = combined , ‘-’ = not combined,
| / ‘?’ = unreachable, ‘x’ = time may be in error, ‘~’ = time too variable.
|| .- xxxx [ yyyy ] +/- zzzz
|| / xxxx = adjusted offset,
|| Log2(Polling interval) -. | yyyy = measured offset,
|| \ | zzzz = estimated error.
|| | |
MS Name/IP address Stratum Poll Reach LastRx Last sample

^* 172.25.254.100 10 6 17 28 +5623ns[ +53us] +/- 895us
*:出现时表示成功
在这里插入图片描述
####timedatectl命令####
timedatectl 管理系统时间
在这里插入图片描述
timedatectl set-time ##设定当前时间
timedatectl set-timezone## 设定当前时区
timedatectl set-local-rtc 0|1 ##设定是否
timedatectl list-timezone ##查看支持的所有时区
例:
timedatectl set-time"2018-11-11 11:11:11"
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

####journal命令####
1.journalctl ##日志查看工具
-n 3 ##查看最近3条日志
-p err ##查看错误日志
-o verbose ## 查看日志的详细参数
–since ##查看从什么时间开始的日志
–until ##查看到什么时间为止的日志
journalctl --since “2018-10-13 12:00” --until “2018-10-13 12:01”
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

2.如何使用systemd-journal保存系统日志
mkdir /var/log/journal
chgrp systemd-journal /var/log/journal
chmod g+s /var/log/journal
ps aux | grep systemd-journal
killall -1 systemd-journald
ls /var/log/journal
946cb0e817ea4adb916183df8c4fc817
在这里插入图片描述
在这里插入图片描述

####日志采集格式的设定####
vim /etc/rsyslog.conf
$template LOGFMT, “%timegenerated% %FROMHOST-IP% %syslogtag% %msg%\n”
%timegenerated% ###显示日志时间
%FROMHOST-IP% ###显示主机ip
%syslogtag% ###日志记录目标
%msg% ###日志内容

####系统日志的管理####
2.rsyslog的管理
/var/log/messages ##服务信息日志
/var/log/secure ##系统登录日志
/var/log/cron ##定时任务日志
/var/log/maillog ##邮件日志
/var/log/boot.log ##系统启动日志
什么类型的日志,什么级别的日志 /var/log/file

##日志类型分为:
auth pam ##产生的日志
authpriv ssh,ftp ##等登录信息的验证信息
cron ##时间人物相关
kern ##内核
lpr ##打印
mail ##邮件
mark(syslog)-rsyslog ##服务内部的信息,时间标识
news ## 新闻组
user ##用户程序产生的相关信息
uucp unix to unix copy,unix ##主机之间相关的通讯
local 1~7 自定义的日志设备

##日志级别分为:
debug 有调式信息的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值