吃颗糖果 發表於 2020-7-18 14:31:00

Linux 集群时间同步(Ubuntu)

<p>在配置hadoop集群时,时间同步是必须要做的,否则会出现各种意想不到的问题。</p>
<p>hadoop102 为 ntp server,hadoop103以及hadoop104 为ntp client(即需要同步时间机器)</p>
<p>1.全部机器都要安装ntp以及ntpdate</p>
<div class="cnblogs_code">
<pre>sudo apt-<span style="color: rgba(0, 0, 255, 1)">get</span> install ntp</pre>
</div>
<div class="cnblogs_code">
<pre>sudo apt-<span style="color: rgba(0, 0, 255, 1)">get</span> install ntpdate</pre>
</div>
<p>2.关闭所有的机器的ntp,每个机器执行命令 一下命令</p>
<div class="cnblogs_code">
<pre>sudo service ntp stop </pre>
</div>
<p>查看ntp状态</p>
<div class="cnblogs_code">
<pre>sudo service ntp status</pre>
</div>
<p>3.修改ntp server即hadoop102的/etc/ntp.conf文件</p>
<div class="cnblogs_code">
<pre>sudo vim /etc/ntp.conf</pre>
</div>
<p>相关条文解释,参考https://www.cnblogs.com/xwdreamer/p/3448773.html</p>
<div class="cnblogs_code">
<pre># /etc/ntp.conf, configuration <span style="color: rgba(0, 0, 255, 1)">for</span> ntpd; see ntp.conf(<span style="color: rgba(128, 0, 128, 1)">5</span>) <span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> help

driftfile </span>/<span style="color: rgba(0, 0, 255, 1)">var</span>/lib/ntp/<span style="color: rgba(0, 0, 0, 1)">ntp.drift

# Leap seconds definition provided by tzdata
leapfile </span>/usr/share/zoneinfo/leap-<span style="color: rgba(0, 0, 0, 1)">seconds.list

# Enable </span><span style="color: rgba(0, 0, 255, 1)">this</span> <span style="color: rgba(0, 0, 255, 1)">if</span><span style="color: rgba(0, 0, 0, 1)"> you want statistics to be logged.
#statsdir </span>/<span style="color: rgba(0, 0, 255, 1)">var</span>/log/ntpstats/<span style="color: rgba(0, 0, 0, 1)">

statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable

# Specify one or more NTP servers.

# Use servers </span><span style="color: rgba(0, 0, 255, 1)">from</span><span style="color: rgba(0, 0, 0, 1)"> the NTP Pool Project. Approved by Ubuntu Technical Board
# on </span><span style="color: rgba(128, 0, 128, 1)">2011</span>-<span style="color: rgba(128, 0, 128, 1)">02</span>-<span style="color: rgba(128, 0, 128, 1)">08</span> (LP: #<span style="color: rgba(128, 0, 128, 1)">104525</span>). See http:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">www.pool.ntp.org/join.html for</span>
<span style="color: rgba(0, 0, 0, 1)"># more information.
pool </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">.ubuntu.pool.ntp.org iburst
pool </span><span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">.ubuntu.pool.ntp.org iburst
pool </span><span style="color: rgba(128, 0, 128, 1)">2</span><span style="color: rgba(0, 0, 0, 1)">.ubuntu.pool.ntp.org iburst
pool </span><span style="color: rgba(128, 0, 128, 1)">3</span><span style="color: rgba(0, 0, 0, 1)">.ubuntu.pool.ntp.org iburst

# Use Ubuntu</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">s ntp server as a fallback.</span>
<span style="color: rgba(0, 0, 0, 1)">pool ntp.ubuntu.com

# Access control configuration; see </span>/usr/share/doc/ntp-doc/html/accopt.html <span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)">
# details.The web page </span>&lt;http:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">support.ntp.org/bin/view/Support/AccessRestrictions&gt;</span>
<span style="color: rgba(0, 0, 0, 1)"># might also be helpful.
#
# Note that </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">restrict</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)"> applies to both servers and clients, so a configuration
# that might be intended to block requests </span><span style="color: rgba(0, 0, 255, 1)">from</span><span style="color: rgba(0, 0, 0, 1)"> certain clients could also end
# up blocking replies </span><span style="color: rgba(0, 0, 255, 1)">from</span><span style="color: rgba(0, 0, 0, 1)"> your own upstream servers.

