Linux时间同步小知识

ntpdate 系统时间、hwclock 硬件时间
1、判断当前时间是否准确
[root@Ecology-APP ~]# date
2020年 03月 03日 星期二 10:13:02 CST

2、检查是否安装ntpdate
[root@Ecology-APP ~]# ntpdate
-bash: ntpdate: command not found

3、检查网络是否通,比如阿里云的时间服务器,如果不能连接外网就选择内网的时间服务器
[root@Ecology-APP ~]# ping ntp1.aliyun.com
PING ntp1.aliyun.com (120.25.115.20) 56(84) bytes of data.
64 bytes from 120.25.115.20: icmp_seq=1 ttl=52 time=14.2 ms

4、安装ntpdate,如果已联网
[root@Ecology-APP ~]# yum -y install ntpdate
已加载插件:fastestmirror
设置安装进程
Determining fastest mirrors
* base: mirrors.ustc.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.7 kB 00:00
extras | 3.4 kB 00:00
extras/primary_db | 29 kB 00:00
updates | 3.4 kB 00:00
updates/primary_db | 8.5 MB 00:01
解决依赖关系
--> 执行事务检查
---> Package ntpdate.x86_64 0:4.2.6p5-15.el6.centos will be 安装
--> 完成依赖关系计算
依赖关系解决
======================================================================================================================================================================================
软件包 架构 版本 仓库 大小
======================================================================================================================================================================================
正在安装:
ntpdate x86_64 4.2.6p5-15.el6.centos updates 79 k
事务概要
======================================================================================================================================================================================
Install 1 Package(s)
总下载量:79 k
Installed size: 123 k
下载软件包:
ntpdate-4.2.6p5-15.el6.centos.x86_64.rpm | 79 kB 00:00
运行 rpm_check_debug
执行事务测试
事务测试成功
执行事务
正在安装 : ntpdate-4.2.6p5-15.el6.centos.x86_64 1/1
Verifying : ntpdate-4.2.6p5-15.el6.centos.x86_64 1/1

已安装:
ntpdate.x86_64 0:4.2.6p5-15.el6.centos
完毕!

5、系统时间同步
[root@Ecology-APP ~]# ntpdate ntp1.aliyun.com
3 Mar 10:26:13 ntpdate[25072]: step time server 120.25.115.20 offset 537.647776 sec

6、硬件时间同步
[root@Ecology-APP ~]# hwclock --systohc
或者
[root@Ecology-APP ~]# hwclock -w

7、检查时间是否已同步
[root@Ecology-APP ~]# date
[root@Ecology-APP ~]# hwclock

8、添加job定时同步
每隔一小时同步一下
* */1 * * * root ntpdate ntp1.aliyun.com;hwclock -w
每天1点同步一次
* 1 * * * root ntpdate ntp1.aliyun.com;hwclock -w

posted @ 2020-03-03 10:49  ritchy  阅读(414)  评论(0编辑  收藏  举报