1.服务名称systemd-journald.service
1.1 journalctl 命令用法
journalctl -n 3 显示最新3条
journalctl --since “2020-02-15 23:20” 显示23:20之后的日志
journalctl -o用法
journalctl -p
想要永久设置需要打开 /etc/systemd/journald.conf/去编辑
1.2 systemd-journald 永久存放日志
系统默认日志在:/run/log/journal中,开启重启后日志,开机重启后日志不会保存
建立永久保存日志方法如下
mkdir /var/log/journal 建立目录
chgrp systemd-journal /var/log/journal 更改目录的组
chmod 2774 /var/log/journal 更改目录权限
systemctl restart systemd-journald.service
当服务重启日志会存放在:/var/log/journal
实验操作
配置/var/log/journal
效果
17:45分建立
一段时间重启后journal有显示重启之前的日志
2.rsyslog.service
cat /var/log/messages 可以打开查看日志
日志类型:
2.1 自定义存放路径
设定配置文件 /etc/rsyslog.conf
a) 打开 vim /etc/rsyslog.conf
b) 编辑
. /var/log/westos 所有级别日志存放在westos
authpriv.* /var/log/westos authpriv存放在westos
. ;authpriv. none /var/log/westos 意思是所有级别日志存放在westos.除了authpriv不存放
c)重启服务
systemctl restart rsyslog.service
d) cat /var/log/westos 可见日志都存放在westos文件中
2.2 更改日志采集格式
a) 更改配置文件 /etc/rsyslog.conf
b) $template westos “%FROMHOST-IP% %timegenerated% %syslogtag% %msg%\n”
设定日志采集格式应用 .;authpriv.none /var/log/westos;WESTOS
c)重启服务
systemctl restart rsyslog.service
d) 查看效果
*3.日志的远程同步: *
rhel7_node1:192.168.0.10 日志接收端,所有人日志都存放在此台主机
rhel8_node2:192.168.0.11 发送日志到rhel7_node1
实验如下
a) rhel7设定接受所有人日志
systemctl stop firewalld 关闭火墙
vim /etc/rsyslog.conf
$Modload imudp 打开日志接受插件
$UDPServer Run 514 指定使用接口
重启:systemctl restart rsyslog
以上设置完成
查询端口:netstat -antlupe |grep rsyslog
b)rhel8_node1操作
vim /etc/rsyslog.conf
. @192.168.0.10
systemctl restart rsyslog
c)查看效果
rhel8操作
rhel7查看效果
4.timedatectl
系统查看时间 timedatectl
timedatectl set-time “2020-02-15 11:52” 设定系统时间
timedatectl list-timezones 显示所有时区时间
timedatectl set-timezone “Asia/Shanghai”
timedatectl set- local-rtc 0|1 0表示UTC格式计算时间 ,1表示local
5.同步时间服务
服务名称:chronyd.service
配置文件:/etc/chrony.conf操作
a)
rhel7系统操作并作为时间源
更改配置文件 vim /etc/chrony.conf
systemctl restart chronyd.service 重启
systemctl stop firewalld 关闭火墙
b)
rhel8操作
11)开启服务:systemctl enable --now chronyd.service
2)编辑 vim /etc/chrony.conf
3)pool 192.168.0.10 iburst
4)systemctl restart chronyd.service
5)chronyc sources -v
效果时间已同步到rhel8中