CentOS7中多台服务器配置时钟同步
場景
CentOS7中怎樣設(shè)置靜態(tài)IP:
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/119242495
在上面給三臺CentOS7的服務(wù)器配置了靜態(tài)IP的基礎(chǔ)上,怎樣配置時鐘同步。
集群中時間不同步有可能會讓大數(shù)據(jù)的應(yīng)用程序運行混亂,造成不可預(yù)知的問題,比如Hbase、mongodb副本集等,Hbase當時間差別過大時就會掛掉,mongodb如果副本時間過快,會出現(xiàn)時間棧幀溢出提前出發(fā)選舉等,所以在大數(shù)據(jù)集群中,ntp服務(wù),應(yīng)該作為一種基礎(chǔ)的服務(wù)。
NTP是網(wǎng)絡(luò)時間協(xié)議(Network Time Protocol),它是用來同步網(wǎng)絡(luò)中各個計算機的時間的協(xié)議。
首先檢查系統(tǒng)中是否已經(jīng)安裝ntp包
rpm -q ntp?
如果沒有安裝的話自行進行安裝。
注:
博客:
https://blog.csdn.net/badao_liumang_qizhi
關(guān)注公眾號
霸道的程序猿
獲取編程相關(guān)電子書、教程推送與免費下載。
實現(xiàn)
在master主服務(wù)器上搭建ntp服務(wù)器
修改/etc/ntp.conf文件
vi /ntp.conf修改為如下
?
修改內(nèi)容
# 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 ::1restrict 192.168.148.2 mask 255.255.255.0 nomodify notrap# 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#server 0.cn.pool.ntp.org #server 1.asia.pool.ntp.org #server 2.192.168.148.128server ntp1.aliyun.com server time1.aliyun.comrestrict time1.aliyun.com nomodify notrap noquery restrict ntp1.aliyun.com nomodify notrap noqueryserver 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. #cryptoincludefile /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修改說明
IP地址從192.168.148.2? 到192.168.254.254,默認網(wǎng)關(guān)為255.255.255.0的機器都可以從NTP服務(wù)器進行同步時間
restrict 192.168.148.2 mask 255.255.255.0 nomodify notrap定義使用的上游ntp服務(wù)器,將原來的注釋掉
server ntp1.aliyun.com server time1.aliyun.com允許上層時間服務(wù)器主動修改本機時間
restrict time1.aliyun.com nomodify notrap noquery restrict ntp1.aliyun.com nomodify notrap noquery外部時間不可用時,使用本地時間作為時間服務(wù)。
server 127.0.0.1 fudge 127.0.0.1 stratum 10配置文件修改完成之后,重啟服務(wù)
service ntpd restartntp同步狀態(tài)查看
ntpstat 命令查看時間同步狀態(tài),這個一般需要5-10分鐘后才能成功連接和同步。所以,服務(wù)器啟動后需要稍等下。
ntpstat還可通過
ntpq -p查詢ntp是否同步
?
ntp客戶端配置
兩個子節(jié)點服務(wù)器slave1和slave2服務(wù)器分別修改配置
vi /etc/ntp.conf將內(nèi)容修改為
# 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 ::1server 192.168.148.128 restrict 192.168.148.128 nomodify notrap noqueryserver 127.0.0.1 fudge 127.0.0.1 stratum 10 # 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#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. #cryptoincludefile /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修改說明
配置時間服務(wù)器為上面搭建的ntp服務(wù)器
server 192.168.148.128配置允許ntp服務(wù)器主動修改本機的時間
restrict 192.168.148.128 nomodify notrap noquery同樣配置本地服務(wù)器
server 127.0.0.1fudge 127.0.0.1 stratum 10然后配置完成后同樣重啟服務(wù)
service ntpd restart同樣通過
ntpstat ntpq -p查看同步的狀態(tài)
也可以單次進行手動同步測試效果
在客戶端slave1上,首先停止ntpd的服務(wù) ,不然會提示: the NTP socket is in use, exiting
service ntpd stop然后同步一次時間
ntpdate 192.168.148.128同步成功之后記得開啟服務(wù)
service ntpd start?
總結(jié)
以上是生活随笔為你收集整理的CentOS7中多台服务器配置时钟同步的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CentOS7中怎样安装JDK与配置环境
- 下一篇: VMWare中修改CentOS虚拟机静态