天天看点

局域网时间同步NTP服务架设

本文主要介绍当局域网内服务器不能连接外网,但是又必须保持各服务器时间同步

1.选用局域网内的其中一台机器做为ntp时间同步源服务器,其他节点机器从源时间同步服务器同步时间

例如我选用的机器为:172.16.19.156(机器名称:centos-1)

2.时间源同步服务器192.168.1.181安装NTP服务

yum -y install ntp

安装完成后配置/etc/ntp.conf文件,配置信息如下

# For more information about this file, see the man pages

# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).

driftfile /var/lib/ntp/drift

# Permit time synchronization with our time source, but do not

# permit the source to query or modify the service on this system.

restrict default kod nomodify notrap nopeer noquery

restrict -6 default kod nomodify notrap nopeer noquery

# Permit all access over the loopback interface.  This could

# be tightened as well, but to do so would effect some of

# the administrative functions.

restrict 127.0.0.1 

restrict -6 ::1

# Hosts on local network are less restricted.

#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.

# Please consider joining the pool (http://www.pool.ntp.org/join.html).

#server 0.rhel.pool.ntp.org

#server 1.rhel.pool.ntp.org

#server 2.rhel.pool.ntp.org

#broadcast 192.168.1.255 autokey        # broadcast server

#broadcastclient                        # broadcast client

#broadcast 224.0.1.1 autokey            # multicast server

#multicastclient 224.0.1.1              # multicast client

#manycastserver 239.255.254.254         # manycast server

#manycastclient 239.255.254.254 autokey # manycast client

# Undisciplined Local Clock. This is a fake driver intended for backup

# and when no outside source of synchronized time is available. 

#server 127.127.1.0     # local clock

#fudge  127.127.1.0 stratum 10

# Enable public key cryptography.

#crypto

includefile /etc/ntp/crypto/pw

# Key file containing the keys and key identifiers used when operating

# with symmetric key cryptography. 

keys /etc/ntp/keys

# Specify the key identifiers which are trusted.

#trustedkey 4 8 42

# Specify the key identifier to use with the ntpdc utility.

#requestkey 8

# Specify the key identifier to use with the ntpq utility.

#controlkey 8

# Enable writing of statistics records.

#statistics clockstats cryptostats loopstats peerstats

#server 127.127.1.0

server 127.127.1.0

fudge  127.127.1.0 stratum 10

变更内容为颜色标识位,主要是注释掉默认的时间同步服务器,改用本机做为本机的时间同步服务器

3.客户端配置,在此也采用ntp进行时间同步

yum -y install  ntp ntpdate

配置/etc/ntp.conf文件,变更内容如下图标识所示

# For more information about this file, see the man pages

# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).

driftfile /var/lib/ntp/drift

# Permit time synchronization with our time source, but do not

# permit the source to query or modify the service on this system.

restrict default kod nomodify notrap nopeer noquery

restrict -6 default kod nomodify notrap nopeer noquery

# Permit all access over the loopback interface.  This could

# be tightened as well, but to do so would effect some of

# the administrative functions.

restrict 127.0.0.1 

restrict -6 ::1

# Hosts on local network are less restricted.

#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.

# Please consider joining the pool (http://www.pool.ntp.org/join.html).

#注释如下server

#server 0.rhel.pool.ntp.org

#server 1.rhel.pool.ntp.org

#server 2.rhel.pool.ntp.org

#broadcast 192.168.1.255 autokey        # broadcast server

#broadcastclient                        # broadcast client

#broadcast 224.0.1.1 autokey            # multicast server

#multicastclient 224.0.1.1              # multicast client

#manycastserver 239.255.254.254         # manycast server

#manycastclient 239.255.254.254 autokey # manycast client

# Undisciplined Local Clock. This is a fake driver intended for backup

# and when no outside source of synchronized time is available. 

#server 127.127.1.0     # local clock

#fudge  127.127.1.0 stratum 10

# Enable public key cryptography.

#crypto

includefile /etc/ntp/crypto/pw

# Key file containing the keys and key identifiers used when operating

# with symmetric key cryptography. 

keys /etc/ntp/keys

# Specify the key identifiers which are trusted.

#trustedkey 4 8 42

# Specify the key identifier to use with the ntpdc utility.

#requestkey 8

# Specify the key identifier to use with the ntpq utility.

#controlkey 8

# Enable writing of statistics records.

#statistics clockstats cryptostats loopstats peerstats

#添加时间同步源服务器,在此设置172.16.19.156为时间源同步服务器

server centos-1 iburst

4.启动源时间同步服务器和设置开机启动

service ntpd start 

chkconfig ntpd on

5.启动客户端时间同步服务

service ntpd start 

chkconfig ntpd on

6.在源时间同步服务器上执行如下命令,查看是否正常采用本地时间同步

局域网时间同步NTP服务架设
局域网时间同步NTP服务架设

7.在客户端执行如下命令,查看是否正常从源时间服务器获取时间

局域网时间同步NTP服务架设
局域网时间同步NTP服务架设

8.刚启动的时候,执行ntpq -p时可能会提示一些错误,如果网络正常的话,一般是因为刚开始启动,还没有开始时间同步.一般5分钟后就会正常.如果有其他错误就需要具体分析了

ntp时间同步服务还是很容易架设的

继续阅读