????升級ntp主要是為了解決系統(tǒng)安全問題:
? ? ? ? ? ? ? ? ? ? 因?yàn)? ? centos7.4系統(tǒng)中默認(rèn)安裝的是 ntp 4.2.6p5版本,但是此版本漏洞很多双饥,很容易被攻擊導(dǎo)致無法提供服務(wù)等等問題。下面的鏈接是ntp 4.2.6p5版本漏洞詳細(xì):
? ??????????????????????????????????http://www.reibang.com/p/a6a761617736
查看當(dāng)前系統(tǒng)版本:
? ? ? ? ? cat /etc/system-release
查看當(dāng)前 ntpd 版本:
? ? ? ? ? ?ntpd --version
一趴生、?系統(tǒng)與軟件版本**
? ? ? ? ? 系統(tǒng)版本:
? ? ? ? ? ? ? ? ?CentOS7.4
? ? ? ? ? ntpd軟件版本:
? ? ? ? ? ? ? ? ? ?ntp-4.2.8p12
? ? ? ? ? 下載地址:
? ? ? ? ? ? ? ? ??Windows下載地址:http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-4.2.8p12.tar.gz
? ? ? ? ? ? ? ? ? Linux 下載地址:wget?http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-4.2.8p12.tar.gz
二、安裝準(zhǔn)備
? ? ? ? ? ? 安裝依賴包:
? ? ? ? ? ? ? ? ? ? yum install gcc gcc-c++ openssl-devel libstdc++* libcap*
? ? ? ? ? ? 備份舊版本的配置文件:(不需要備份的話請?zhí)^)
????????????建議備份因?yàn)樵创a安裝不會生成配置文件如果不備份的話我會在下面貼出配置文件的內(nèi)容
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cp -ar /etc/ntp /etc/ntp.bak
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cp /etc/ntp.conf /etc/ntp.conf.bak
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cp /etc/init.d/ntpd /etc/init.d/ntpd.bak
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cp /etc/sysconfig/ntpd /etc/sysconfig/ntpd.bak
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cp /etc/sysconfig/ntpdate /etc/sysconfig/ntpdate.bak
? ? ? ? ? ? 卸載yum安裝的ntpd服務(wù):
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? yum remove ntp ntpdate
? ? ? ? ? ? 解壓 ntp 壓縮文件:
三刘急、編譯安裝ntp-4.2.8p9
? ? ? ? ? ? 解壓源碼壓縮文件:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?tar -zxvf ntp-4.2.8p12.tar.gz???
? ? ? ? ? ? 進(jìn)入解壓生成的ntp-4.2.8p9文件夾:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cd ntp-4.2.8p12/
? ? ? ? ? ? 編譯安裝ntpd:
./configure \
--prefix=/usr \
--bindir=/usr/sbin \
--enable-all-clocks \
--enable-parse-clocks \
--docdir=/usr/share/doc/ntp-4.2.8p12
????????????????命令詳解:
????????????????????????????????--prefix=安裝的目錄? ?
? ??????????????????????????????--bindir=會將主程序放置到這個文件夾
? ??????????????????????????????--docdir=doc文檔的存放目錄
? ? ? ? ? ? ? ? 查看運(yùn)行是否有錯誤:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 執(zhí)行:? echo $?
? ? ? ? ? ? ? 編譯并安裝:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? make && make install
? ? ? ? ? ? ? ?創(chuàng)建軟鏈接:
????????????????????????????????????ln -s /usr/local/ntp-4.2.8p12 /usr/local/ntp
? ? ? ? ? ? ? ? 查看 ntp 版本:
? ? ????????????????????????????????????ntpd --version
配置 ntp :
? ? ? ? ? ? ? ? 執(zhí)行 vim /etc/ntp.conf
? ? ? ? ? ? ? ? 這個配置文件是將此節(jié)點(diǎn)配置成本地服務(wù) server 端:
本地其他機(jī)器可以使用命令:????????ntpdate mongodb04? ? ? ? ? ? 來和此節(jié)點(diǎn)同步時間
添加以下配置:
# 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.215.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
#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
server 127.127.1.0? # local clock
fudge 127.127.1.0 stratum 10
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
? ? ? ? ? ? ? ? ? ? 然后就是啟動 ntp 服務(wù)了:
? ? ? ? ? ? ? ? ? ? ?????????????????????????????????????????/usr/sbin/ntpd -c /etc/ntp.conf
? ? ? ? ? ? ? ? ? ? 查看 ntp 服務(wù)是否啟動:
? ??????????????????????????????????????????????????????????ps -ef | grep ntpd
? ? ? ? ? ? ? ? ? ? ?查看 ntp 服務(wù)端口:
? ??????????????????????????????????????????????????netstat -tunlp | grep 123
????????????????????????檢查同步情況:
? ??????????????????????????????????????????????watch ntpq -p
在啟動之后短時間內(nèi)可能無法和此節(jié)點(diǎn)同步時間可能會出現(xiàn)下面的問題:
? ????????????? 執(zhí)行同步命令:????ntpdate mongodb04
????????????????????????????????31 Aug 00:34:43 ntpdate[18417]: no server suitable for synchronization found
稍微等一會在進(jìn)行同步:
? ? ? ? ? ? ? ? 執(zhí)行同步命令:????ntpdate mongodb04
????????????????????????????????31 Aug 00:39:20 ntpdate[18684]: adjust time server 192.168.215.184 offset -0.111364 sec