Hadoop基础教程-第10章 HBase:Hadoop数据库(10.4 NTP时间同步)(草稿)

第10章 HBase:Hadoop数据库

10.4 NTP时间同步

10.4.1 为什么需要时间同步

HBase的HMaster和HRegionServer启动失败,大多是因为集群时间不同步造成的。需要定时进行集群时间同步。

10.4.1 ntp服务端

(1)安装ntp

[root@node1 ~]# yum install -y ntp
.....
Installing:
 ntp                                            x86_64                                4.2.6p5-25.el7.centos.2                                   updates                                547 k
Installing for dependencies:
 autogen-libopts                                x86_64                                5.18-5.el7                                                base                                    66 k
 ntpdate                                        x86_64                                4.2.6p5-25.el7.centos.2                                   updates                                 86 k

Transaction Summary
=============================================================================================================================================================================================
Install  1 Package (+2 Dependent packages)

Total download size: 699 k
Installed size: 1.6 M
Downloading packages:
(1/3): autogen-libopts-5.18-5.el7.x86_64.rpm                                                                                                                          |  66 kB  00:00:00     
(2/3): ntpdate-4.2.6p5-25.el7.centos.2.x86_64.rpm                                                                                                                     |  86 kB  00:00:00     
(3/3): ntp-4.2.6p5-25.el7.centos.2.x86_64.rpm                                                                                                                         | 547 kB  00:00:00     
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                        726 kB/s | 699 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : autogen-libopts-5.18-5.el7.x86_64                                                                                                                                         1/3 
  Installing : ntpdate-4.2.6p5-25.el7.centos.2.x86_64                                                                                                                                    2/3 
  Installing : ntp-4.2.6p5-25.el7.centos.2.x86_64                                                                                                                                        3/3 
  Verifying  : ntp-4.2.6p5-25.el7.centos.2.x86_64                                                                                                                                        1/3 
  Verifying  : ntpdate-4.2.6p5-25.el7.centos.2.x86_64                                                                                                                                    2/3 
  Verifying  : autogen-libopts-5.18-5.el7.x86_64                                                                                                                                         3/3 

Installed:
  ntp.x86_64 0:4.2.6p5-25.el7.centos.2                                                                                                                                                       

Dependency Installed:
  autogen-libopts.x86_64 0:5.18-5.el7                                                        ntpdate.x86_64 0:4.2.6p5-25.el7.centos.2                                                       

Complete!
[root@node1 ~]# 

(2)配置/etc/ntp.conf

[root@node1 ~]# vi /etc/ntp.conf

只需将#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap修改为 restrict 192.168.80.0 mask 255.255.255.0 nomodify notrap,给局域网内主机同步时间的权限,但不允许修改时间服务器的时间。 完整的配置文件如下:

[root@node1 ~]# cat /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

#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
[root@node1 ~]# 

(3)开机启动ntp

[root@node1 ~]# systemctl start ntpd
[root@node1 ~]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
[root@node1 ~]# 
[root@node1 ~]# systemctl status ntpd
● ntpd.service - Network Time Service
   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2017-07-25 10:40:48 EDT; 3min 18s ago
 Main PID: 2504 (ntpd)
   CGroup: /system.slice/ntpd.service
           └─2504 /usr/sbin/ntpd -u ntp:ntp -g

Jul 25 10:40:48 node1 ntpd[2504]: Listen and drop on 1 v6wildcard :: UDP 123
Jul 25 10:40:48 node1 ntpd[2504]: Listen normally on 2 lo 127.0.0.1 UDP 123
Jul 25 10:40:48 node1 ntpd[2504]: Listen normally on 3 ens32 192.168.80.131 UDP 123
Jul 25 10:40:48 node1 ntpd[2504]: Listen normally on 4 lo ::1 UDP 123
Jul 25 10:40:48 node1 ntpd[2504]: Listen normally on 5 ens32 fe80::20c:29ff:fe9c:13bd UDP 123
Jul 25 10:40:48 node1 ntpd[2504]: Listening on routing socket on fd #22 for interface updates
Jul 25 10:40:48 node1 ntpd[2504]: 0.0.0.0 c016 06 restart
Jul 25 10:40:48 node1 ntpd[2504]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM
Jul 25 10:40:48 node1 ntpd[2504]: 0.0.0.0 c011 01 freq_not_set
Jul 25 10:40:55 node1 ntpd[2504]: 0.0.0.0 c614 04 freq_mode
[root@node1 ~]# 

10.4.2 ntp客户端

安装ntp客户端,只需安装ntpdate

[root@node2 ~]# yum install -y ntpdate
[root@node3 ~]# yum install -y ntpdate

时间同步

[root@node2 ~]# ntpdate 192.168.80.131
25 Jul 11:03:47 ntpdate[2243]: adjust time server 192.168.80.131 offset -0.014726 sec
[root@node2 ~]#
[root@node3 ~]# ntpdate 192.168.80.131
25 Jul 11:03:35 ntpdate[2228]: adjust time server 192.168.80.131 offset -0.034661 sec
[root@node3 ~]#

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏三杯水

DNS主从服务器搭建

http://blog.51cto.com/yichenyang/1911098 http://blog.51cto.com/wubinary/1379595

22120
来自专栏我的博客

Lumen5.X使用频率限制组件笔记

编写中间件,是根据vendor/illuminate/routing/Middleware/ThrottleRequests.php改写 备注:需要先...

408120
来自专栏运维

DNS主从服务器搭建

http://blog.51cto.com/yichenyang/1911098 http://blog.51cto.com/wubinary/1379595

20110
来自专栏Objective-C

iOS-安装和使用 CocoaPods

55170
来自专栏Laoqi's Linux运维专列

LAMP安装mysql 时遇到的问题汇总

1: 缺少 libaio 包, libaio是Linux下的一个异步非阻塞方式读写文件的接口。 1 2 3 [[email protect...

40160
来自专栏Python与爬虫

佛系编程[如何创建一个安全可靠的应用程序]

推荐最近在GitHub上很火的一个项目,按照介绍,你也可以创建一个安全可靠的应用程序 项目地址在>>> nocode https://github.com/k...

46190
来自专栏懒人开发

docker安装

http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

43340
来自专栏Duncan's Blog

springmvc-mybatis

本文基于原文http://doc.okbase.net/fengshizty/archive/126397.html配置环境。 首先说说几个问题 1.关于Myb...

15030
来自专栏乐沙弥的世界

[ERROR] WSREP no such a transition REPLICATING

满心欢喜的测试高大上的PXC,还没折腾几天就碰到了Bug,主要的错误提示为[ERROR] WSREP: FSM: no such a transition RE...

19020
来自专栏程序猿DD

Spring Cloud Feign的文件上传实现

在Spring Cloud封装的Feign中并不直接支持传文件,但可以通过引入Feign的扩展包来实现,本文就来具体说说如何实现。 ? 服务提供方(接收文件) ...

459110

扫码关注云+社区

领取腾讯云代金券