# By </span><span style="color: rgba(0, 0, 255, 1)">default</span>, exchange time with everybody, but don<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">t allow configuration.</span>
restrict -<span style="color: rgba(128, 0, 128, 1)">4</span> <span style="color: rgba(0, 0, 255, 1)">default</span><span style="color: rgba(0, 0, 0, 1)"> kod notrap nomodify nopeer noquery limited
restrict </span>-<span style="color: rgba(128, 0, 128, 1)">6</span> <span style="color: rgba(0, 0, 255, 1)">default</span><span style="color: rgba(0, 0, 0, 1)"> kod notrap nomodify nopeer noquery limited

# Local users may interrogate the ntp server more closely.
restrict </span><span style="color: rgba(128, 0, 128, 1)">127.0</span>.<span style="color: rgba(128, 0, 128, 1)">0.1</span><span style="color: rgba(0, 0, 0, 1)">
restrict ::</span><span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">

# Needed </span><span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> adding pool entries
restrict source notrap nomodify noquery

# Clients </span><span style="color: rgba(0, 0, 255, 1)">from</span> <span style="color: rgba(0, 0, 255, 1)">this</span> (example!) subnet have unlimited access, but only <span style="color: rgba(0, 0, 255, 1)">if</span><span style="color: rgba(0, 0, 0, 1)">
# cryptographically authenticated.
#restrict </span><span style="color: rgba(128, 0, 128, 1)">192.168</span>.<span style="color: rgba(128, 0, 128, 1)">123.0</span> mask <span style="color: rgba(128, 0, 128, 1)">255.255</span>.<span style="color: rgba(128, 0, 128, 1)">255.0</span><span style="color: rgba(0, 0, 0, 1)"> notrust


# If you want to provide time to your local subnet, change the next line.
# (Again, the address </span><span style="color: rgba(0, 0, 255, 1)">is</span><span style="color: rgba(0, 0, 0, 1)"> an example only.)
#broadcast </span><span style="color: rgba(128, 0, 128, 1)">192.168</span>.<span style="color: rgba(128, 0, 128, 1)">123.255</span><span style="color: rgba(0, 0, 0, 1)">

# If you want to listen to time broadcasts on your local subnet, de</span>-<span style="color: rgba(0, 0, 0, 1)">comment the
# next lines.Please </span><span style="color: rgba(0, 0, 255, 1)">do</span> <span style="color: rgba(0, 0, 255, 1)">this</span> only <span style="color: rgba(0, 0, 255, 1)">if</span> you trust everybody on the network!<span style="color: rgba(0, 0, 0, 1)">
#disable auth
#broadcastclient</span></pre>
</div>
<p>改为如下后保存:</p>
<div class="cnblogs_code">
<pre># /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for<span> help

driftfile /var/lib/ntp/<span>ntp.drift

# Leap seconds definition provided by tzdata
leapfile /usr/share/zoneinfo/leap-<span>seconds.list

# Enable this if<span> you want statistics to be logged.
#statsdir /var/log/ntpstats/<span>

statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable<br><br></span></span></span></span></span></pre>
<pre><span style="color: rgba(255, 0, 0, 1)"><strong># Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
</strong></span><span style="color: rgba(0, 0, 0, 1)"><span style="color: rgba(255, 0, 0, 1)"><strong># more information.</strong></span>
<span style="color: rgba(255, 0, 0, 1)"><strong>#pool </strong></span></span><span style="color: rgba(255, 0, 0, 1)"><strong>0.ubuntu.pool.ntp.org iburst
#pool 1.ubuntu.pool.ntp.org iburst
#pool 2.ubuntu.pool.ntp.org iburst
#pool 3.ubuntu.pool.ntp.org iburst</strong><strong>

