美文网首页
第九节、NTP服务

第九节、NTP服务

作者: 妄语莫言 | 来源:发表于2017-11-28 01:57 被阅读0次
    1. 服务的功能和用途是什么?
    2. 服务的安装方法,具体了命令参数。
    3. 安装完成后,安装路径,配置文件,启动文件的位置。
    4. 配置文件里面的内容,参数的具体含义。
    5. 如何启动服务,怎么查看服务是否已启动,端口号
    6. 软件服务部署好之后怎么验证及使用。
    

    一、NTP服务

    参考网址1CSDN博客Linux NTP配置详解 (Network Time Protocol)
    参考网址2潘帕斯的蓝白天的博客
    NTP服务配置 ](http://blog.sina.com.cn/s/blog_4612ed51010124e2.html)
    NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议

    • 在服务端安装ntp服务yum install ntp -y
    • 安装完成后查看配置文件位置rpm -ql ntp|more得到文件位置/etc/ntp.conf启动文件位置/etc/rc.d/init.d/ntpd
    • 查看配置文件内容,利用命令过略带#的注释内容grep -v "^#" /etc/ntp.conf
    driftfile /var/lib/ntp/drift#在与上级时间服务器联系时所花费的时间,记录在driftfile参数后面的文件内
    restrict default kod nomodify notrap nopeer noquery#允许所有机器和自己时间通信
    restrict 127.0.0.1 #允许本机访问NTP服务127.0.0.1 是本地回还地址代表自己
    server 0.centos.pool.ntp.org iburst #设置上层时间服务器地址
    includefile /etc/ntp/crypto/pw #引用的时间戳
    keys /etc/ntp/keys #密钥设置默认即可
    
    备注

    NTP服务器设置时候一般都必须设置上层时间服务器作为校时依据,如果能连接外网可以设置官方权威的时间服务器,如果不能联网需要添加如下代码将自己作为上层服务器,自己和自己校时。

    server 127.127.1.0#设置和自己校时
    fudge 127.127.1.0 stratum 10#这行是时间服务器的层次。设为0则为顶级,如果要向别的NTP服务器更新时间,请不要把它设为0
    
    • 启动ntp服务`/etc/init.d/ntpd start|restart|stop
    • 查看服务是否运行ps -ef|grep ntp,通过端口号查看NTP服务netstat -nul|grep 123
    [root@mini ntp]# /etc/init.d/ntpd start
    Starting ntpd:                                             [  OK  ]
    [root@mini ntp]# ps -ef|grep ntp
    ntp        2714      1  0 14:33 ?        00:00:00 ntpd -u ntp:ntp -p /var/run/ntpd.pid -g
    root       2717   2630  0 14:34 pts/0    00:00:00 grep ntp
    [root@mini ntp]# netstat -nul|grep 123#u表示udp协议,l表示监听listen,n即numeric,不解析名字don't resolve names
    udp        0      0 192.168.15.138:123          0.0.0.0:*                               
    udp        0      0 127.0.0.1:123               0.0.0.0:*                               
    udp        0      0 0.0.0.0:123                 0.0.0.0:*                               
    udp        0      0 fe80::20c:29ff:fea8:f959:123 :::*                                    
    udp        0      0 ::1:123                     :::*                                    
    udp        0      0 :::123                      :::*  
    
    • 查看NTP服务的具体状态ntpq -p
    故障排查

    这里测试服务器的时候返回故障如下,首先查看两边防火墙selinux是否关闭,然后检查服务端NTP是否已启动

    [root@mini ~]# ntpq -p
    localhost: timed out, nothing received
    ***Request timed out
    

    查询相关资料可能是主机有启用Ipv6 ,默认先走的ipv6地址
    分别测试ntpq -4p,ntpq -6p

    [root@mini ~]# ntpq -4p
         remote           refid      st t when poll reach   delay   offset  jitter
    ==============================================================================
    *ntp3.itcomplian 10.6.30.8        6 u   53   64   17  314.185   34.002 104.899
     localhost       .INIT.          16 l    -   64    0    0.000    0.000   0.000
    

    结果ipv4正常,ipv6无返回结果,关闭ipv6
    在/etc/modprobe.d/dist.conf结尾添加
    alias net-pf-10 off
    alias ipv6 off
    再次查看ntp服务状态``

    [root@mini ~]# ntpq -p
         remote           refid      st t when poll reach   delay   offset  jitter
    ==============================================================================
     biisoni.miuku.n 204.123.2.72     2 u    -   64    1  230.114  -41.780   8.367
    *LOCAL(0)        .LOCL.          10 l    1   64    1    0.000    0.000   0.000
    

    此时server端NTP服务正常运行,再局域网客户端测试(需要安装ntpdate服务yum install -y ntpdate

    [root@yumserver ~]# ntpdate 192.168.15.138   
    28 Nov 13:51:46 ntpdate[1125]: step time server 192.168.15.138 offset 197569.297959 sec
    

    最后将NTP服务加入开机自动启动项目chkconfig ntpd on

    附件NTP配置文件

    [root@mini ~]# cat /etc/ntp.conf 
    ###config NTP
    driftfile /var/lib/ntp/drift
    restrict default kod nomodify notrap nopeer noquery
    restrict 127.0.0.1
    server 0.centos.pool.ntp.org iburst
    server 127.127.1.0
    fudge 127.127.1.0 stratum 10
    includefile /etc/ntp/crypto/pw
    keys /etc/ntp/keys
    

    相关文章

      网友评论

          本文标题:第九节、NTP服务

          本文链接:https://www.haomeiwen.com/subject/zezrbxtx.html