修改服务器时间及时区

楼主在这里用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

原文地址:https://www.cnblogs.com/liangjiongyao/p/9334464.html