centos7 设置时区且自动同步

每次新虚拟机都要设置时间,在此备忘一下

root@localhost # date
Wed May 13 19:24:10 CST 2020
root@localhost # timedatectl status
      Local time: Wed 2020-05-13 19:22:52 CST
  Universal time: Wed 2020-05-13 11:22:52 UTC
        RTC time: Wed 2020-05-13 11:22:51
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: n/a
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

安装ntp

root@localhost # yum -y install ntp ntpdate
#开机启动服务
root@localhost # systemctl enable ntpd 
# 更新时间
root@localhost # ntpdate cn.pool.ntp.org
13 May 11:27:28 ntpdate[53055]: step time server 84.16.73.33 offset -28799.290997 sec
# 设置中国时区
root@localhost # timedatectl set-timezone Asia/Shanghai
# 同步系统时间到硬件
root@localhost # hwclock --systohc 
# root@localhost # timedatectl set-local-rtc 1
# 查看时间,已恢复正常
root@localhost # date
Wed May 13 11:27:56 CST 2020

你可能感兴趣的:(linux,centos)