一、相关知识了解

linux时间同步目前主要有三种软件:chrony、ntp、openntpd这三种,性能最强的是chrony,也是最推荐使用的
https://chrony.tuxfamily.org/comparison.html //参数对比

UTC (Universal Time Coordinated) 世界标准时间
GMT (Greenwich Mean Time) 格林尼治时间
CST (China standard Time) 中国标准时间
EDT为美国东部时间

二、查看参数

1、cat /etc/issue //查看系统版本确认是否8或7
2、timedatectl //查看当前使用时区及时间

三、centos8更新系统时间

1、查看并修改系统时区

timedatectl //查看时间时区
timedatectl set-timezone Asia/Shanghai //设置系统时区位亚洲/上海

2、安装chrony

  1. yum install -y chrony
  1. 可选配置,选择自己指定的NTP服务器,不指定自动使用公共服务器
  1. vim /etc/chrony.conf
  2. //-----------------------------
  3. # 使用 pool.ntp.org 项目中的公共服务器。以server开,理论上想添加多少时间服务器都可以
  4. # Use public servers from the pool.ntp.org project.
  5. # Please consider joining the pool (http://www.pool.ntp.org/join.html).
  6. pool 2.centos.pool.ntp.org iburst
  7. server ntp.aliyum.com iburst
  8. server ntp6.aliyum.com iburst
  9. server cn.ntp.org.cn iburst
  10. server ntp.shu.edu.cn iburst
  11. //-----------------------------
  12. //重启chronyd查看时间同步源
  13. systemctl restart chronyd
  14. systemctl enable chronyd
  15. chronyc sources -v
  16. chronyc sourcestats -v

3、重启并设置开机自启chronyd

systemctl restart chronyd
systemctl enable chronyd

4、查看时间同步状态

timedatectl status

5、 开启网络时间同步

timedatectl set-ntp true

四、centos7更新时间

yum install -y ntp //安装ntp
systemctl start ntpd //启动ntp
systemctl enable ntpd //开机自启
ntpdate -u ntp.aliyun.com //预先同步测试,查看是否成功
hwclock -w //同步BIOS
vim /etc/crontab //配置定时任务24小时同步一次

  1. 0 0 * * * root ntpdate ntp.aliyun.com > /dev/null 2>&1; /sbin/hwclock -w

service crond restart //重启crond

//可选配置查看crontab及运行日志异常处理
service crond status //查看运行状态
/var/log/cron.log //查看运行日志