半纸鸢 發表於 2019-5-8 18:44:00

Centos 搭建本地NTP服务器。

<p>  环境:Centos7.6</p>
<p>  实验主机:A:192.168.2.10</p>
<p>       B:192.168.2.11</p>
<p>       C:192.168.2.12(master)</p>
<p>  这里选择C做时间服务器。</p>
<h2>一:安装NTP服务。</h2>
<div class="cnblogs_Highlighter">
<pre class="brush:csharp;gutter:true;">yum install ntp -y
</pre>
</div>
<h2>二:修改配置文件。</h2>
<h3>1:C服务器添加如下配置</h3>
<div class="cnblogs_code">
<pre>#restrict <span style="color: rgba(0, 0, 255, 1)">default</span><span style="color: rgba(0, 0, 0, 1)"> nomodify notrap nopeer noquery  #将这条注释
</span></pre>
<p>&nbsp; restrict 192.168.2.12 nomodify notrap nopeer noquery<br>&nbsp; restrict 192.168.2.0 mask 255.255.252.0 nomodify notrap  <span>#允许特定网段能同步时间</span></p>
<pre><br>server 127.127.1.0    如果网络时间同步服务器不可以用,就以本地时间为标准想客户端提供服务。
Fudge 127.127.1.0 stratum 10<span style="color: rgba(128, 0, 128, 1)"><br><br></span></pre>
<p>&nbsp; #server 0.centos.pool.ntp.org iburst<br>&nbsp; #server 1.centos.pool.ntp.org iburst<br>&nbsp; #server 2.centos.pool.ntp.org iburst<br>&nbsp; #server 3.centos.pool.ntp.org iburst&nbsp;</p>
<p><em id="__mceDel">&nbsp; #将网络时间服务地址注释</em></p>







</div>
<pre>配置解释:<br>权限的设定主要以 restrict 这个参数来设定,主要的语法为: <br>restrict IP地址 mask 子网掩码 参数 <br>其中 IP 可以是IP地址,也可以是 default ,default 就是指所有的IP <br>参数有以下几个: <br>ignore :关闭所有的 NTP 联机服务 <br>nomodify:客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时。 <br>notrust :客户端除非通过认证,否则该客户端来源将被视为不信任子网 <br>noquery :不提供客户端的时间查询 <br><br></pre>
<h3>2:A和B服务器添加如下配置。<span style="color: rgba(255, 0, 0, 1)">(注意对应IP)</span></h3>
<div class="cnblogs_code">
<pre>#restrict <span style="color: rgba(0, 0, 255, 1)">default</span><span style="color: rgba(0, 0, 0, 1)"> nomodify notrap nopeer noquery    #注释掉
restrict </span><span style="color: rgba(128, 0, 128, 1)">192.168</span>.<span style="color: rgba(128, 0, 128, 1)">2.10</span><span style="color: rgba(0, 0, 0, 1)"> nomodify notrap nopeer noquery
restrict </span><span style="color: rgba(128, 0, 128, 1)">192.168</span>.<span style="color: rgba(128, 0, 128, 1)">2.0</span> mask <span style="color: rgba(128, 0, 128, 1)">255.255</span>.<span style="color: rgba(128, 0, 128, 1)">252.0</span><span style="color: rgba(0, 0, 0, 1)"> nomodify notrap

#server </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">.centos.pool.ntp.org iburst
#server </span><span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">.centos.pool.ntp.org iburst
#server </span><span style="color: rgba(128, 0, 128, 1)">2</span><span style="color: rgba(0, 0, 0, 1)">.centos.pool.ntp.org iburst
#server </span><span style="color: rgba(128, 0, 128, 1)">3</span><span style="color: rgba(0, 0, 0, 1)">.centos.pool.ntp.org iburst    <br>#注释掉以上4条。
<br>server </span><span style="color: rgba(128, 0, 128, 1)">192.168</span>.<span style="color: rgba(128, 0, 128, 1)">2.12</span><span style="color: rgba(0, 0, 0, 1)">
Fudge </span><span style="color: rgba(128, 0, 128, 1)">192.168</span>.<span style="color: rgba(128, 0, 128, 1)">2.12</span> stratum <span style="color: rgba(128, 0, 128, 1)">10</span></pre>
</div>
<p>&nbsp;</p>
<h2>三:启动和自启动NTP服务</h2>
<div class="cnblogs_Highlighter">
<pre class="brush:csharp;gutter:true;">systemctl start ntpd
systemctl enable ntpd
</pre>
</div>
<p>  <span style="color: rgba(255, 0, 0, 1)">启动后5-10分钟内自动进行同步。</span></p>
<h2>四:查看服务状态。</h2>
<p>  1:C服务器:</p>
<p>  <img src="https://img2018.cnblogs.com/blog/1469820/201905/1469820-20190508184224707-941284536.png" alt=""></p>
<p>  2:A服务器:</p>
<p>  <img src="https://img2018.cnblogs.com/blog/1469820/201905/1469820-20190508184257489-2043506410.png" alt=""></p>
<p>  3:B服务器</p>
<p>  <img src="https://img2018.cnblogs.com/blog/1469820/201905/1469820-20190508184316646-1055215767.png" alt=""></p>
<p>&nbsp;</p>

</div>
<div id="MySignature" role="contentinfo">
    <p>本文来自博客园,作者:鲜小橙,转载请注明原文链接:https://www.cnblogs.com/big-cousin/p/10833687.html</p><br><br>
来源:https://www.cnblogs.com/big-cousin/p/10833687.html
頁: [1]
查看完整版本: Centos 搭建本地NTP服务器。