• 如何搭建NTP服务


    最近,在搭建Oracle RAC过程中,需要用到DNS和NTP,其中,DNS用于域名、IP管理,NTP用于时间同步。其实,很久以前搭建过这两种服务,但技术,本质上,符合“用进废退”的客观规律。用得越频,自然就越娴熟。少用甚而不用,慢慢就淡忘了。以至于哪天要用起来的时候,会茫茫然不知而从。虽说网上的相关资料汗牛充栋,但难保良莠不齐。在搜索辨别的过程中,自然会花费不少时间。现在记录一下,一来整理思路,二则以备不时之需。毕竟,自己写的,再次看的时候,会更容易上手。

    实验环境:

    node1.being.com  192.168.1.130  -->>NTP服务器

    node2.being.com  192.168.1.131  -->>客户端

    一、在node1上编辑NTP配置文件

         1.  [root@node1 ~]# vim /etc/ntp.conf      

    restrict default kod nomodify notrap nopeer noquery   --拒绝IPv4的用户
    restrict -6 default kod nomodify notrap nopeer noquery --拒绝IPv6的用户
     
    restrict 127.0.0.1  --这两个是默认值,放行本机来源
    restrict -6 ::1
    restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap   --允许192.168.1.0这个网段的主机通过本机进行网络校时
    #restrict default  nomodify notrap --注意:为了方便,可设置为default,即允许所有IP通过本机进行网络校时
    server 0.rhel.pool.ntp.org --设置主机来源,即node1通过0.rhel.pool.ntp.org进行网络校对 server 1.rhel.pool.ntp.org server 2.rhel.pool.ntp.org

         其中,nomodify:客户端不能使用ntpc与ntpq这两个程序来修改服务器的时间参数,但客户端仍可通过这部主机来进行网络校时

                 notrap: 不提供trap这个远程事件登陆的功能

                 noquery: 客户端不能够使用ntpc、ntpd等命令来查询时间服务器,等于不提供NTP的网络校时。注意:如果需要提供NTP服务的话,则这个参数切记不要。

          如果IP后面没有任何参数,则表示“该IP或网段不受任何限制”

        2.  重启服务

             [root@node1 ~]# /etc/init.d/ntpd restart

    二、在node2上进行验证

          [root@node2 oracle]# ntpdate -d 192.168.1.130   --注意,通常需要5分钟才会和ntp服务器顺利连接上

          24 Mar 21:18:02 ntpdate[1382]: no server suitable for synchronization found

          用 ntpdate -d 192.168.1.130 进行查看,发现Server dropped: strata too high且stratum 16,而正常情况下,stratum最多可达15个阶层。

          这表示NTP Server还没有和它自身或者它的上一层Server同步上。

    三、在node1的/etc/ntp.conf添加以下参数

    server 127.127.1.0
    fudge  127.127.1.0 stratum 10

          以上定义是让NTP Server和其自身保持同步,如果在/etc/ntp.conf中定义的server都不可用时,将使用local时间作为ntp服务提供给ntp客户端。

          重启ntp服务,用以下命令进行验证

          [root@node1 ~]# ntpq -p   -->> 显示local即ok

          remote refid st t when poll reach delay offset jitter
          ==============================================================================
         *LOCAL(0) .LOCL. 10 l 44 64 377 0.000 0.000 0.000

    四、在客户端进行配置

          这时,有两种方法实现时间同步。

          1. 用ntpdate并采用crontab

             [root@node1 ~]# vim /etc/crontab 

             0 1 *  *  *  root (/usr/sbin/ntpdate 192.168.1.130 && /sbin/hwclock -w) &> /dev/null

           2. 采用ntp服务

             [root@node2 ~]# vim /etc/ntp.conf               

    restrict default kod nomodify notrap nopeer noquery
    restrict -6 default kod nomodify notrap nopeer noquery
    
    restrict 127.0.0.1
    restrict -6 ::1
    restrict 192.168.1.130    -->>这一项非必须的,在客户端,只指定server即可。
    
    server 192.168.1.130
    server 0.rhel.pool.ntp.org
    server 1.rhel.pool.ntp.org
    server 2.rhel.pool.ntp.org

             重启服务,此时大功告成,主要障碍还是在第二步客户端用ntpdate同步服务端的时候,报no server suitable的错误。

    他山之石,可以攻玉。老实说,这个问题的解决主要参考了以下两位作者的博客以及《鸟哥的Linux私房菜-服务器架构篇》。在此一并谢过!

    http://hi.baidu.com/d_life/item/3d5a081935834708e65c3697

    http://blog.csdn.net/suer0101/article/details/7868813

  • 相关阅读:
    cf 786B. Legacy(线段树区间建图)
    cf 1416D. Graph and Queries (生成树重构+线段树维护dfs序)
    cf 1437E. Make It Increasing
    cf 1434D. Roads and Ramen (树上最长偶权链)
    cf 1413C (贪心排序+双指针)
    cf 1421E. Swedish Heroes (dp)
    CF1428 F.Fruit Sequences
    11.Redis详解(十一)------ 过期删除策略和内存淘汰策略
    10.Redis详解(十)------ 集群模式详解
    9.Redis详解(九)------ 哨兵(Sentinel)模式详解
  • 原文地址:https://www.cnblogs.com/ivictor/p/3622081.html
Copyright © 2020-2023  润新知