日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

CentOS7中多台服务器配置时钟同步

發布時間:2025/3/19 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CentOS7中多台服务器配置时钟同步 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

場景

CentOS7中怎樣設置靜態IP:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/119242495

在上面給三臺CentOS7的服務器配置了靜態IP的基礎上,怎樣配置時鐘同步。

集群中時間不同步有可能會讓大數據的應用程序運行混亂,造成不可預知的問題,比如Hbase、mongodb副本集等,Hbase當時間差別過大時就會掛掉,mongodb如果副本時間過快,會出現時間棧幀溢出提前出發選舉等,所以在大數據集群中,ntp服務,應該作為一種基礎的服務。

NTP是網絡時間協議(Network Time Protocol),它是用來同步網絡中各個計算機的時間的協議。

首先檢查系統中是否已經安裝ntp包

rpm -q ntp

?

如果沒有安裝的話自行進行安裝。

注:

博客:
https://blog.csdn.net/badao_liumang_qizhi
關注公眾號
霸道的程序猿
獲取編程相關電子書、教程推送與免費下載。

實現

在master主服務器上搭建ntp服務器

修改/etc/ntp.conf文件

vi /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 ::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,默認網關為255.255.255.0的機器都可以從NTP服務器進行同步時間

restrict 192.168.148.2 mask 255.255.255.0 nomodify notrap

定義使用的上游ntp服務器,將原來的注釋掉

server ntp1.aliyun.com server time1.aliyun.com

允許上層時間服務器主動修改本機時間

restrict time1.aliyun.com nomodify notrap noquery restrict ntp1.aliyun.com nomodify notrap noquery

外部時間不可用時,使用本地時間作為時間服務。

server 127.0.0.1 fudge 127.0.0.1 stratum 10

配置文件修改完成之后,重啟服務

service ntpd restart

ntp同步狀態查看

ntpstat 命令查看時間同步狀態,這個一般需要5-10分鐘后才能成功連接和同步。所以,服務器啟動后需要稍等下。

ntpstat

還可通過

ntpq -p

查詢ntp是否同步

?

ntp客戶端配置

兩個子節點服務器slave1和slave2服務器分別修改配置

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 ::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

修改說明

配置時間服務器為上面搭建的ntp服務器

server 192.168.148.128

配置允許ntp服務器主動修改本機的時間

restrict 192.168.148.128 nomodify notrap noquery

同樣配置本地服務器

server 127.0.0.1fudge 127.0.0.1 stratum 10

然后配置完成后同樣重啟服務

service ntpd restart

同樣通過

ntpstat ntpq -p

查看同步的狀態

也可以單次進行手動同步測試效果

在客戶端slave1上,首先停止ntpd的服務 ,不然會提示: the NTP socket is in use, exiting

service ntpd stop

然后同步一次時間

ntpdate 192.168.148.128

同步成功之后記得開啟服務

service ntpd start

?

總結

以上是生活随笔為你收集整理的CentOS7中多台服务器配置时钟同步的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。