一、timedatectl
1.设定系统时间
timedatectl set-time "2020-07-02 11:19:00" ##设定系统时间
2.设定系统时区
1 | timedatectl list-timezones ##显示系统的所有时区
2 | timedatectl set-timezone "Asia/Shanghai" ##设定系统时区
##设定世界地点为上海
3 | [root@yxy ~]# timedatectl ##发现CST和utc时间不同
4 | Local time: Fri 2020-04-10 10:48:41 CST ##本地时间
5 | Universal time: Fri 2020-04-10 02:48:41 UTC ##国际标准时间
6 | RTC time: Fri 2020-04-10 02:48:42 ##硬件时间
7 | Time zone: Asia/Shanghai (CST, +0800)
8 | System clock synchronized: no
9 | NTP service: inactive
10| RTC in local TZ: no
3.设定系统时间计算方式
1 | timedatectl set-local-rtc 0|1 ##设定系统时间计算方式
2 | ##0表示使用utc时间计算方式
3 | timedatectl set-local-rtc 0 ##将硬件时间与国际标时间
4 | timedatectl set-local-rtc 1 ##将硬件时间与本地时间同步
五、 时间同步服务
#服务名称: chronyd.service
#配置文件: /etc/chrony.conf
在yxy作为时间源lww同步yxy时间
1.在yxy中
1 | vim /etc/chrony.conf
2 | 26 allow 172.25.254.0/24 ##允许172.25.254.0网段主机同步时间
3 | 29 local stratum 10 ##开启时间同步服务器功能并设定级别为10
4 | systemctl restart chronyd.service
5 | systemctl stop firewalld | systemctl disable --now firewalld
2.在lww中
1 | vim /etc/chrony.conf
2 | pool 172.25.254.10 iburst
3 | systemctl restart chronyd.service
3.使用chronyc 命令查看时间效果
在lww里查看时间:已经变成了yxy中的时间
1 | [root@lww ~]# chronyc sources -v
2 | 210 Number of sources = 1
3 |
4 | .-- Source mode '^' = server, '=' = peer, '#' = local clock.
5 | / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
6 | | / '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
7 | || .- xxxx [ yyyy ] +/- zzzz
8 | || Reachability register (octal) -. | xxxx = adjusted offset,
9 | || Log2(Polling interval) --. | | yyyy = measured offset,
10| || \ | | zzzz = estimated error.
11| || | | \
12| MS Name/IP address Stratum Poll Reach LastRx Last sample
13| ===============================================================================
14| ^* 172.25.254.10 10 6 377 23 -11us[ -35us] +/- 409us
注意:只有底下出现*号,同步时间成功。