Ubuntu 16.04 NTP时间服务器安装配置

本文介绍了如何在Ubuntu 16.04上安装和配置NTP服务器,以实现内网服务器的时间同步。步骤包括安装ntp软件、修改配置文件以指定服务器和客户端、重启服务,以及解决同步问题。同时,强调了客户端也需要安装ntp并配置以同步时间。

      最近安装完全分布式部署hbase1.2.4,需要几台内网服务器时间保持同步,服务器为Ubuntu16.04.

     1.首先安装ntp软件(先联网安装软件,再切换回局域网):sudo apt-get intall ntp

    2.修改配置文件,sudo vim /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
             # Specify one or more NTP servers,因为是内网,所以用本地时间做为服务器时间,注意这里不是127.0.0.1
              server 127.127.1.0

            #我注释掉了这些东西

            #pool 0.ubuntu.pool.ntp.org iburst
            #pool 1.ubuntu.pool.ntp.org iburst
            #pool 2.ubuntu.pool.ntp.org iburst
            #pool 3.ubuntu.pool.ntp.org iburst
            # Use Ubuntu's ntp server as a fallback.
            #pool 127.127.1.0

            #增加了NTP服务器自身到时间服务器的同步

            fudge 127.127.1.0 stratum 8

           #增加了一些需要同步的客户端的ip

            restrict -4 default kod notrap nomodify nopeer noquery limited
            restrict -6 default kod notrap nomodify nopeer noquery limited
            restrict 133.16.157.34
            restrict 133.16.157.36

               restrict 127.0.0.1
               restrict ::1

                # Needed for adding pool entries
                restrict source notrap nomodify noquery

              加粗的部分是我主要改动的部分。

3. 重启ntp服务:sudo /etc/init.d/ntp restart

4.在需要同步时间的客户端运行ntpdate 133.16.157.35(ntp Server)即可同步时间,但经常报no suitable server......,可以到

  ntp server上执行ntpq -p查看。一般来说此错误是由于ntp server自身与时间服务器对时需要5分钟左右的时间造成。过一会儿,

如5分钟后,再在客户端执行ntpdate 133.16.157.35,提示同步完成。

5. 客户端配置
   如果你以为上面配置好了,局域网段的服务器就能和这台ntp server自动时间同步了,那就太天真了。
   还需要在需要同步时间的每台客户端上安装ntp, sudo apt-get install ntp,然后修改vim /etc/ntp.conf,增加server 133.16.157.35,

   然后重启客户端的ntp服务,sudo /etc/init.d/ntp restart,这样客户端就能和ntp server 进行时间同步了。




评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值