timedatectl命令
timedatectl 管理时间和日期
显示
[root@node1 ~]# timedatectl
Local time: Fri 2019-10-11 03:54:35 EDT #本地时间
Universal time: Fri 2019-10-11 07:54:35 UTC #格林威治时间
RTC time: Fri 2019-10-11 07:54:35 #主板bios时间
Timezone: America/New_York (EDT, -0400) #时区
NTP enabled: yes #自动同步时间功能
NTP synchronized: no #是否自动同步过
RTC in local TZ: no #是否开启本地时间功能
DST active: n/a
修改
timedatectl
#查看日期时间、时区及NTP状态
timedatectl list-timezones
#查看时区列表
timedatectl set-timezone Asia/Shanghai
#修改时区
timedatectl set-time "YYYY-MM-DD HH:MM:SS"
#修改日期时间
timedatectl set-local-rtc 0|1
#开启或关闭本地时间同步BISO时间;0为关闭;1为开启
timedatectl ntp 0|1
#开启或关闭网络时间同步;0为关闭;1为开启
cat /etc/adjtime
#可查看使用的是本地时间还是UTC时间
chronyd服务
chrony 是一个开源的自由软件,它能保持系统时钟与时钟服务器(NTP)同步,让时间保持精确。
chrony由两部分组成:chronyd和chronyc 。
chronyd 是一个后台运行的守护进程,用于调整内核中运行的系统时钟与时钟服务器同步。
配置文件/etc/chrony.conf
时间同步设置,注意关闭防火墙
服务器
地址为192.168.154.10
- 开放同步时间,修改配置文件
vim /etc/chrony.conf
# Allow NTP client access from local network.
allow 192.168.154.0/24
#允许那些地址段访问本机同步时间
# Serve time even if not synchronized to any NTP server.
local stratum 10
#开启本机作为时间源,不同不任何主机时间
2. 重启服务systemctl restart chronyd
客户端
地址为192.168.154.11
- 匹配同步主机,修改配置文件
vim /etc/chrony.conf
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 192.168.154.10 iburst
#访问192.168.154.10服务器同步时间
4. 重启服务systemctl restart chronyd
5. 查看时间是否同步成功
chronyc sources -v
#查看最后以行显示
#^*1.1.1.1 表示成功