您好,欢迎进入北京泰福特电子科技有限公司官网

咨询服务热线

400-015-1230

NTP服务在Linux离线安装及配置说明

发布时间:2022-04-12 10:26:17

常用命令:      

rpm -qa | grep ntp    

#查询已安装的ntp版本信息等    

service ntpd status  

#查询ntp服务状态    

service ntpd start      

#启动      

service ntpd stop    

#停止      

service ntpd restart  

#重启

ntpq -p  

#查看ntp服务器与上层ntp的状态

ntpstat    

#命令查看时间同步状态,这个一般需要5-10分钟后才能成功连接和同步。

所以,服务器启动后需要稍等下。

刚启动的时候,一般是:

# ntpstat

unsynchronised

time server re-starting

polling server every 64 s

连接同步后:

synchronised to NTP server (202.120.2.101) at stratum 4

time correct to within 1192 ms

polling server every 64 s

1、下载ntp的安装包:

ntp:可以为其配置ntp.conf将其设置为自动同步某服务器时钟。

ntpdate:可以使用 ntpdate -u ip地址 来手动同步某服务器的时钟。

2、安装命令:

方式(1) rpm -ivh ntp-4.2.6p5-18.el7.centos.x86_64.rpm

若出现找不到依赖则使用下面的命令:

方式(2)rpm -ivh ntp-4.2.6p5-18.el7.centos.x86_64.rpm --nodeps --force

 本人在使用方式(2)后使用rpm -qa | grep ntp 后看到了ntp,但是没有在/etc里看到ntp.conf。于是乎又使用方式一重新安装了一遍,这个文件出现了。

3、客户端配置:(/etc/ntp.conf)

[root@localhost etc]# cat ntp.conf //然后添加这两行 ,意思是 允许IPV4 IPV6 查询 拒绝修改restrict -4 default kod notrap nomodify  

restrict -6 default kod notrap nomodify//允许上层进行修改本机时间

//restrict 10.173.24.27 nomodify notrap noquery//配置上层server(要同步的),在这里配置的是实际的物理地址server 10.173.24.27  fudge 10.173.24.27 stratum 8

[root@localhost etc]# 4、服务器配置:(/etc/ntp.conf)[root@localhost etc]# cat ntp.conf//然后添加这两行 ,意思是 允许IPV4 IPV6 查询 拒绝修改restrict -4 default kod notrap nomodify  

restrict -6 default kod notrap nomodify//添加修改上层时间服务器,如果能联通外网,则不需要修改,

//server 0.rhel.pool.ntp.org iburst

//server 1.rhel.pool.ntp.org iburst

//server 2.rhel.pool.ntp.org iburst

//server 3.rhel.pool.ntp.org iburst

//如果联不通外网,则把上面几行注释,然后添加下面两行,意思是设置成时间服务器是自己

server 127.127.1.0fudge 127.127.1.0 stratum 8[root@localhost etc]#

5、测试(ntpstat一般是过个5-10分钟才能同步)

(1)服务器:

[root@localhost etc]# ntpq -p

remote refid  st t when poll reach  delay  offset  jitter

==============================================================================

*LOCAL(0)    .LOCL.   8 l   36   64  377   0.000   0.000  0.000

[root@localhost etc]# ntpstat synchronised to local net at stratum 9

time correct to within 12 ms polling server every 64 s

(2)客户端:

[root@localhost etc]# ntpq -p

remote      refid      st t when poll reach   delay   offset  jitter

==============================================================================

*10.173.24.27    LOCAL(0)         9 u   40   64  377    1.108    2.560   0.764

[root@localhost etc]# ntpstat

synchronised to NTP server (10.173.24.27) at stratum 10

  time correct to within 461 ms

  polling server every 64 s

6、日志设置

[root@localhost sysconfig]# pwd

/etc/sysconfig

[root@localhost sysconfig]#cat ntpd

# Command line options for ntpd

OPTIONS="-g -l /var/log/ntpstats/ntpd.log"

[root@localhost ntpstats]# service ntpd stop

[root@localhost ntpstats]# service ntpd start

[root@localhost ntpstats]# service ntpd status

[root@localhost ntpstats]# tail -200f /var/log/ntpstats/ntpd.log


  • 联系方式
  • 传 真:86-10-82782026
  • 电 话:400-015-1230
  • 地 址:北京市海淀区北清路68号院用友软件园北区17号楼三层
在线咨询

咨询电话:

400-015-1230

  • 微信扫码 关注我们

Copyright © 2002-2035 北京泰福特电子科技有限公司 版权所有 备案号:京ICP备12028220号-1
京公网安备 11010802025976号

扫一扫咨询微信客服

18519396506
Powered by RRZCMS