zoukankan      html  css  js  c++  java
  • NTP原理及配置使用

    一、NTP简介

    1.NTP简介   

           NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议。它的用途是把计算机的时钟同步到世界协调时UTC,其精度在局域网内可达0.1ms,在互联网上绝大多数的地方其精度可以达到1-50ms。(1s=1000ms) NTP服务器就是利用NTP协议提供时间同步服务的。

    2.NTP原理
        NTP客户端可以定时自动向NTP服务器发送请求来获取时间,NTP服务器将时间发送给客户端,。
        NTP服务器的时间来源有两个
        1.网络时间
        2.NTP服务器自己的时间
    2.NTP架构
        C/S
    二、部署NTP服务端
    1.NTP安装
    1. [root@web02 ~]# yum install ntp -y
    2.NTP配置文件说明
    1)restict 表示进行授权,授权哪些主机可以使用这个服务器
        格式: restrict  IP地址  mask  子网掩码  参数
    参数有以下几个
        ignore  :关闭所有的 NTP 联机服务
        nomodify:客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时。
        notrust :客户端除非通过认证,否则该客户端来源将被视为不信任子网
        noquery :不提供客户端的时间查询:用户端不能使用ntpq,ntpc等命令来查询ntp服务器
        notrap :不提供trap远端登陆:拒绝为匹配的主机提供模式 6 控制消息陷阱服务。陷阱服务是 ntpdq 控制消息协议的子系统,用于远程事件日志记录程序。
        nopeer :用于阻止主机尝试与服务器对等,并允许欺诈性服务器控制时钟
        kod : 访问违规时发送 KoD 包。
     
    例子:
        restrict 127.0.0.1 表示当前主机可以使用这个时间服务
        restrict 172.16.1.0 mask 255.255.255.0 表示授权172.16.1网络中的全部主机可以使用时间服务
        restrict 0.0.0.0 mask 0.0.0.0  nomodify notrao 表示所有主机都可以访问这个时间服务
        restrict efault ignore 设置默认策略,允许任意主机进行时间同步
     
    2)server 表示当前NTP服务从哪个主机来获取时间
    默认的ntp地址
        server 0.centos.pool.ntp.org iburst
        server 1.centos.pool.ntp.org iburst
        server 2.centos.pool.ntp.org iburst
        server 3.centos.pool.ntp.org iburst
    常用的ntp地址
        server ntp1.aliyun.com     #→阿里云时间服务器(ntp1...21等)
        server time.nist.gov          #→微软时间服务器
    3)fudge 设置你的ntp优先级
    4)statsdir logfile  指定日志文件的位置
     
    3.修改NTP配置文件
    【此例使用ntp本机时间作为时间源】
    1. [root@web02 ~]# cd /etc/
    2. [root@web02 etc]# mv ntp.conf ntp.conf.bak
    3. [root@web02 etc]#cat > ntp.conf<<eof
    4. server 127.127.1.0
    5. restrict 127.0.0.1
    6. restrict 10.0.0.0 mask 255.255.255.0
    7. fudge 127.127.1.1 startnum 10
    8. statsdir /var/log/ntp/
    9. logfile /var/log/ntp/ntp.log
    10. eof
    检查ntp运行状态
    1. [root@web02 etc]# ntpq -p
    2. remote refid st t when poll reach delay offset jitter
    3. ==============================================================================
    4. *LOCAL(0) .LOCL. 5 l 1 64 1 0.000 0.000 0.000
    5.  
    6. [root@web02 etc]# ntpstat
    7. synchronised to local net at stratum 6
    8. time correct to within 7948 ms
    9. polling server every 64 s
    三、部署NTP客户端
     
    1.windows客户端
         
    2.linux客户端
        客户端只需要安装ntp,但是不能启动ntp。
        启动ntp会报错:
    1. [root@test ~]# yum install ntpdate
    2. [root@test ~]# crontab -e
    3. */5 * * * * /usr/sbin/ntpdate 10.0.0.7 &gt;/dev/null 2&gt;&1
  • 相关阅读:
    vim介绍 & vim颜色显示和移动光标& vim一般模式下移动光标 & vim一般模式下复制、剪切和粘贴
    lvm 详解 磁盘故障小案例
    磁盘格式化、磁盘挂载、手动增加swap空间
    df du 磁盘分区
    su sudo 限制root远程登录
    usermod 用户密码管理 mkpasswd
    顺序查找,二分法查找,插值查找算法实现及分析
    完全二叉树的构建及三种遍历
    Mybatis由于类型转换出现的问题
    delimiter解释
  • 原文地址:https://www.cnblogs.com/lwf-blog/p/7289932.html
Copyright © 2011-2022 走看看