Spark on Yarn+Hbase环境搭建指南(四)NTP服务设置

来源:互联网 发布:老炮儿网络剧 编辑:程序博客网 时间:2024/06/05 06:13

一、简介

    NTP(Network Time Protocol)是运行在传输层的协议,使用123端口的UDP,它允许计算机在网络上同步时间。NTP同步方式分为:使用ntpdate命令直接同步和使用NTPD服务平滑同步。区别为:使用ntpdate同步则操作系统时间立即更新,可能会导致定时执行等任务重复执行。NTPD服务方式平滑同步时间,每次同步时间的偏移量不会太陡,逐步同步。为了HBase安装过程顺利,强烈建议先设置NTP,否则可能出现莫名其妙的状况。

二、设计

    一台连接外网的服务器与外部服务器同步时间,其余内网服务器与此服务器同步。

三、安装

1)     查看客户端和服务端服务器ntp rpm包是否安装

#rpm –qa|grep ntp

如果有ntp和ntpdate则表示已安装。

2)     如果未安装,则使用如下指令安装。

#yum install ntp

四、配置NTP-Server

1)编辑ntp.conf文件

#vi /etc/ntp.conf

本次配置如下:

#drift file

driftfile /var/lib/ntp/drift

#restrict default nomodify notrap nopeer noquery

restrict 127.0.0.1

restrict ::1

#限制本地机器访问,注意根据实际情况修改

restrict 192.168.8.0 mask 255.255.255.0 nomodify notrap

#或者不做限制

restrict default ignore

#public servers

server 0.centos.pool.ntp.org iburst

#undisiplined local clock  注意:非127.0.0.1在无外部时钟源时,可以降低strtum

server 127.127.1.0 prefer

fudge 127.127.1.0 stratum 8

#logs

logfile /var/log/ntp.log

#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

2)启动NTP Daemon

前提:防火墙已关闭

    #systemctl stop ntpd

#systemctl enable ntpd

#systemctl status ntpd

#设置为重启后自动启动

#chkconfig ntpd on

3)验证Server时间同步状态

NTP daemon启动后,等待几分钟(一般最多15分钟,也有1小时多的)。NTP将与系统配置的Server进行同步。

通过如下指令查看网络中的NTP服务器以及服务器和客户端关系。

#ntpq –p

一般delay和offset非0(同步本机的可能是0),jitter小于0.

查看系统时间:

#date –R

通过如下指令查看服务连接和监听:

#netstat –tlunp|grep ntp

查看时间同步状态,一般需要5-10分钟才能成功连接和同步。刚启动时一般显示:unsynchronised time serverre-starting pooling server every 64s,连接并同步后显示:synchronised to NTP server (xxx)at statum 3.指令如下:

#ntpstat

如果出现问题,查看日志信息:

#cat /var/log/messages

如果想要查询所配置的时钟服务器或者同步,则使用ntpdate指令,参数可使用ntpdate –help查看,其中-d为查看详细信息。如果同步成功,则会显示类似adjust time server 192.168.8.250offset -0.003264sec的信息:

#ntpdate –d 192.168.8.250

五、配置NTP-Client

1)编辑ntp.conf文件

#vi /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 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 ::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.centos.pool.ntp.org iburst

#server 1.centos.pool.ntp.org iburst

#server 2.centos.pool.ntp.org iburst

#server 3.centos.pool.ntp.org iburst

#之前所配置的ntp server

server 192.168.8.250

restrict 192.168.8.250 nomodify notrap noquery

sever 127.127.1.0 fudge

127.127.1.0 stratum 8

#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

# 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

# Disable the monitoring facility to prevent amplification attacks using ntpdc

# monlist command when default restrict does not include the noquery flag. See

# CVE-2013-5211 for more details.

# Note: Monitoring will not be disabled with the limited restriction flag.

disable monitor

2)启动NTP Daemon

#systemctl stop ntpd

#systemctl enable ntpd

#systemctl status ntpd

#设置为重启后自动启动

#chkconfig ntpd on

3)验证

同NTP-Server部分。

六、配置中所遇问题

1) ntpq指令出现:name or service not known:

解决:

修改/etc/hosts,增加

127.0.0.1 localhost

2) ntpdate指令出现:Strata too high

连不到外网服务器又未配置Undisciplined Local Clock。参考配置文件中Undisciplined Local Clock配置即可。


0 0