centos 局域网时间同步设置

来源:互联网 发布:linux下的echo命令 编辑:程序博客网 时间:2024/05/16 04:39

系统环境,请查看《virtualbox5.0.8 centos6.7 mini 安装》

规划:

192.168.56.2 时间同步服务端,局域网内以此服务器为时间源

其他同网段机器作为客户端,向192.168.56.2发起同步请求

在所有机器上安装ntp

yum -y install ntp

#设置开机启动

chkconfig ntpd on

#开启服务

service ntpd start



192.168.56.2 上配置

#删除/etc/ntp.conf所有内容

echo > /etc/ntp.conf


vi /etc/ntp.conf

#修改成以下内容

driftfile /var/lib/ntp/drift

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

restrict 127.0.0.1
restrict -6 ::1

#允许56.0网段同步

restrict 192.168.56.0 mask 255.255.255.0 nomodify notrap

includefile /etc/ntp/crypto/pw

keys /etc/ntp/keys

server 127.127.1.0     # local clock
fudge  127.127.1.0 stratum 10


#修改防火墙
vi /etc/sysconfig/iptables
在紧接着-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT    的下一行增加
#ntp
-A INPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCEPT
#重启防火墙
service iptables restart


#其他客户端机器设置

vi /etc/sysconfig/ntpd

#在最后新加一行

SYNC_HWCLOCK=yes


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

restrict 192.168.56.2 nomodify notrap noquery

server 192.168.56.2 iburst

includefile /etc/ntp/crypto/pw

keys /etc/ntp/keys

server  127.127.1.0     # local clock
fudge   127.127.1.0 stratum 10


#监视ntpd

ntpq -p


#正常情况出现

     remote           refid                    st t      when poll   reach   delay   offset       jitter
==============================================================================
*192.168.56.2    LOCAL(0)        11 u       41   64     377      0.249    0.004   0.165
 LOCAL(0)          .LOCL.              10 l   1071   64          0      0.000    0.000   0.000

0 0
原创粉丝点击