樓主在這里用chrony,一般redhat7和CentOS7默認已安裝chrony
yum install chrony
修改配置文件,添加時間服務器
vi /etc/chrony.conf
# server 0.asia.pool.ntp.org iburst
# server 1.asia.pool.ntp.org iburst
# server 2.asia.pool.ntp.org iburst
# server 3.asia.pool.ntp.org iburst
server 192.168.101.1 #本地物理機
server ntp1.aliyun.com
server time1.aliyun.com
啟動服務
systemctl start chronyd
驗證
[root@ceph-deploy ~]# chronyc sources -v //查看時間同步源
210 Number of sources = 3
.-- 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
===============================================================================
^? gateway 0 6 0 - +0ns[ +0ns] +/- 0ns
^? 120.25.115.20 2 6 3 5 -2442us[-2442us] +/- 6122us
^? 203.107.6.88 2 6 3 5 -2272us[-2272us] +/- 25ms
[root@ceph-deploy ~]# ss -tulp | grep chronyd // 查看時間同步源狀態
udp UNCONN 0 0 127.0.0.1:323 *:* users:(("chronyd",pid=10826,fd=1))
udp UNCONN 0 0 ::1:323 :::* users:(("chronyd",pid=10826,fd=2))
一切看起來很正常,但是一date就發現慢了一天,timedatectl查看一下時區,原來是美國東部時間,也就是時區錯了
[root@ceph-deploy ~]# date
Wed Jul 18 22:25:04 EDT 2018
[root@ceph-deploy ~]# timedatectl
Local time: Wed 2018-07-18 22:26:52 EDT
Universal time: Thu 2018-07-19 02:26:52 UTC
RTC time: Thu 2018-07-19 02:26:32
Time zone: America/New_York (EDT, -0400)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: yes
Last DST change: DST began at
Sun 2018-03-11 01:59:59 EST
Sun 2018-03-11 03:00:00 EDT
Next DST change: DST ends (the clock jumps one hour backwards) at
Sun 2018-11-04 01:59:59 EDT
Sun 2018-11-04 01:00:00 EST
復制響應的時區文件到/etc/localtime,最后才把時間調整過來,出現這種情況一般是安裝系統的時候沒選對時區,默認就是美國東部時間
cp /usr/share/zoneinfo/$主時區/$次時區 /etc/localtime
[root@ceph-deploy ~]# cd /usr/share/zoneinfo/
[root@ceph-deploy zoneinfo]# cp Asia/Shanghai /etc/localtime
cp: overwrite ‘/etc/localtime’? y
[root@ceph-deploy zoneinfo]# date
Thu Jul 19 10:31:10 CST 2018