# Use Ubuntu's ntp server as a fallback.</strong></span>
<span style="color: rgba(255, 0, 0, 1)">#pool ntp.ubuntu.com
<strong>server </strong></span><strong><span style="color: rgba(255, 0, 0, 1)">127.127.1.0
fudge 127.127.1.0 stratum 10</span></strong><span style="color: rgba(0, 0, 0, 1)">


# Access control configuration; see </span>/usr/share/doc/ntp-doc/html/accopt.html <span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)">
# details.The web page </span>&lt;http:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">support.ntp.org/bin/view/Support/AccessRestrictions&gt;</span>
<span style="color: rgba(0, 0, 0, 1)"># might also be helpful.
#
# Note that </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">restrict</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)"> applies to both servers and clients, so a configuration
# that might be intended to block requests </span><span style="color: rgba(0, 0, 255, 1)">from</span><span style="color: rgba(0, 0, 0, 1)"> certain clients could also end
# up blocking replies </span><span style="color: rgba(0, 0, 255, 1)">from</span><span style="color: rgba(0, 0, 0, 1)"> your own upstream servers.

# By </span><span style="color: rgba(0, 0, 255, 1)">default</span>, exchange time with everybody, but don<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">t allow configuration.</span>
restrict -<span style="color: rgba(128, 0, 128, 1)">4</span> <span style="color: rgba(0, 0, 255, 1)">default</span><span style="color: rgba(0, 0, 0, 1)"> kod notrap nomodify nopeer noquery limited
restrict </span>-<span style="color: rgba(128, 0, 128, 1)">6</span> <span style="color: rgba(0, 0, 255, 1)">default</span><span style="color: rgba(0, 0, 0, 1)"> kod notrap nomodify nopeer noquery limited

# Local users may interrogate the ntp server more closely.
restrict </span><span style="color: rgba(128, 0, 128, 1)">127.0</span>.<span style="color: rgba(128, 0, 128, 1)">0.1</span><span style="color: rgba(0, 0, 0, 1)">
restrict ::</span><span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">

# Needed </span><span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> adding pool entries
restrict source notrap nomodify noquery

<span style="color: rgba(255, 0, 0, 1)"># Clients </span></span><span style="color: rgba(255, 0, 0, 1)">from this (example!) subnet have unlimited access, but only if
# cryptographically authenticated.
restrict 192.168.123.0 mask 255.255.255.0</span><span style="color: rgba(0, 0, 0, 1)"><span style="color: rgba(255, 0, 0, 1)"> nomodify notrap</span>


# If you want to provide time to your local subnet, change the next line.
# (Again, the address </span><span style="color: rgba(0, 0, 255, 1)">is</span><span style="color: rgba(0, 0, 0, 1)"> an example only.)
#broadcast </span><span style="color: rgba(128, 0, 128, 1)">192.168</span>.<span style="color: rgba(128, 0, 128, 1)">123.255</span></pre>
</div>
<p>4.对ntp server (hadoop102)执行命令,开启服务</p>
<div class="cnblogs_code">
<pre>sudo service ntp start</pre>
</div>
<p>5.同步时间(除hadoop102的其他机器都要执行)</p>
<div class="cnblogs_code">
<pre>sudo ntpdate hadoop102</pre>
</div>
<p>6&nbsp;在除hadoop102的其他机器,将同步时间的命令放在crontab中(切换到root用户下操作)</p>
<div class="cnblogs_code">
<pre>*/<span style="color: rgba(128, 0, 128, 1)">10</span> * * * * /usr/sbin/ntpdate hadoop102</pre>
</div>
<p>每十分钟更新一次</p>
<p>相关错误:</p>
<p>&nbsp;no server suitable for synchronization found</p>
<p>http://www.blogjava.net/spray/archive/2008/07/10/213964.html</p>
<p>Ubuntu 时间设置</p>
<p>https://www.cnblogs.com/qiumingcheng/p/12210629.html</p>
<p>&nbsp;</p>

</div>
<div id="MySignature" role="contentinfo">
    <p>本文来自博客园,作者:秋华,转载请注明原文链接:https://www.cnblogs.com/qiu-hua/p/13335686.html</p><br><br>
来源:https://www.cnblogs.com/qiu-hua/p/13335686.html
頁: [1]
查看完整版本: Linux 集群时间同步(Ubuntu)