您的位置:首页 > 编程语言 > PHP开发

ubuntu上搭建ntp时间服务器

2015-07-30 00:07 495 查看
ubuntu上搭建ntp时间服务器的步骤如下:

1.安装ntp

sudo apt-get install ntp

2.修改配置文件

sudo vim /etc/ntp.conf

在/etc/ntp.conf里面添加以下内容:

    driftfile /var/lib/ntp/ntp.drift

    statistics loopstats peerstats clockstats

    filegen loopstats file loopstats type day enable

    filegen peerstats file peerstats type day enable

    filegen clockstats file clockstats type day enable

    server ntp.ubuntu.com

    restrict -4 default kod notrap nomodify nopeer noquery

    restrict -6 default kod notrap nomodify nopeer noquery

    restrict 192.168.0.0 mask 255.255.255.0 nomodify

    restrict 127.0.0.1

    restrict ::1

说明:

  主要是在配置文件中加入:

  restrict 192.168.0.0 mask 255.255.255.0 nomodify

  restrict 192.168.0.0 mask 255.255.255.0 nomodify---主要是允许能同步的服务器所在的内部网段

  权限设定主要以restrict这个参数来设定,主要的语法为:

  restrict IP mask netmask_IP parameter

  其中IP可以是软体位址,也可以是 default ,default 就类似0.0.0.0

  至于 paramter则有:

  ignore:关闭所有的NTP 连线服务

  nomodify:表示Client 端不能更改 Server 端的时间参数,不过Client端仍然可以透过Server 端來进行网络较时。

  notrust:该 Client 除非通过认证,否则该 Client 来源将被视为不信任网域

  noquery:不提供 Client 端的时间查询

  如果 paramter完全没有设定,那就表示该 IP (或网域) 『没有任何限制!』

3.取消防火墙对123端口的限制

iptables -t filter -A INPUT -p udp --destination-port 123 -j ACCEPT

4.重启ntp服务

sudo /etc/init.d/ntp restart

5.在客户机上安装ntpdate

sudo apt-get install ntpdate

6.在客户端上同步时间

sudo ntpdate 192.168.0.10

  **可能出现的错误

  (1)在客户端上执行 sudo ntpdate 192.168.0.10命令同步时间的时候出现错误提示:no server suitable for synchronization found 

  原因:

  在ntp 服务器上重新启动ntp服务后,ntp 服务器自身或者与其自身的同步需要一个时间段,这个过程可能是3-5分钟,在这个时间之内在客户端上运行sudo ntpdate 192.168.0.10命令时会产生no server suitable
for synchronization found的错误。所以要等几分钟后再在客户端上执行同步时间的命令。

  (2)等一段时间后仍然提示:no server suitable for synchronization found,执行sudo ntpdate -d 192.168.0.10后会看到错误提示:Server
dropped: Strata too high,并且显示“stratum 16”。而正常情况下stratum这个值得范围0-15。

原因:ntp服务器还没有和其自身或者它的时间服务器的时间同步上,可能是没有连接外网,不能和server
ntp.ubuntu.com的时间同步。

这里我先设置好ntp
server的时间,在/etc/ntp.conf里面添加如下两行:

server 127.127.1.0


fudge 127.127.1.0 stratum 8

即使用local时间作为ntp服务提供给ntp客户端。

执行watch ntpq -p可以查看ntp server和自身同步的过程。当reach这个值增加到17的时候,就可以在客户端执行同步时间的命令了。

参考资料:http://www.blogjava.net/spray/archive/2008/07/10/213964.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: