linux设置时间自动同步+同步硬件时间

2022-11-03 1596阅读

温馨提示:这篇文章已超过512天没有更新,请注意相关的内容是否还可用!

1.检查系统是否安装了NTP包,没有安装我们直接使用yum命令在线安装: yum install ntp

linux设置时间自动同步+同步硬件时间
(图片来源网络,侵删)
linux设置时间自动同步+同步硬件时间
(图片来源网络,侵删)

注意尽量使用ntp服务,而不是用ntpdate

见参考,ntp是逐渐同步,ntpdate 是直接修改

2,service --status-all 查看开启了哪些服务

3,如果ntp未开启,则开启此服务 service ntpd start

4,设置ntp服务开机自启动chkconfig ntpd on

直接修改硬件时间与系统时间一致

[root@localhost ~]# timedatectl set-local-rtc 1

或者

[root@localhost ~]# hwclock --systohc --localtime

5,系统时间与硬件时间同步:

ntp服务,默认只会同步系统时间。如果想要让ntp同时同步硬件时间linux 同步时间,可以设置/etc/sysconfig/ntpd文件,在/etc/sysconfig/ntpd文件中,添加 SYNC_HWCLOCK=yes 这样linux 同步时间,就可以让硬件时间与系统时间一起同步。

6,与互联网标准时间进行同步 ntpdate time.windows.com

或 ntpdate cn.pool.ntp.org

如果端口被占用则,停止占用端口的进程,再执行

yum install lsof

lsof -i:123 查看123端口使用情况

kill -9 xxx杀死进程

ntpdate time.windows.com 同步时间

7,设置自动同步(定时任务,每隔一小时同步。。)

vi /etc/crontab

00 0 1 * * ntpdate -s time.windows.com  #每天凌晨1点
* */1 * * * ntpdate -s time.windows.com #每一个小时
* */1 * * * ntpdate -s cn.pool.ntp.org

8,重启linux,测试系统时间与硬件时间同步。

其他:查看系统时间 date 查看硬件时间 clock

有时候时间同步失败,可能并不是系统的问题,可能是时区不对

见参考

VPS购买请点击我

文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。

目录[+]