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 条评论
登录 后参与评论

相关文章

来自专栏Youngxj

拦截黑客非法操作-无名智者保护伞

1565
来自专栏用户2442861的专栏

cmake教程二,变量以及flow control

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/haluoluo211/article/d...

572
来自专栏魏艾斯博客www.vpsss.net

解决 Winscp 不显示隐藏文件的办法

平时魏艾斯博客使用 Winscp 当做 SFTP 工具, 我们也经常遇到要修改.htaccess 和.user.ini 等等用.开头或者其他特殊扩展名文件,在 ...

3729
来自专栏云飞学编程

python小伙自制模板之家查询和下载文件的脚本

通过python的requests和lxml库,完成对模板之家免费模板的查询和下载功能(保存本地)

753
来自专栏魏艾斯博客www.vpsss.net

解决 Winscp 不显示隐藏文件的办法

742
来自专栏前端新视界

Yeoman 官网教学案例:使用 Yeoman 构建 WebApp

STEP 1:设置开发环境 ? 与 Yeoman 的所有交互都是通过命令行。Mac 系统使用 terminal.app,Linux 系统使用 shell,win...

1757
来自专栏nice_每一天

转载 Elasticsearch开发环境搭建(Eclipse\MyEclipse + Maven)

作者:好记性不如烂笔头! 出处:http://www.cnblogs.com/zlslch/

641
来自专栏机器之心

教程 | 只需15分钟,使用谷歌云平台运行Jupyter Notebook

选自Medium 机器之心编译 参与:路雪 近日,Amulya Aankul 在 Medium 上发表文章,描述他在谷歌云平台上运行 Jupyter Noteb...

3738
来自专栏维C果糖

详述 IntelliJ IDEA 创建 Maven 项目及设置 java 源目录的方法

Maven 是一个优秀的项目管理工具,它为我们提供了一个构建完整的生命周期框架。现在,就让我们一起看看如何利用 IntelliJ IDEA 快速的创建 Mave...

4809
来自专栏V站

PHP丨如何判断访客PC及PE端?(图片API配合使用)

手机双端比如自适应网站的站长来说还是比较有用的,使用它不但单纯的可以完美解决如何用PHP判断用户通过电脑端还是手机端访问网站,还可以实现一些实际的网站问题,比如...

1784

扫码关注云+社区