Ntp服务器的搭建

在搭建Ntp服务器的过程中,试过两种方案,具体如下:

方案一: 到ntp官网获取源码编译,失败
 
下载源码ntp-4.2.8 -> ./configure -> make 无法通过;
 ps,在ubuntu12.02上源码无法编译通过。不过在Fedora上这种方案是可行的。所以,不同系统结果是不一样的。
 
 
方案二:成功
 
在线安装,sudo apt-get install ntp (提示:unable to locate package);
-> sudo apt-get update(获取更新)
-> sudo apt-get install ntp 
-> service --status-all(查看ntp服务已经开启)
[ + ] kerneloops
[ ? ] killprocs 
[ ? ] kmod 
[ ? ] lightdm
[ ? ] networking 
[ + ] ntp (+表示已经开启)
[ ? ] ondemand 
[ - ] openntpd
[ ? ]  pppd-dns 
[ - ] procps
[ - ] pulseaudio
 
->ntpq -p(验证服务)
 
root@ubuntu:/home/junliang# ntpq -p
      remote           refid      st t when poll reach   delay   offset  jitter
==============================================
   news.neu.edu.cn 202.118.1.46     2 u    -   64    1   85.222   -6.096   0.000
   time7.aliyun.co .INIT.          16 u    -   64    0    0.000    0.000   0.000
   ntp2.aliyun.com .INIT.          16 u    -   64    0    0.000    0.000   0.000
   ntp1.aliyun.com 10.137.38.86     2 u    1   64    1   31.265   -3.079   0.000
  juniperberry.ca .INIT.          16 u    -   64    0    0.000    0.000   0.000            
                          
ps:具体参数的含义可查看《鸟叔的Linux私房菜-服务器架设篇》,若是在线安装,并且主机可以连接到internet,则不用配置ntpd.conf文件中的server项否则需要配置用本机时间作为ntp服务器的时间源
 
完成了以上过程后,ntp client端可能还是不能连接到该服务器,此时还需执行下面的操作查看ntp server的防火墙是否开启。
 

由于NTP服务默认走UPD协议,使用123端口,如果启动防火墙的话,需要配置一下防火墙。vim /etc/sysconfig/iptables 打开防火墙配置文件。加入如下配置项:

#open port for NTP server

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

重启防火墙服务器  service iptables restart

NTP服务启动后大约需要3~5分钟的时间才会进行一次时间同步。可以通过命令ntpstat查看同步情况,只用NTP服务器同步成功后,NTP客户端才可以同来同步时间。如果需要立刻从指定的时间服务器同步时间,可以使用ntpdate 命令。使用ntpdate 命令时,需要先关闭ntp服务 service ntpd stop。然后执行 ntpdate NTPSERVERIP 即可立即完成时间的同步。

常用的NTP服务器以及NTP服务器配置过程

posted @ 2016-04-16 15:09  VincentFu  阅读(1266)  评论(0编辑  收藏  举报