linux下日志管理系统,Linux系统日志管理

1.rsyslog服务

此服务用来采集系统日至,他不产生日志,只起采集作用

rsyslog的管理

进程和操作内核需要为发生的事记录日志,这些日志一般记录在/var/log下,文件信息记录如下:

var/log/messages #服务信息日志

var/log/secure #系统登陆日志

var/log/cron #定时任务日志

var/log/mail #邮件日志

var/log/boot.log #系统启动日志

bVbeiDE?w=750&h=446

2.日志的远程服务

1.在日志发送方

vim /etc/rsyslog.conf

*.* @172.25.254.200 ##"@"表示utp协议发送,“@@”表示tcp协议发送

systemctl restart rsyslog

2.在日志接受方

vim /etc/rsyslog.conf

15 $ModLoad imudp #日志接收插件

16 $UDPServerRun #开启接收端口

systemctl restart rsyslog

systemctl stop firewalld #关闭火墙

systemctl disable firewalld #设定火墙开机时关闭

测试:

在发送方和接收方都清空日志文件

> /var/log/messages

在日志发送方

logger test

cat /var/log/meaasges #查看日志是否生成

在日志接收方

cat /var/log/messages

bVbeiF8?w=798&h=611

3.日志采集格式设定

vim /etc/rsyslog.conf

$template LOGFMT, "%timegenerated% %FORMHOST-IP% %syslogtag% %msg%\n"

*.* /var/log/westos;LOGFMT

4.时间同步服务

服务名称

chronyd

在服务端:

vim /etc/chrony.conf

22 allow 172.25.254.0/24 #允许17.25.254.xxx来同步本机时间

29 local stratum 10 #本机不同步任何主机的时间,本机作为时间元

systemctl restart chronyd.service

timedatectl set-timezone Asia/Shanghai #更改当前时区为东8区

在客户端:

vim /etc/chrony.conf

3 server 172.25.254.222 iburst #本机立即同步200主机的时间

systemctl restart chronyd.service

timedatectl set-timezone Asia/Shanghai #更改当前时区为东8区

测试:

在客户端

[root@client Desktop]# chronyc sources -v

210 Number of sources = 1

.-- 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.222 10 6 17 49 -60ms[ -60ms] +/- 62ms

bVbeiNE?w=935&h=280

bVbeiNW?w=931&h=592

5.timedatectl命令

timedatectl #管理系统时间

timedatectl status #显示当前时间信息

set-time "年-月-日 时:分:秒" #设定当前时间

set-timezone #设定当前时区

set-local-rtc 0|1 #设定是否使用utc时间

查看 vim /etc/adjtime

list-timezones #查看支持的所有时区

bVbeiQz?w=926&h=555

6.journal

1.日志查看工具

journalctl

-n 3 #查看最近3条日志

-p err #查看错误日志

-o verbose #查看日志的详细参数

--since “时间” #查看从什么时刻开始的日志

--until “时间” #查看到什么时刻为止的日志

bVbeiTM?w=975&h=260

2.使用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

journalctl

bVbeiXV?w=1067&h=564

bVbeiXX?w=1064&h=584

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值