linux日志管理

  1. rsyslog:
    此服务是用来采集系统日志的,它不生产日志,指示起采集的作用。

  2. rsyslog的管理:
    /var/log/messages
    ###服务信息日志###
    /var/log/secure
    ###系统登录日志###
    /var/log/cron
    ###定时服务日志###
    /var/loog/millog
    ###邮件日志###
    /var/log/boot.log
    ###系统启动日志###

在这里插入图片描述

  1. 日志管理服务:
    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
###自定义的日志设备###
从上到下,级别从高到底,记录的信息越来越少,详细可以查看手册:man 3 syslog

  1. 日志的远程同步:
    1)在日志发送方:
    systemctl stop firewalld
    ###关闭火墙###
    systemctl disable firewalld
    ###设定火墙开机关闭###
    vim /etc/rsyslog.conf
    ###* . *
    @
    ###udp协议发送###
    @@
    ###tcp协议发送###
    systemctl restart rsyslog
    在这里插入图片描述
    在这里插入图片描述
    2 )在日志接收方:
    vim /etc/rsyslog.conf
    MODLOAD
    ###日志接收模块###
    UDPSeverRun514
    ###开启接受端口###
    systemctl stop firewalld
    ##关闭火墙
    systemctl disable firewall
    ##设定火墙开机关闭
    在这里插入图片描述
    在这里插入图片描述
    3 )测试
    在发送方和接受方都清空日志文件 > /var/log/messages. 日志发送方: logger test
    cat /var/log/messages ##查看文件已经生成
    日志接收方查看文件是否生成
    在这里插入图片描述

  2. 日志采集格式设定:
    vim /etc/rsyslog.conf
    systemctl restart rsyslog
    %timegenerated%
    ###显示日志时间###
    %FROMHOST-IP%
    ###显示主机ip###
    %syslogtag%
    ###日志记录目标###
    %msg%
    ###日志内容###
    \n
    ###换行###

cat /etc/log/westos

  1. 时间同步服务:
    服务名称:
    chronyd
    在服务端:
    vim /etc/chrony.conf
    #Allow NTP client access from local network.
    allow 172.25.254.50/24 ##允许那些客户端来同步本机时间
    #Listen for commands only on localhost.
    bindcmdaddress 127.0.0.1
    bindcmdaddress ::1
    #Serve time even if not synchronized to any NTP server.
    local stratum 10 ##本机不同步任何主机的时间,本机作为时间源
    systemctl stop firewalld 关闭火墙
    systemctl disable firewalld 设定火墙开机关闭
    systemctl restart chronyd 重启服务
    在客户端:
    vim /etc/chrony.conf
    sysserver 172.25.254.150 iburst ##本机立即同步150主机时间
    temctl restart chronyd
    systemctl stop firewalld
    systemctl disable firewalld
    测试:
    chronyc sources -v
    在这里插入图片描述

  2. timedatectl命令:
    timedatectl
    ###管理系统时间###
    timedatectl status
    ###显示当前时间信息###
    set-time
    ###设定当前时间###
    set-timezone
    ###设定当前时区###
    set-local-rtc 0|1
    ###设定UTC时间###
    list-timezone
    ###查看支持的所有时区###

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

  4. 如何使用systemd-journald保存日志:
    默认systemd-journald是不保存系统日志到硬盘的
    那么关机后再次开机只能看到本次开机之后的日志
    上次关机之前的日志是无法查看的
    mkdir /var/log/journal
    chgrp systemd-journal /var/log/journal
    chmod g+s /var/log/journal
    killall -l systemd-journald
    journalctl
    ls /var/log/journal
    946cb0e817ea4adb916183df8c4fc817

之后用journal查看。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值