一、timedatectl
1.设定系统时间
timedatectl set-time "2020-04-10 10:41:55" ##设定系统时间
2.设定系统时区
- timedatectl list-timezones ##显示系统的所有时区
- timedatectl set-timezone "Asia/Shanghai" ##设定系统时区
- ##设定世界地点为上海
- [root@foundation69 ~]# timedatectl ##发现CST和utc时间不同
- Local time: Fri 2020-04-10 10:48:41 CST ##本地时间
- Universal time: Fri 2020-04-10 02:48:41 UTC ##国际标准时间
- RTC time: Fri 2020-04-10 02:48:42 ##硬件时间
- Time zone: Asia/Shanghai (CST, +0800)
- System clock synchronized: no
- NTP service: inactive
- RTC in local TZ: no
3.设定系统时间计算方式
- timedatectl set-local-rtc 0|1 ##设定系统时间计算方式
- ##0表示使用utc时间计算方式
- timedatectl set-local-rtc 0 ##将硬件时间与国际标时间
- timedatectl set-local-rtc 1 ##将硬件时间与本地时间同步
五、 时间同步服务
- #服务名称: chronyd.service
- #配置文件: /etc/chrony.conf
在Horizon_carry作为时间源carry同步horizon时间
1.在Horizon_carry中
- vim /etc/chrony.conf
- 26 allow 172.25.254.0/24 ##允许172.25.254.0网段主机同步时间
- 29 local stratum 10 ##开启时间同步服务器功能并设定级别为10
- systemctl restart chronyd.service
- systemctl stop firewalld
2.在carry中
- vim /etc/chrony.conf
- pool 172.25.254.10 iburst
- systemctl restart chronyd.service
3.使用chronyc 命令查看时间效果
在carry里查看时间:已经变成了Horizon_carry中的时间
[root@carry ~]# 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
|| Reachability register (octal) -. | 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.10 3 6 377 3 -5190us[ -26ms] +/- 135ms