当前位置:操作系统 > Unix/Linux >>

centos8和centos7更新系统时间ntp同步更新方法

ntp时间同步常见疑难:no server suitable for synchronization found

注意查看防火墙可以试试加参数 -u 例如 ntpdate -u ntp.aliyun.com 


一、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

yum install -y chrony
可选配置,选择自己指定的NTP服务器,不指定自动使用公共服务器

vim /etc/chrony.conf

//-----------------------------

# 使用 pool.ntp.org 项目中的公共服务器。以server开,理论上想添加多少时间服务器都可以
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
pool 2.centos.pool.ntp.org iburst
server ntp.aliyum.com iburst
server ntp6.aliyum.com iburst
server cn.ntp.org.cn iburst
server ntp.shu.edu.cn iburst

//-----------------------------

//重启chronyd查看时间同步源
systemctl restart chronyd
systemctl enable chronyd
chronyc sources -v
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 //预先同步测试,查看是否成功 有可能防火墙会阻碍更新时间,这时可以加上“-u”参数


hwclock -w //同步BIOS

vim /etc/crontab  //配置定时任务24小时同步一次

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 //查看运行日志
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,