如何使用npt结合crontab实现集群之间的时间同步
当我们每个机器的时间都不一致时,假如有一个定时任务,定的10点启动执行。结果namenode十点了启动任务,可是分配到的执行节点DataNode才九点五十导致任务执行失败怎么办?
这就需要将机器之间的时间保持一致
时间同步方式:找一台机器,作为时间服务器,所有的机器与这台机器的时间进行同步,如每隔十分钟同步一次。
操作
切换到root用户检查是否安装了ntp
我们以102作为我们的时间主机,向其他机器发布同步时间
[shaozhiqi@hadoop102 ~]$ su root
Password:
[root@hadoop102 shaozhiqi]# rpm -qa|grep ntp
ntp-4.2.6p5-25.el7.centos.2.x86_64
fontpackages-filesystem-1.44-8.el7.noarch
ntpdate-4.2.6p5-25.el7.centos.2.x86_64
python-ntplib-0.3.2-1.el7.noarch
[root@hadoop102 shaozhiqi]#查
编辑ntp的配置文件
我里面带//的注释在配置时应该删除,这里为了方便说明
[root@hadoop102 shaozhiqi]# vim /etc/ntp.conf
# 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](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 //我们操作注掉
//添加节点,当上述机器的丢失网略,还可以作为集群的时间同步机器
server 127.127.1.0
fudge 127.127.0 stratum 10
修改/etc/sysconfig/ntpd,让硬件时间和系统时间一起同步,加上保险些
[root@hadoop102 ~]# vim /etc/sysconfig/ntpd
# Command line options for ntpd
OPTIONS="-g"
SYNC_HWCLOCK=yes
重启102的时间同步
先查看状态是 Active: inactive (dead)
[root@hadoop102 ~]# service ntpd status
Redirecting to /bin/systemctl status ntpd.service
● ntpd.service - Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)
Active: inactive (dead)
[root@hadoop102 ~]#
启动后台查看状态是Active: active (running)
[root@hadoop102 ~]# service ntpd status
Redirecting to /bin/systemctl status ntpd.service
● ntpd.service - Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)
Active: active (running) since Sat 2019-06-29 11:33:51 CST; 12s ago
Process: 3174 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 3176 (ntpd)
CGroup: /system.slice/ntpd.service
└─3176 /usr/sbin/ntpd -u ntp:ntp -g
Jun 29 11:33:51 hadoop102 ntpd[3176]: Listen normally on 2 lo 127.0.0.1 UDP 123
Jun 29 11:33:51 hadoop102 ntpd[3176]: Listen normally on 3 eth0 192.168.1.102 UDP 123
Jun 29 11:33:51 hadoop102 ntpd[3176]: Listen normally on 4 virbr0 192.168.122.1 UDP 123
Jun 29 11:33:51 hadoop102 ntpd[3176]: Listen normally on 5 lo ::1 UDP 123
Jun 29 11:33:51 hadoop102 ntpd[3176]: Listen normally on 6 eth0 fe80::250:56ff:fe3a:7b92 UDP 123
Jun 29 11:33:51 hadoop102 ntpd[3176]: Listening on routing socket on fd #23 for interface updates
Jun 29 11:33:51 hadoop102 ntpd[3176]: 0.0.0.0 c016 06 restart
Jun 29 11:33:51 hadoop102 ntpd[3176]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM
Jun 29 11:33:51 hadoop102 ntpd[3176]: 0.0.0.0 c011 01 freq_not_set
Jun 29 11:33:52 hadoop102 ntpd[3176]: 0.0.0.0 c514 04 freq_mode
[root@hadoop102 ~]#
设置永久启动
[root@hadoop102 ~]# chkconfig ntpd on
Note: Forwarding request to 'systemctl enable ntpd.service'.
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
[root@hadoop102 ~]#
102机器配置结束
配置103/104 在root用户
其他机器每隔10分支与时间服务器同步一次
crontab –e 表示要去编写crate脚本,e代表编辑
103机器
[root@hadoop103 ~]# crontab -e
no crontab for root - using an empty one
*/10 * * * * /usr/sbin/ntpdate hadoop102
104 机器
[root@hadoop104 ~]# crontab -e
no crontab for root - using an empty one
*/10 * * * * /usr/sbin/ntpdate hadoop102
配置结束
验证
修改时间语法:date -s "2019-6-28 10:10:10"//表示修改当前机器的时间点为某个时间
验证:修改103的时间,今天是29号我们改为28号,看等会会不会同步
[root@hadoop103 ~]# date
Sat Jun 29 11:52:44 CST 2019
[root@hadoop103 ~]# date -s "2019-6-28 10:10:10"
Fri Jun 28 10:10:10 CST 2019
[root@hadoop103 ~]# date
Fri Jun 28 10:10:18 CST 2019
[root@hadoop103 ~]#
验证:同样修改104的时间,今天是29号我们改为28号,看等会会不会同步
[root@hadoop104 ~]# date
Sat Jun 29 11:53:50 CST 2019
[root@hadoop104 ~]# date -s "2019-6-28 10:10:10"
Fri Jun 28 10:10:10 CST 2019
[root@hadoop104 ~]# date
Fri Jun 28 10:10:15 CST 2019
[root@hadoop104 ~]#
验证结果:103
[root@hadoop103 ~]# date
Fri Jun 28 10:10:18 CST 2019
[root@hadoop103 ~]# date
Sat Jun 29 11:55:42 CST 2019
[root@hadoop103 ~]#
验证结果:104
[root@hadoop104 ~]# date
Fri Jun 28 10:10:15 CST 2019
[root@hadoop104 ~]# date
Sat Jun 29 11:56:19 CST 2019
[root@hadoop104 ~]#
配置成功 O(∩_∩)O哈哈~
如何使用npt结合crontab实现集群之间的时间同步的更多相关文章
- Linux集群部署自定义时间同步服务器(ntpd)
Linux集群部署自定义时间同步服务器(ntpd) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 身为一名运维人员,在搭建集群的时候,第一步需要做的就是同步每个机器的时间,尤其是在 ...
- 在不同版本号hdfs集群之间转移数据
在不同版本号hdfs集群之间转移数据 最简单的办法就是把src集群的数据导到本地,然后起还有一个进程将本地数据传到des集群上去. 只是这有几个问题: 效率减少 占用本地磁盘空间 不能应付实时 ...
- 面向接口编程实现不改代码实现Redis单机/集群之间的切换
开发中一般使用Redis单机,线上使用Redis集群,因此需要实现单机和集群之间的灵活切换 pom配置: <!-- Redis客户端 --> <dependency> < ...
- DistCp 集群之间数据拷贝工具
DistCp(分布式拷贝)是用于大规模集群内部和集群之间拷贝的工具.可以将数据拷贝到另个一集群,也可以将另一个集群的数据拷贝到本集群.
- 集群之间配置 SSH无密码登录
集群之间配置 SSH无密码登录 配置 ssh (1)基本语法 ssh 另一台电脑的 ip 地址 (2)ssh 连接时出现 Host key verification failed 的解决方法 # ss ...
- elasticsearch基于RBAC认证和集群之间的TLS通讯
elasticsearch基于RBAC认证和集群之间的TLS通讯 一.背景 二.需要解决的问题 三.给es增加用户名和密码访问 1.修改config/elasticsearch.yml 2.访问es集 ...
- Hadoop集群搭建中时间同步步骤
一.设置主节点时间服务器的时区 二.在每一个节点上检查是否安装时间服务ntp 三.在主节点上配置时间同步的相关文件 四.在其他从节点上配置与主节点时间同步的脚本 一.设 ...
- shell 脚本实战笔记(3)--集群机器的时间同步设置
背景: 有些分布式服务(比如HBase服务), 依赖于系统时间戳, 如果集群各个节点, 系统时间不一致, 导致服务出现诡异的情况. 解决方案: 那如何同步集群各个节点之间的时间? 采用NTP(Netw ...
- Linux集群配置ntp时间同步服务
集群中时间不同步有可能会让大数据的应用程序运行混乱,造成不可预知的问题,比如Hbase,当时间差别过大时就会挂掉,所以在大数据集群中,ntp服务,应该作为一种基础的服务,以下在演示在CentOS 7. ...
随机推荐
- ElasticSearch之映射常用操作
本文案例操作,建议先阅读我之前的文章<ElasticSearch之安装及基本操作API> Mapping (映射)类似关系型数据库中的表的结构定义.我们将数据以 JSON 格式存入到 El ...
- qt creator源码全方面分析(3-5)
目录 qtcreatorlibrary.pri 使用实例 上半部 下半部 结果 qtcreatorlibrary.pri 上一章节,我们介绍了src.pro,这里乘此机会,把src目录下的所有项目文件 ...
- 基于Ubuntu的ORB-SLAM2项目环境搭建过程
目录 关于ORB-SLAM2 环境搭建 已有环境 创建环境 新建项目目录 安装Pangolin 安装OpenCV 3.2 安装Eigen DBoW2 and g2o (Included in Thir ...
- 高性能-GC
带着问题去思考!大家好 相对.NET 来说.CLR去处理了,C,C++这些就需要手动去垃圾回收. GC大部分容易察觉的性能问题.其实很多问题实际是哪个都是由于对垃圾回收器的行为和预期结果理解有误.在, ...
- ECharts的使用与总结
ECharts的使用与总结 一,介绍与需求 1.1,介绍 ECharts商业级数据图表,一个纯Javascript的图表库,可以流畅的运行在PC和移动设备上,兼容当前绝大部分浏览器(IE6/7/8/9 ...
- 2019HECTF总结_web题
奇怪的编码 ♭|§∮♯♭|§∮♬♭|§§♫♭|§∮§♭|§♩§♭|♯♬¶♭|§§♫♭|§§¶♭|♯¶§♭|♯¶♫♭|§∮♭♭|§§♫♭|§§♬♭|♯♬♪♭|♯¶♪♭|♯¶|♭|♯¶♯♭|♯♬♬♭|♯♬ ...
- vue one one
目录 Vue 渐进式 JavaScript 框架 一.走进Vue 1.what -- 什么是Vue 2.why -- 为什么要学习Vue 3.special -- 特点 4.how -- 如何使用Vu ...
- CDNbest-设置不缓存
写在开始之前 有时候根据业务需求,我们网站不需要缓存,这时候就需要设置下 让网站不走缓存 步骤一 登录平台找到我们的站点->站点设置->缓存设置 如图 备注:填写需要操作的域名,时间为&q ...
- [kmp,不要过多调用strlen!!!] Codeforces 1200E Compress Words
题目:http://codeforces.com/contest/1200/problem/E Compress Words time limit per test 1 second memory l ...
- 服务器安装 mongodb
参考 https://www.cnblogs.com/layezi/p/7290082.html