linux测试环境打日志,Linux中日志采集以及格式定义

三、systemd-journald的日志

1..systemd-journald可移植性高,资源消耗少、结构简单、可扩展、安全性高等优点。

2.安全性之所以高是因为此程序只负责对日志进行查看而不能对日志进行保存和采集,那么关机后再开机(重启),只能查看到开机后的日志,因为系统之前的日志是保存在内存中的,所以关机后就被清空了,那么再开机时用journalctl是看不到的之前的日志信息的。

journalctl命令

格式: journalctl + 参数 #日志的查看

具体参数的含义:

-p err #查看报错日志

-f #监控 (用户ctrl+c结束监控)

-n 3 #最新(new)的三条日志

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

_PID=*** #直接查看PID为**的程序产生的日志

--since 时间点 --until 时间点 #查看从何时到何时的日志

3.命令练习

[root@node1 Desktop]# journalctl -n 3

-- Logs begin at Tue 2018-10-16 08:51:42 EDT, end at Tue 2018-10-16 11:05:45 EDT

Oct 16 11:05:42 node1 rc.local[1347]: /etc/rc.d/rc.local: line 18: /dev/tcp/cont

Oct 16 11:05:45 node1 rc.local[1347]: /etc/rc.d/rc.local: connect: No route to h

Oct 16 11:05:45 node1 rc.local[1347]: /etc/rc.d/rc.local: line 18: /dev/tcp/cont

ff9d7af727f38f53752b704030edcb30.png

[root@node1 Desktop]# journalctl -p err

-- Logs begin at Tue 2018-10-16 08:51:42 EDT, end at Tue 2018-10-16 11:08:36 ED

Oct 16 08:51:42 localhost kernel: Detected CPU family 6 model 61

Oct 16 08:51:42 localhost kernel: Warning: Intel CPU model - this hardware has

Oct 16 08:51:43 localhost rpcbind[196]: rpcbind terminating on signal. Restart

Oct 16 08:51:46 node1 smartd[617]: Problem creating device name scan list

Oct 16 08:51:46 node1 smartd[617]: In the system's table of devices NO devices

Oct 16 08:51:49 node1 rpcbind[1341]: Cannot open '/var/lib/rpcbind/rpcbind.xdr'

Oct 16 08:51:49 node1 rpcbind[1341]: Cannot open '/var/lib/rpcbind/portmap.xdr'

Oct 16 08:51:49 node1 systemd[1]: Failed to start LSB: Starts the Spacewalk Dae

