1.1 ntp 集群时间同步服务

1.ntp集群时间同步服务规划

ntp.jpeg

2.具体操作

注:使用root用户操作。

校正个节点时区

1).查看当前系统时区(东八区),如果时区存在问题,需要校正

[root@hadoop104 ~]# date -R

Wed, 18 Oct 2017 14:39:01 +0800

2).删除当前系统时区

[root@hadoop104 ~]# sudo rm -rf /etc/localtime

3).通过软连接方式,设置本地系统时区

[root@hadoop104 ~]# ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

ntp-server端(hadoop104)配置

step1: 配置时间服务器前,手动联网同步校正时间

1).查看hadoop104节点的 ntpdate 服务工作状态(接下来需要手动与第三方网络时间服务器同步一次,ntpdate需要处于关闭状态)

[root@hadoop104 ~]# service ntpd status

ntpd (pid 1799) is running...

2).停止当前正在运行的ntpdate服务
[root@hadoop104 ~]# service ntpd stop

[root@hadoop104 ~]# service ntpd status

ntpd is stopped

3).与网络时间服务器手动同步(注:特殊情况下,无法访问 pool.ntp.org 时间服务器,可与 ntp1.aliyun.com 阿里云时间服务器进行同步)

[root@hadoop104 ~]# ntpdate pool.ntp.org

18 Oct 15:18:12 ntpdate[14323]: step time server 123.249.20.211 offset 34837488.962033 sec

[root@hadoop104 ~]# ntpdate pool.ntp.org

18 Oct 16:44:47 ntpdate[7739]: no server suitable for synchronization found

[root@hadoop104 ~]# ntpdate ntp1.aliyun.com

18 Oct 16:46:35 ntpdate[7743]: adjust time server 182.92.12.11 offset 0.001637 sec

4).配置定时任务,定期将系统时间同步给硬件时钟

[root@hadoop104 ~]# crontab -e

 # 每15min将系统时间(系统可以实时与网络同步)同步给硬件时钟

 */15 * * * * /sbin/hwclock -w

5).默认crond 服务随机启动,自动刷新,也可以通过以下方式手动刷新

[root@hadoop104 ~]# service crond restart

step2: ntpd-server节点配置ntp服务

[root@hadoop104 ~]# vim /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.
# ---------------------------------------------------------------------------------------
## 释放如下行的注释,运行1~255网段客户端过来同步时间
## nomodify 客户端不能使用ntpc与ntpq两支程式来修改服务器的时间参数
## notrap 不提供trap这个远程时间登录的功能
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:(屏蔽掉以后,hadoop104不能与网络时间同步,但集群内部时间是一致的)
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
# ---------------------------------------------------------------------------------------
# 将hadoop104的本地时钟作为时间供给源,这样,即便它失去网络连接,它也可以继续为网络提供服务;
server 127.127.1.0
fudge 127.127.1.0 stratum 10
# ---------------------------------------------------------------------------------------
step3: ntpd-server节点重启ntp服务

注:
1).前面初始化操作,停止了ntpd服务,而且修改了ntp.conf配置信息,需要重启ntpd服务才能时配置生效;
2).hadoop104 实时与第三方网络时间服务器同时时间同时,定期将系统时间同步给硬件时钟,并且对局域网内的hadoop102~3节点提供时间同步服务;
service ntpd status

ntpd is stopped

[root@hadoop104 share]# service ntpd start

Starting ntpd: [ OK ]

[root@hadoop104 share]# service ntpd status

ntpd (pid 14718) is running...

3).hadoop104节点的ntpd服务设置开启启动
[root@hadoop104 ~]# chkconfig ntpd on
[root@hadoop104 ~]# chkconfig ntpd --list

ntp-consumer端使用crond 周期性同步时间

1).停止 ntpd 服务(关闭自动同步,全部基于crontab,手动与 hadoop104进行同步)
[root@hadoop102 ~]# service ntpd stop
[root@hadoop102 ~]# service ntpd status

ntpd is stopped ...

关闭开机启动
[root@hadoop102 ~]# chkconfig ntpd off

2).配置定时任务,手动同步时间(测试阶段设置阶段每1min同步一次,以便检测同步效果,生产环境调整为10min同步一次)
[root@hadoop102 ~]# crontab -e

# 与时间服务器hadoop104同步频率 1(0)min/次 (分 时 日 月 周天)
*/1 * * * * /sbin/ntpdate hadoop104
# (30min/次) 将系统时间同步给硬件
*/30 * * * * /sbin/hwclock -w

3).故意修改hadoop102~103当前系统时间,测试能否通过时间同步,校正过来
[root@hadoop102 ~]# date -s '2016-10-10 10:10:10'

等待 ... 1min 让crond 生效 ...

4).SecureCRT客户端,对当前所有session用户同时发送date命令查看时间同步效果

[root@hadoopxxx ~]# date
date.jpeg

5).测试通过,hadoop102~3的定时任务,切换回,生产环境

[root@hadoop102 ~]# crontab -e

# 与时间服务器hadoop104同步频率 10min/次
*/10 * * * * /sbin/ntpdate hadoop104
# (30min/次) 将系统时间同步给硬件
*/30 * * * * /sbin/hwclock -w

6).默认crond 服务随机启动,自动刷新,也可以通过以下方式手动刷新
[root@hadoop102 ~]# service crond restart

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 157,298评论 4 360
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 66,701评论 1 290
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 107,078评论 0 237
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,687评论 0 202
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,018评论 3 286
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,410评论 1 211
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,729评论 2 310
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,412评论 0 194
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,124评论 1 239
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,379评论 2 242
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,903评论 1 257
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,268评论 2 251
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,894评论 3 233
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,014评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,770评论 0 192
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,435评论 2 269
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,312评论 2 260

推荐阅读更多精彩内容