Linux配置 | NTP时间同步

NTP:网络时间协议 是以交换封包把两台电脑的时钟同步化的网络协议。

一、查看系统是否已经安装ntp服务组件

rpm -qa | grep "ntp"  
ntp-4.2.6p5-15.el6.centos.x86_64
ntpdate-4.2.6p5-15.el6.centos.x86_64

二、NTP服务端配置

1、如果没有检测到本地ntp组件,使用yum进行安装

yum -y install ntp 

2、设置东八区时区为当前时区

rm -rf /etc/localtime
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

3、手动同步下网络时间

ntpdate -u cn.pool.ntp.org

4、修改配置文件

vi/etc/ntp.conf

添加如下内容:

默认允许任何主机进行时间同步
restrict default ignore
允许上层时间服务器主动修改本机时间
restrict cn.pool.ntp.org nomodify notrap noquery
restrict 0.cn.pool.ntp.org nomodify notrap noquery
restrict 1.cn.pool.ntp.org nomodify notrap noquery
restrict asia.pool.ntp.org nomodify notrap noquery
restrict 0.asia.pool.ntp.org nomodify notrap noquery
restrict 1.asia.pool.ntp.org nomodify notrap noquery
外部时间服务器不可用时,以本地时间作为时间服务
server  127.127.1.0     # local clock
fudge   127.127.1.0 stratum 10

三、设置NTP服务自启动

1、设置ntp为自启动项

chkconfig ntpd on   
chkconfig --list ntpd #查看启动项2、3、4、5是否打开

2、启动NTP服务

/etc/init.d/ntpd restart   启动NTP服务
netstat -tlunp | grep #ntp查看ntp服务进程
ntpstat   #查看时间同步状态。启动后,一般需要5-10分钟左右的时候才能与外部时间服务器开始同步时间。可以通过命令查询NTPD服务情况

3、查看网络中的NTP服务器,同时显示客户端和每个服务器的关系

ntpq –p  #出现了红框中local,说明本地时钟源配置成功

posted @ 2020-12-19 17:13  KnowKnow~  阅读(704)  评论(0)    收藏  举报