Oct 16 08:52:09 node1 libvirtd[1345]: libvirt version: 1.1.1, package: 29.el7 (

Oct 16 08:52:09 node1 libvirtd[1345]: Module /usr/lib64/libvirt/connection-driv

3ae9e4319007818f802045c6ff629232.png

[root@node1 Desktop]# journalctl _PID=5535

-- Logs begin at Tue 2018-10-16 08:51:42 EDT, end at Tue 2018-10-16 11:15:58 ED

b9e68a3c019299c26a75cbd11080d108.png

[root@node1 Desktop]# journalctl --since 11:00 --until 11:01

-- Logs begin at Tue 2018-10-16 08:51:42 EDT, end at Tue 2018-10-16 11:19:31 ED

Oct 16 11:00:00 node1 rc.local[1347]: /etc/rc.d/rc.local: connect: No route to

Oct 16 11:00:00 node1 rc.local[1347]: /etc/rc.d/rc.local: line 18: /dev/tcp/con

Oct 16 11:00:01 node1 systemd[1]: Starting Session 16 of user root.

Oct 16 11:00:01 node1 systemd[1]: Started Session 16 of user root.

Oct 16 11:00:01 node1 CROND[5151]: (root) CMD (/usr/lib64/sa/sa1 1 1)

Oct 16 11:00:03 node1 rc.local[1347]: /etc/rc.d/rc.local: connect: No route to

Oct 16 11:00:03 node1 rc.local[1347]: /etc/rc.d/rc.local: line 18: /dev/tcp/con

Oct 16 11:00:09 node1 rc.local[1347]: /etc/rc.d/rc.local: connect: No route to

Oct 16 11:00:09 node1 rc.local[1347]: /etc/rc.d/rc.local: line 18: /dev/tcp/con

Oct 16 11:00:12 node1 rc.local[1347]: /etc/rc.d/rc.local: connect: No route to

Oct 16 11:00:12 node1 rc.local[1347]: /etc/rc.d/rc.local: line 18: /dev/tcp/con

Oct 16 11:00:18 node1 rc.local[1347]: /etc/rc.d/rc.local: connect: No route to

Oct 16 11:00:18 node1 rc.local[1347]: /etc/rc.d/rc.local: line 18: /dev/tcp/con

Oct 16 11:00:21 node1 rc.local[1347]: /etc/rc.d/rc.local: connect: No route to

Oct 16 11:00:21 node1 rc.local[1347]: /etc/rc.d/rc.local: line 18: /dev/tcp/con

Oct 16 11:00:27 node1 rc.local[1347]: /etc/rc.d/rc.local: connect: No route to

Oct 16 11:00:27 node1 rc.local[1347]: /etc/rc.d/rc.local: line 18: /dev/tcp/con

08db9d23e96f7712fda077741f3dfae9.png

4.让systemd-journald将日志保存到硬盘中,也就是说即使系统重启,仍然可以查看到系统重启之前的日志信息

[root@node1 Desktop]# mkdir /var/log/journal

[root@node1 Desktop]# ll -d /var/log/journal/

drwxr-xr-x. 2 root root 6 Oct 16 11:30 /var/log/journal/

[root@node1 Desktop]# chgrp systemd-journal /var/log/journal ##更改目录的所有组

##/var/log/journal/中的日志信息只能被systemd-journal组所识别

[root@node1 Desktop]# ll -d /var/log/journal/

drwxr-xr-x. 2 root systemd-journal 6 Oct 16 11:30 /var/log/journal/

[root@node1 Desktop]# chmod g+s /var/log/journal

##使在/var/log/journal目录中出现的文件的所有组自动归属于该目录的所有组

[root@node1 Desktop]# ll -d /var/log/journal/

drwxr-sr-x. 2 root systemd-journal 6 Oct 16 11:30 /var/log/journal/

[root@node1 Desktop]# ps aux | grep systemd-journald

root 409 0.0 0.2 42992 4692 ? Ss 08:51 0:01 /usr/lib/systemd/systemd-journald

root 6116 0.0 0.0 112644 984 pts/0 R+ 11:31 0:00 grep --color=auto systemd-journald

[root@node1 Desktop]# kill -1 409 ##重新加载

3e6130f0af380e8ba22570942170f8ce.png

[root@node1 Desktop]# date

Tue Oct 16 11:34:38 EDT 2018

[root@node1 Desktop]# reboot

Connection to 172.25.254.100 closed by remote host.

Connection to 172.25.254.100 closed.

[kiosk@foundation69 ~]$ ssh root@172.25.254.100

root@172.25.254.100's password:

Last login: Tue Oct 16 08:53:50 2018 from 172.25.254.69

[root@node1 ~]# journalctl

3f4936a33602f823c5be02750a3ea758.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Go语言(也称为Golang)是由Google开发的一种静态强类型、编译型的编程语言。它旨在成为一门简单、高效、安全和并发的编程语言,特别适用于构建高性能的服务器和分布式系统。以下是Go语言的一些主要特点和优势: 简洁性:Go语言的语法简单直观,易于学习和使用。它避免了复杂的语法特性,如继承、重载等,转而采用组合和接口来实现代码的复用和扩展。 高性能:Go语言具有出色的性能,可以媲美C和C++。它使用静态类型系统和编译型语言的优势,能够生成高效的机器码。 并发性:Go语言内置了对并发的支持,通过轻量级的goroutine和channel机制,可以轻松实现并发编程。这使得Go语言在构建高性能的服务器和分布式系统时具有天然的优势。 安全性:Go语言具有强大的类型系统和内存管理机制,能够减少运行时错误和内存泄漏等问题。它还支持编译时检查,可以在编译阶段就发现潜在的问题。 标准库:Go语言的标准库非常丰富,包含了大量的实用功能和工具,如网络编程、文件操作、加密解密等。这使得开发者可以更加专注于业务逻辑的实现,而无需花费太多时间在底层功能的实现上。 跨平台:Go语言支持多种操作系统和平台,包括Windows、Linux、macOS等。它使用统一的构建系统(如Go Modules),可以轻松地跨平台编译和运行代码。 开源和社区支持:Go语言是开源的,具有庞大的社区支持和丰富的资源。开发者可以通过社区获取帮助、分享经验和学习资料。 总之,Go语言是一种简单、高效、安全、并发的编程语言,特别适用于构建高性能的服务器和分布式系统。如果你正在寻找一种易于学习和使用的编程语言,并且需要处理大量的并发请求和数据,那么Go语言可能是一个不错的选择。
Go语言(也称为Golang)是由Google开发的一种静态强类型、编译型的编程语言。它旨在成为一门简单、高效、安全和并发的编程语言,特别适用于构建高性能的服务器和分布式系统。以下是Go语言的一些主要特点和优势: 简洁性:Go语言的语法简单直观,易于学习和使用。它避免了复杂的语法特性,如继承、重载等,转而采用组合和接口来实现代码的复用和扩展。 高性能:Go语言具有出色的性能,可以媲美C和C++。它使用静态类型系统和编译型语言的优势,能够生成高效的机器码。 并发性:Go语言内置了对并发的支持,通过轻量级的goroutine和channel机制,可以轻松实现并发编程。这使得Go语言在构建高性能的服务器和分布式系统时具有天然的优势。 安全性:Go语言具有强大的类型系统和内存管理机制,能够减少运行时错误和内存泄漏等问题。它还支持编译时检查,可以在编译阶段就发现潜在的问题。 标准库:Go语言的标准库非常丰富,包含了大量的实用功能和工具,如网络编程、文件操作、加密解密等。这使得开发者可以更加专注于业务逻辑的实现,而无需花费太多时间在底层功能的实现上。 跨平台:Go语言支持多种操作系统和平台,包括Windows、Linux、macOS等。它使用统一的构建系统(如Go Modules),可以轻松地跨平台编译和运行代码。 开源和社区支持:Go语言是开源的,具有庞大的社区支持和丰富的资源。开发者可以通过社区获取帮助、分享经验和学习资料。 总之,Go语言是一种简单、高效、安全、并发的编程语言,特别适用于构建高性能的服务器和分布式系统。如果你正在寻找一种易于学习和使用的编程语言,并且需要处理大量的并发请求和数据,那么Go语言可能是一个不错的选择。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值