NTP服务器时间集群借节点之间同步

1、三个节点时间同步,cdh1,cdh2,cdh3

2、做法:cdh1从网络时间同步,然后cdh2和cdh3从cdh1节点同步

3、安装与自启动设置

yum install ntp

按上面的安装方式在内网每台节点上都安装好NTP软件包

完成后,都需要配置NTP服务为自启动

chkconfig ntpd on

chkconfig --list ntpd

ntpd           0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭

如果2,3,4,5都为启动,则正常。

在配置前,先使用ntpdate手动同步下时间,免得本机与外部时间服务器时间差距太大,让ntpd不能正常同步。

ntpdate -u cn.ntp.org.cn

4、配置cdh1的/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.189.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 cn.ntp.org.cn perfer

#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
# 允许上层时间服务器主动修改本机时间
restrict cn.ntp.org.cn nomodify notrap noquery

# 外部时间服务器不可用时,以本地时间作为时间服务
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

5、启动ntp服务

service ntpd start

启动后,一般需要5-10分钟左右的时候才能与外部时间服务器开始同步时间。

6、通过watch ntpq -p  查看网络ntp服务器

 

7、然后去cdh2和cdh3去修改/ect/ntp.conf,向cdh1同步时间

修改一行:server cdh1

8、分别在cdh2和cdh3启动ntp

service ntpd start

9、其他命令

service ntpd restart 重启ntp

service ntpd stop 停止ntp

ntpstat 命令查看时间同步状态,这个一般需要5-10分钟后才能成功连接和同步

[root@cdh2 opt]# ntpstat
synchronised to NTP server (192.168.189.128) at stratum 4
   time correct to within 48 ms
   polling server every 64 s

 

posted @ 2017-11-20 16:16  麻雀虽小五脏俱全  阅读(2655)  评论(0编辑  收藏  举报