主服務:hadoop1 ip:192.168.1.88 其餘服務器:hadoopxx ip:192.168.1.xx 1)查看軟件包是否安裝 rpm -q ntp
1.png 2)若是沒有 那麼用yum install 軟件包 進行安裝 3)設置開啓自啓動 systemctl enable ntpd 4)啓動服務 systemctl start ntpd 5)設置主服務器 配置文件 標記處爲修改內容 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 192.168.1.0 mask 255.255.255.0 nomodify notrap #111111111111 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 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 #111111111111 server 2.cn.pool.ntp.org server 1.asia.pool.ntp.org server 2.asia.pool.ntp.org #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 #111111111111 restrict 2.cn.pool.ntp.org nomodify notrap noquery restrict 1.asia.pool.ntp.org nomodify notrap noquery restrict 2.asia.pool.ntp.org nomodify notrap noquery server 127.0.0.1 # local clock fudge 127.0.0.1 stratum 10 # 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 6)重啓服務 systemctl restart ntpd 7)執行 ntpstat 若是顯示下邊結果 正在啓動 unsynchronised time server re-starting polling server every 64 s 8)執行 ntpstat 若是顯示下邊結果 已經開始運行 synchronised to NTP server (182.92.12.11) at stratum 3 time correct to within 17 ms polling server every 64 s 9)修改非主服務器配置文件 標記處爲修改內容 vi /etc/ # 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 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 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 #1111111111 server 192.168.1.88 restrict 192.168.1.88 nomodify notrap noquery server 127.0.0.1 fudge 127.0.0.1 stratum 10 #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 10)查看同步狀況 ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== *hadoop1 182.92.12.11 3 u 71 128 377 0.209 -1.088 0.367 localhost .INIT. 16 l - 1024 0 0.000 0.000 0.000 參數解釋: ● remote: 遠程NTP服務器的IP地址或域名,帶 「*」 的表示本地NTP服務器與該服務器同步。 ● refid: 遠程NTP服務器的上層服務器的IP地址或域名。 ● st: 遠程NTP服務器所在的層數。 ● t: 本地NTP服務器與遠程NTP服務器的通訊方式,u: 單播; b: 廣播; l: 本地。 ● when: 上一次校訂時間與如今時間的差值。!!!!!!!!!!!!! ● poll: 本地NTP服務器查詢遠程NTP服務器的時間間隔。!!!!!!!!!!! ● reach: 是一種衡量前8次查詢是否成功的位掩碼值,377表示都成功,0表示不成功。 ● delay: 網絡延時,單位是10的-6次方秒。 ● offset: 本地NTP服務器與遠程NTP服務器的時間偏移。 ● jitter: 查詢誤差的分佈值,用於表示遠程NTP服務器的網絡延時是否穩定,單位爲10的-6次方秒。 11)測試 a. 暫時關閉ntp timedatectl set-ntp 0 //否則會報錯 Failed to set time: Automatic time synchronization is enabled b. 設置服務器時間 timedatectl set-time '2018-08-08' c.打開ntp服務 timedatectl set-ntp 1 d.查看系統時間 date 一下子就不是'2018-08-08'了 證實已經同步了