《初入linux》--第九部分-linux的日志管理
来源:互联网 发布:网络审计设备 编辑:程序博客网 时间:2024/05/22 05:12
一.linux日志服务
其配置文件在 /etc/rsyslog.conf
何为日志:顾名思义就是针对自己的工作,每天记录工作的内容、所花费的时间以及在工作过程中遇到的问题,解决问题的思路和方法,
linux系统中,日志是查看工作状态,防患差错于未然的重要服务。
1.日志文件
日志文件为分别有:
1)/var/log/messages //记录系统服务日志
</pre><pre name="code" class="plain">Oct 18 07:07:34 localhost dbus[776]: [system] Activating service name='org.freedesktop.problems' (using servicehelper)Oct 18 07:07:34 localhost dbus-daemon: dbus[776]: [system] Activating service name='org.freedesktop.problems' (using servicehelper)Oct 18 07:07:34 localhost dbus[776]: [system] Successfully activated service 'org.freedesktop.problems'Oct 18 07:07:34 localhost dbus-daemon: dbus[776]: [system] Successfully activated service 'org.freedesktop.problems'Oct 18 07:10:01 localhost systemd: Started Session 9 of user root.Oct 18 07:10:01 localhost systemd: Starting Session 9 of user root.Oct 18 07:10:24 localhost dbus[776]: [system] Activating service name='org.freedesktop.problems' (using servicehelper)
2)/var/log/maillog //记录系统邮件日志
3)/var/log/cron //记录系统定时任务
1)vim /etc/rsyslog.conf
2)*.* @172.25.5.11 配置日志接受方ip,@表示用UDP协议发送
设置完成后可以使用
4)/var/log/boot.log //记录启动信息
2.日志管理服务 rsyslog
rsyslog 负责采集日志和分类
配置文件:vim /etc/rsyslog.conf
在配置文件的rules部分,我们可以对日志文件,采集格式等进行配置
#### RULES ##### Log all kernel messages to the console.# Logging much else clutters up the screen.#kern.* /dev/console# Log anything (except mail) of level info or higher.# Don't log private authentication messages!*.info;mail.none;authpriv.none;cron.none /var/log/messages# The authpriv file has restricted access.authpriv.* /var/log/secure# Log all the mail messages in one place.mail.* -/var/log/maillog# Log cron stuffcron.* /var/log/cron# Everybody gets emergency messages*.emerg :omusrmsg:*
3.日志采集格式设置方法
1)进入 /etc/rsyslog.conf
2)在配置文件的RULES部分上方添加自己需要的格式宏定义
如:$template WESTOS,"%timegenerated% %FROMHOST-IP% %syslogtag% %msg%\n"
$ActionfileDefaultTemplate WESTOS //这表示设置一个名为WESTOS的采集格式
$ActionfileDefaultTemplate WESTOS //这表示设置一个名为WESTOS的采集格式
3)在需要用此格式采集的日志文件后加上 ;<WESTOS
$template WESTOS,"%timegenerated% %FROMHOST-IP% %syslogtag% %msg%\n"$ActionfileDefaultTemplate WESTOS#### RULES ##### Log all kernel messages to the console.# Logging much else clutters up the screen.#kern.* /dev/console# Log anything (except mail) of level info or higher.# Don't log private authentication messages!*.info;mail.none;authpriv.none;cron.none /var/log/messages;<WESTOS# The authpriv file has restricted access.authpriv.* /var/log/secure
4)测试修改是否成功
>/var/log/messages //清空日志文件
logger test message //发送测试信息
二.远程同步日志:
在实际工作环境下,当一台服务器宕机后,最快查出问题的方法,就是实时同步它的日志信息,在同步的服务器上查看日志。
设置方法:
注:在虚拟机的实验环境下必须关闭防火墙服务,否则无法进行数据同步:
关闭方法:systemctl stop firewalld
1.配置日志发送方:
1)vim /etc/rsyslog.conf
2)*.* @172.25.5.11 配置日志接受方ip,@表示用UDP协议发送
2.配置日志接受方:
1)vim /etc/rsyslog.conf
2)在配置文件的udp设置中添加:
$ModLoad imudp
$UDPServerRun 514
# Provides UDP syslog reception$ModLoad imudp //使用udp协议接受$UDPServerRun 514 //开放udp端口514
设置完成后可以使用
>/var/log/messages //发送,接受都要清空日志文件
logger test message //发送测试信息
来测试是否成功 0 0
- 《初入linux》--第九部分-linux的日志管理
- 《初入linux》--第五部分-用户管理
- 《初入linux》--第七部分-文件本地管理和远程管理
- 《初入linux》--第十五部分-linux分区、分区加密 和 lvm逻辑卷管理
- 《初入linux》--第二十部分-Apache服务器的几个实用技巧
- 《初入linux》--第十九部分-DNS服务器的基本搭建
- linux的日志管理
- linux的日志管理
- 《初入linux》--第二部分-系统结构与基本文件管理
- 《初入linux》--第八部分-linux下基本网络配置
- linux服务器的日志管理
- linux中日志的管理
- linux-10 日志的管理
- 《初入linux》--第一部分-基本命令符
- 《初入linux》--第三部分-man命令与输入输出
- 《初入linux》--第六部分-用户与文件权限
- 《初入linux》--第十部分-设备使用与时间同步
- 《初入linux》--第十二部分-ACL用户权限列表权限
- HDU1556 color the ball(树状数组)向下查询,向上统计
- 计算机算法之穷举法
- 《TCP/IP详解:卷一》第1章:概述
- LinearLayout和Relativelayout的右对齐问题
- Sencha Touch 2 官方文档翻译之 Sencha Touch 2应用程序简介
- 《初入linux》--第九部分-linux的日志管理
- linux串口收发程序
- 用Spring MVC搭建REST风格的服务
- Windows核心编程 第十二章 纤程
- 大数据Spark “蘑菇云”行动第62课: 广告点击系统数据库系统DAO实现
- 坚持#第70天~模拟短暂计划二维码完成&&tomcat
- codeforces 732F (桥)
- 常用SharedPreferences工具编写
- C语言代码6(判断两数组有无共同元素)