linux ntp时间同步(内网)

操作环境:centos 6.7

服务器IP角色说明
192.168.6.61NTPD服务器作为内外网络的NTPD服务
192.168.6.62NTPD客户端内网设备与192.168.6.61时间同步
192.168.6.63NTPD客户端内网设备与192.168.6.61时间同步
192.168.6.64NTPD客户端内网设备与192.168.6.61时间同步
192.168.6.65NTPD客户端内网设备与192.168.6.61时间同步

1.安装ntp时间服务器(所有机器)

1.1 yum安装方式:#yum install -y ntp
1.2 tar包安装方式:

tar -zxvf ntp-4.2.8p8.tar.gz
cd ntp-4.2.8p8
./configure --prefix=/usr/local/ntp --enable-all-clocks --enable-parse-clocks
make && make install

 

rpm -q ntp #查看是否安装成功

2.设置ntp服务为开机自启动(所有机器)

chkconfig ntpd on

[root@mini1 ~]# chkconfig --list ntpd
ntpd            0:关闭    1:关闭    2:启用    3:启用    4:启用    5:启用    6:关闭

3.设置NTP Server

vi /etc/ntp.conf


driftfile /var/lib/ntp/drift

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

restrict 127.0.0.1 
restrict -6 ::1

#允许192.168.6网段机器同步时间
restrict 192.168.6.0 mask 255.255.255.0 nomodify notrap

#远程时间服务器的地址
server 210.72.145.44 perfer #中国国家授时中心
server 1.cn.pool.ntp.org

#允许上层服务器主动修改本机时间
restrict 210.72.145.44 nomodify notrap noquery
restrict 1.cn.pool.ntp.ofg nomodify notrap noquery

#外部时间服务器不可用时,以本地时间作为时间服务
server 127.127.1.0
fudge  127.127.1.0 stratum 10 

includefile /etc/ntp/crypto/pw

keys /etc/ntp/keys

4.设置NTP client

vi /etc/ntp.conf

driftfile /var/lib/ntp/drift
restrict 127.0.0.配置只有192.168.6这个网段的可以从本NTP 服务器同步时间
server 192.168.6.61
restrict 210.72.145.44 nomodify notrap noquery
restrict 1.cn.pool.ntp.ofg nomodify notrap noquery
#允许上层时间服务器主动修改本机时间

#远程时间服务器的地址
includefile210.72.145.44 perfer #中国国家授时中心
includefile1.cn.pool.ntp.ofg

keys /etc/ntp/keys

5.重启ntpd服务(所有机器)

service ntpd restart

6.查看NTP服务

ntpq -p        #NTP Server

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 210.72.145.44   .INIT.          16 -    -  256    0    0.000    0.000   0.000
*LOCAL(0)        .LOCL.          10 l    -   64  377    0.000    0.000   0.000

ntpq -p        #NTP Client

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*mini1           LOCAL(0)        11 u   60   64    7    0.334   -0.487   0.034

查看时间同步状态,一般需要5-10分钟后才能成功连接和同步。所以,服务器启动后需要稍等下。

ntpstat

刚启动时时:unsynchronised

启动并连接同步后:
synchronised to NTP server (192.168.6.61) at stratum 12
time correct to within 263 ms
polling server every 64 s

 

  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值