當我們在搭建集群的時候,要實作時間同步
現在以三臺虛擬機為例子,
hadoop01,hadoop02,hadoop03
現在讓hadoop01來充當服務器,
讓hadoop02,hadoop03來充當客戶端
首先對hadoop01服務器來進行配置
1.需要先安裝ntp服務和ntpdate工具
yum -y install ntp ntpdate
2.改組態檔,組態檔在/etc/ntp.conf
配置文化有幾個位置需要改動
1)授權下述網段上所有的機器允許從ntp服務器上查詢和同步時間
restrict 192.168.10.0 mask 255.255.255.0 nomodify notrap
192.168.10.0 ----》一定要查詢自己的網關
2)#增加下述幾個時間服務器串列,可以多些幾個,萬一有一個服務器掛掉的時候,他會自動找下一個
server 0.asia.pool.ntp.org iburst
server 1.asia.pool.ntp.org iburst
server 2.asia.pool.ntp.org iburst
server 3.asia.pool.ntp.org iburst
3)這兩行內容表示當外部時間不可用時,使用本地時間
server 127.127.1.0 iburst
fudge 127.127.1.0 stratum 10
4)下述四行表示允許上層服務器修改本機時間
0.asia.pool.ntp.org nomodify notrap noquery restrict 1.asia.pool.ntp.org nomodify notrap noquery restrict 2.asia.pool.ntp.org nomodify notrap noquery restrict 3.asia.pool.ntp.org nomodify notrap noquery restrict
3.設定開機自啟動服務
systemctl enable ntpd
使客戶端工具ntpdate工具生效
systemctl enable ntpdate
我們可以檢查一下狀態
systemctl is-enabled ntpd
如果結果是enable就對了
4.啟用ntp服務
1)我們可以查看ntpd行程
ps -ef | grep ntpd
如果行程存在,說明服務啟動成功
5.設定防火墻關閉
systemctl disable firewalld
可以查看狀態關閉沒關閉(但是一般會有延遲)
systemctl status firewalld
6.設定bios和系統時間同步
hwclock -w
- 測驗
ntpstat
回傳類似結果
synchronised to NTP server (211.233.84.186) at stratum 3 time correct to within 292 ms
說明了本地已經和時間服務器同步了
如果unsynchronised polling server every 8 s 這個問題
我遇到的問題是網關寫錯了,還可以把組態檔加一句話
interface listen 192.168.1.21 (這個ip就是充當服務器的ip)
二.配置客戶端
配置客戶端有兩種方法
一種是讓hadoop02 又有客戶端又有服務器端,這樣可以讓hadoop02的客戶端請求hadoop02的服務端,在由hadoop02的服務端請求hadoop01這個服務器:
這種寫法好處是:hadoop02的ntpd服務始終運行著,我們不用再手動執行命令或者寫定時器了,而且ntpd服務是慢慢改變時間的,很柔和
第一種:
配置:
1.需要先安裝ntp服務和ntpdate工具
yum -y install ntp ntpdate
2.設定bios和系統時間同步
hwclock -w
3.寫組態檔
echo "server 192.168.10.200" >/etc/ntp.conf
server 192.168.10.200 這個就是hadoop01的ip地址
- 重啟服務以使配置生效,之后大概要等10分鐘左右,才會同步成功
systemctl enable ntpd
systemctl restart ntpd
第二種:是寫個定時器,定時實作時間同步
1.配置
1.需要先安裝ntp服務和ntpdate工具
yum -y install ntp ntpdate
2.寫定時器
寫定時器要注意的兩點是
a.執行命令要寫絕對路徑
b.要寫上系統和bios時間同步
* * * * * (/usr/sbin/ntpdate -u 192.168.10.200 && /sbin/hwclock -w) &> /var/log/ntpdate.log
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/200294.html
標籤:其他
上一篇:Spring Cloud Alibaba入門實踐(十一)-Sentinel之規則與資源
下一篇:OLAP查詢資料量預估的解決方案
