unit9、linux中时间的查看与同步,日志的查看与同步

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

root@desktop .ssh]# timedatectl set-time "2018-08-09 12:00:00"
[root@desktop .ssh]# timedatectl
      Local time: 四 2018-08-09 12:00:16 CST
  Universal time: 四 2018-08-09 04:00:16 UTC
        RTC time: 四 2018-08-09 04:00:16


在这里插入图片描述
#####################同步时间
server200:

[root@server .ssh]# date
2019年 08月 19日 星期一 06:55:42 CST
[root@server .ssh]# vim /etc/chrony.conf 
 23 allow 172.25.254.0/24
 24 # Listen for commands only on localhost.
 25 bindcmdaddress 127.0.0.1
 26 bindcmdaddress ::1
 27 
 28 # Serve time even if not synchronized to any NTP server.
 29 local stratum 10
[root@server .ssh]# systemctl restart chronyd.service 
[root@server .ssh]# systemctl stop firewalld


client:100

[root@desktop .ssh]# date 11111111     ###客户机设置时间
2018年 11月 11日 星期日 11:11:00 CST
vim /etc/chrony.conf
server 172.25.254.200 iburst		##本机立即同步200主机的时间Use public servers from the pool.ntp.org project.Please consider joining the pool (http://www.pool.ntp.org/join.html).server 172.25.254.200 iburst
#server 0.rhel.pool.ntp.org iburst
#server 1.rhel.pool.ntp.org iburst
#server 2.rhel.pool.ntp.org iburst
#server 3.rhel.pool.ntp.org iburstIgnore stratum in source selection.stratumweight 0systemctl restart chronyd                          ##重起服务
timedatectl set-timezone Asia/Shanghai  ##更改当前时区为东8区
[root@foundation30 ~]# 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.200               10   6     3    61   -6740h[ -6740h] +/-  250us


测试client100:


 [root@desktop .ssh]# date
2019年 08月 19日 星期一 07:02:40 CST
[root@desktop .ssh]# date
2019年 08月 19日 星期一 07:03:01 CST

   

在这里插入图片描述#####日志的远程同步
在日志发送方:

vim /etc/rsyslog.conf
.	@172.25.254.200		##"@"表示udp协议发送,"@@"表示tcp协议发送systemctl restart rsyslog

在日志接收方:

vim /etc/rsyslog.conf
15 $ModLoad imudp		##日志接收模块
16 $UDPServerRun 514		##开启接收端口systemctl restart rsyslog	
systemctl stop firewalld 	##关闭火墙
systemctl disable firewalld 	##设定火墙开机关闭

测试:
在发送放和接受放都清空日志文件
/var/log/messages在日志的发送方
logger testcat /var/log/messages ##查看日志已经生成在日志接收方查看
cat /var/log/messages

在这里插入图片描述
#######################journal
1.journalctl ##日志查看工具
-n 3 ##查看最近3条日志
-p err ##查看错误日志
-o verbose ##查看日志的详细参数 (举例sshd,重启pid会变,查看原来pid的日志)
–since ##查看从什么时间开始的日志
–until ##查看到什么时间为止的日志
journalctl --since “2018-11-11 12:00” --until “2018-11-11 12:01” (查看时间段内的日志)journalctl是查看内存中日志,不存储

[root@desktop .ssh]# journalctl -n 3                  ##查看3条                                 
-- Logs begin at 一 2019-08-19 03:51:14 CST, end at 一 2019-08-19 07:23:58 CST. --
8月 19 07:23:58 desktop dbus[517]: [system] Activating service name='org.freedesktop.PackageKit' (using servicehelper)
8月 19 07:23:58 desktop dbus-daemon[517]: dbus[517]: [system] Successfully activated service 'org.freedesktop.PackageKit'
8月 19 07:23:58 desktop dbus[517]: [system] Successfully activated service 'org.freedesktop.PackageKit'


##查看错误日志

[root@desktop .ssh]# journalctl -p err                 ##查看错误日志
-- Logs begin at 一 2019-08-19 03:51:14 CST, end at 一 2019-08-19 07:23:58 CST. --
8月 19 03:51:14 localhost kernel: Failed to access perfctr msr (MSR c1 is 0)
8月 19 03:51:16 localhost rpcbind[170]: rpcbind terminating on signal. Restart with "rpcbind -w"
8月 19 03:51:43 desktop smartd[502]: Problem creating device name scan list
8月 19 03:51:43 desktop smartd[502]: In the system's table of devices NO devices found to scan
8月 19 03:52:18 desktop systemd[1]: Failed to start LSB: Starts the Spacewalk Daemon.
8月 19 03:52:19 desktop systemd[1]: Failed to start /etc/rc.d/rc.local Compatibility.
8月 19 03:52:31 desktop libvirtd[1065]: libvirt version: 1.1.1, package: 29.el7 (Red Hat, Inc. <http://bugzilla.redhat.com/b
8月 19 03:52:31 desktop libvirtd[1065]: Module /usr/lib64/libvirt/connection-driver/libvirt_driver_lxc.so not accessible
8月 19 03:57:48 desktop bluetoothd[2194]: Parsing /etc/bluetooth/input.conf failed: No such file or directory
8月 09 12:09:39 desktop smartd[502]: System clock time adjusted to the past. Resetting next wakeup time.


###查看日志详细参数
[root@desktop .ssh]# journalctl -o verbose
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值