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

ntpServer搭建用以进行时间同步

2016-11-23 16:49 411 查看
  在试各种乱七八糟的集群中,突然发现了一个问题,假如在一个闭网环境下安装某些集群软件的时候服务器之间的时间不同步(如HBase),会导致启动失败。那么就需要进行时间同步。可是往常都是网络校准的,没网的集群只能自己搞一个同步服务器了。

  查看资料之后发现这东西还是挺简单的,ntp自带server,只不过默认没用上而已,拿ubuntu来举例s:

sudo vim /etc/ntp.conf


    首先找到server ntp.ubuntu.com这一行,在下面加入如下两条,这代表着前面的server连不上时使用本地时间为其他机器校准:

server ntp.ubuntu.com
server 127.127.1.0
fudge 127.127.1.0 stratum 8


  再找到如下两行,然后把自己的网段放进去(这后面没加任何认证,毕竟内网):

restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery

restrict 192.168.12.0 mask 255.255.255.0


  然后重启服务就可以了

sudo /etc/init.d/ntp restart


  这时候,别的机器执行‘sudo ntp 服务IP’还是不可以,会出现一个:

no server suitable for synchronization found


  需要等待64*5秒之后才可以进行校准,可以使用命令查看情况:

Titan@cloud13:~/hbase/logs$ ntpq -p
remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
ntp02.cpe.rmutt 122.231.59.246   2 u  106   64    2  139.508   19.258   0.000
ntp.nic.kz      .INIT.          16 u    -   64    0    0.000    0.000   0.000
82.200.209.236  .INIT.          16 u    -   64    0    0.000    0.000   0.000
dadns.cdnetwork 204.123.2.5      2 u  106   64  126   69.146   -4.726   5.426
chilipepper.can 193.79.237.14    2 u   41   64  103  318.484   62.871   9.066
*LOCAL(0)        .LOCL.           8 l   53   64  177    0.000    0.000   0.000


View Code
  其中reach 大于17时其他机器就可以用此服务器进行校准了~~

sudo ntpdate IP


  如果出现

22 Dec 14:49:02 ntpdate[14906]: the NTP socket is in use, exiting

那么使用
sudo lsof -i:123
找到正在运行的ntp
然后sudo kill -9 pid


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: