Centos 7 Ntp 服務器的配置


我的hadoop 節點有兩個, 兩個cdhslave節點,一個master節點;

cdh02,cdh03為slave節點,cdh01為master節點

ntp服務器和兩個節點,兩個節點的時間從master節點獲取時間並進行同步。

在master節點  先檢查有沒有ntp fuwu安裝

rpm -qa | grep ntp 

 

以上代碼如果有這個安裝包,先進行清理;

 

后安裝ntp

yum install -y ntp

 

[root@cdh01 ~]# yum install -y ntp
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.huaweicloud.com
Resolving Dependencies
--> Running transaction check
---> Package ntp.x86_64 0:4.2.6p5-29.el7.centos will be installed
--> Processing Dependency: ntpdate = 4.2.6p5-29.el7.centos for package: ntp-4.2.6p5-29.el7.centos.x86_64
--> Processing Dependency: libopts.so.25()(64bit) for package: ntp-4.2.6p5-29.el7.centos.x86_64
--> Running transaction check
---> Package autogen-libopts.x86_64 0:5.18-5.el7 will be installed
---> Package ntpdate.x86_64 0:4.2.6p5-29.el7.centos will be installed
--> Finished Dependency Resolution

Dependencies Resolved

# Please consider joining the pool (http://www.pool.ntp.org/join.html).
===========================================================================================================================
 Package                         Arch                   Version                                 Repository            Size
===========================================================================================================================

以上為安裝日志

安裝完后

進行配置

vi /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 172.16.9.130 mask 255.255.255.0 nomodify notrap  #這里把ip地址改成你的master(本機)de ip地址
#########################################
# 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
#+++++++++++++++++++++++++++++++++++++++++++++++
#+++++最后加上這兩句+++++++++++++++++++++++++++++++++
server 127.127.1.0
fudge 127.127.1.0 stratum 10
#以上所有的配置,先吧時間區域改成上海,再進行

 

然后把服務設置成開機啟動...

chkconfig ntpd on



然后 啟動服務


systemctl start ntpd

 

----------------------------------------------------

master節點配置結束

接下來我們配置slave節點

在slave節點一下命令進行配置

crontab -e

 

然后文件內容輸入一下內容:

0-59/5 * * * * /usr/sbin/ntpdate cdh01

 

# cdh01 為maister節點的hostname(之前在hosts文件里已經配置過映射)

0-59為 任何一秒

5 為每個五分鍾同步一次時間

cdh02,cdh03兩個節點都進行這個配置。

ntp服務配置完畢 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM