时间同步服务chrony chronyd服务
来源:原创
时间:2020-02-17
作者:脚本小站
分类:Linux
快速执行:
yum install chrony -y && systemctl start chronyd.service && systemctl enable chronyd.service && timedatectl set-timezone Asia/Shanghai && chronyc -a makestep
开启服务:
systemctl start chronyd.service systemctl enable chronyd.service
配置:
vim /etc/chrony.conf
查看信息:
]# timedatectl status Local time: Mon 2020-02-17 05:31:56 EST Universal time: Mon 2020-02-17 10:31:56 UTC RTC time: Mon 2020-02-17 10:31:42 Time zone: America/New_York (EST, -0500) NTP enabled: yes NTP synchronized: yes RTC in local TZ: no DST active: no Last DST change: DST ended at Sun 2019-11-03 01:59:59 EDT Sun 2019-11-03 01:00:00 EST Next DST change: DST begins (the clock jumps one hour forward) at Sun 2020-03-08 01:59:59 EST Sun 2020-03-08 03:00:00 EDT
列出所有时区:
timedatectl list-timezones
设置时区:
]# timedatectl set-timezone Asia/Shanghai
手动同步时间:
]# chronyc -a makestep
集群同步:
集群时间同步需要有一个时间同步源,将集群其他节点的时间同步源指向同一个源即可。
server 192.168.1.88 iburst
查看时间同步源:^? 表示未连接成功,^* 表示同步成功。
]# 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 =============================================================================== ^* 203.107.6.88 2 10 177 241 -1940us[-2125us] +/- 17ms
手动同步时间:
systemctl stop chronyd chronyd -q 'server ntp.aliyun.com iburst' systemctl start chronyd
查看时间同步源状态:
chronyc sourcestats -v
启用NTP时间同步:
timedatectl set-ntp yes
校准时间服务器:
chronyc tracking
常用命令:
timedatectl #查看日期时间、时区及NTP状态 timedatectl list-timezones #查看时区列表 timedatectl set-timezone Asia/Shanghai #修改时区 timedatectl set-time "YYYY-MM-DD HH:MM:SS" #修改日期时间 timedatectl set-local-rtc 0 #使用utc时间 cat /etc/adjtime 0.0 0 0.0 0 UTC timedatectl set-local-rtc 1 #使用本地时间 cat /etc/adjtime 0.0 0 0.0 0 LOCAL
手动设置时间:
date -s "2021-06-10 15:36:30"
作为服务端的配置:配置完成后重启。
server 127.0.0.1 iburst driftfile /var/lib/chrony/drift makestep 1.0 3 rtcsync allow 0.0.0.0/0 # 允许同步的网段 local stratum 10 # 这个要打开,没网连不上时间源任然为本地提供时间同步服务 logdir /var/log/chrony