ntp时间服务器

发布时间:2020-07-05 13:32:47 作者:小铁匠819
来源:网络 阅读:786

1NTP时间服务器

NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议。

NTP服务器是用于局域网服务器时间同步使用的,可以保证局域网所有的服务器与时间服务器的时间保持一致,某些应用对时间实时性要求高的必须统一时间。

基于Client/server模式udp123端口

 

2、安装步骤:

2.1、 服务器端: 

NTP服务器监听端口为UDP的123,那就需要在本地防火墙开启运行客户端访问123端口,vi /etc/sysconfig/iptables添加如下规则:

-A INPUT -m state --state NEW -m udp -pudp --dport 123 -j ACCEPT

2.1.1、首先关闭防火墙:   /etc/init.d/iptables stop

     或关闭Selinux软件服务: Setenforce 0临时关闭

2.1.2[root@haikang~]#yum install ntp* -y   //安装ntp软件

        [root@haikang ~]# cp /etc/ntp.conf/etc/ntp.conf.bak  //备份ntp主配置文件

        [root@haikang ~]#vi /etc/ntp.conf   //修改ntp主配置文件 

        [root@haikang~]# cat /etc/ntp.conf   //查看主配置文件

          driftfile /var/lib/ntp/drift 

           //在与上级时间服务器联系时所花费的时间,记录在driftfile参数后面的文件内

restrictdefault kod nomodify notrap nopeer noquery

//允许所有来跟我进行同步

          restrict 127.0.0.1  //开启内部递归网络接口 lo

          restrict 192.168.1.0 mask255.255.255.0 nomodify notrap

           //定义可访问的内部子网客户端,但不能修改NTP服务器的时间参数。

server 0.centos.pool.ntp.org iburst    

//上级时间服务器

server 127.127.1.0     # local clock//设置与本机ntp同步时钟

         [root@haikang~]# /etc/init.d/ntpd start 

         //启动ntp服务,客户端需要几分钟后才能同步,否则会提示错误.

         [root@haikang ~]# netstat -nulp|grep ntp   //查看是否有ntp进程

[root@haikang ~]# ntpq -p   //查看ntp服务器的上级服务器

[root@haikang ~]# watch ntpq -p

     remote           refid      st t when poll reach   delay  offset  jitter

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

 ntp1.ams1.nl.le 130.133.1.10     2 u  15   64  153 337.087  -705047 7050475

注释:remote -本机和上层ntp的ip或主机名,“+”表示优先,“*”表示次优先

refid  - 参考上一层ntp主机地址

st    - stratum阶层

when   - 多少秒前曾经同步过时间

poll   - 下次更新在多少秒后

reach  - 已经向上层ntp服务器要求更新的次数

delay  - 网络延迟

offset  - 时间补偿

jitter  - 系统时间与bios时间差 

    2.2、客户端:           

[root@localhost ~]# ntpdate172.16.30.12  //与NTP进行同步

30 May 01:15:35 ntpdate[1096]: adjust timeserver 172.16.30.12 offset 0.003669 sec

备注:如果客户机没有ntpdate,可以yum –y install ntp 即可!

客户端创建计划任务:

crontab -e  创建客户端定期同步,需创建计划任务。

如:增加一行,在每天的6点10分与时间同步服务器进行同步

10(分)  06(时) *(日) *(月) *(周)/usr/sbin/ntpdate ntp-server的ip (172.16.30.10)>>/usr/local/logs/crontab/ntpdate.log

crontab -l  //查看计划任务

备注:如果客户机没有crontab,可以yum  install cron*  -y 即可。

crontab 主要用来创建计划任务

2.3ntp客户端同步时的错误解决方案:

[root@localhost~]# ntpdate 172.16.30.12

30 May11:50:29 ntpdate[1136]: no server suitable for synchronization found

   客户端用[root@localhost~]# ntpdate  -d 172.16.30.12

    错误1.Serverdropped: no data

        关闭防火墙或者加入规则-AINPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCEPT

 


推荐阅读:
  1. ntp网络时间服务器的新功能是什么
  2. 关于NTP时间服务器的详细介绍

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

ntp nt

上一篇:来来来!游戏场景风格暴露你的年纪

下一篇:thinkphp5 生成二维码在模板中显示

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》