Linux时钟

  Linux系统有两个时钟:一个是主板电池供电运行的硬件时钟(Real Time Clock,简称RTC),另一个是内核中的系统时钟(System Clock)。当Linux系统启动时,内核读取RTC时钟,用于初始化系统时钟。

1. 硬件时钟

查看硬件时钟:# hwclock --show
设置硬件时钟:# hwclock --set --date="12/31/18 09:28:00"

2. 系统时钟

查看系统时钟:# date
设置系统时钟:# date -s "2020-08-12 12:00:00"

3. 时钟同步

硬件时钟同步到系统时钟:# hwclock --hctosys 或 hwclock -s
系统时钟同步到硬件时钟:# hwclock --systohc 或 hwclock -w

4. chrony

  Linux在运行时间长了之后,系统时钟会存在一定的误差,时钟同步在大型集群环境中是很重要的。

  Centos 7系统默认使用chrony来实现时钟同步。chrony包含两个程序:chronyd 是一个守护程序,chronyc 是一个命令行界面程序。

(1)配置服务端

# yum -y install chrony
# vim /etc/chrony.conf
server ntp.aliyun.com iburst
server ntp.cloud.aliyuncs.com iburst
driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
allow 192.168.2.0/24
local stratum 10
logdir /var/log/chrony
# systemctl enable chronyd
# systemctl start chronyd

(2)配置客户端

# yum -y install chrony
# vim /etc/chrony.conf
server 192.168.2.10 iburst
# systemctl enable chronyd
# systemctl start chronyd
# chronyc sources -v

 

posted @ 2020-08-12 11:13  PIPO2  阅读(446)  评论(0编辑  收藏  举报