天天看點

NTP服務部署(centos7)

NTP服務在大資料叢集部署時時一個很關鍵的步驟,叢集時間不對會導緻很多問題

1.yum安裝ntp服務
	yum -y install ntp
	
離線安裝需要三個包
	ntp.x86_64 0:4.2.6p5-28.el7.centos                                                             
	autogen-libopts.x86_64 0:5.18-5.el7
	ntpdate.x86_64 0:4.2.6p5-28.el7.centos
           

2.配置服務端 vi /etc/ntp.conf

配置服務端 vi /etc/ntp.conf 

	#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
#修改為--允許192.168.11.x網段内所有的主機通路
	restrict 192.168.11.0 mask 255.255.255.0 nomodify notrap
#注釋掉下面的4行
	#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 ntp1.aliyun.com
	server time1.aliyun.com
	server 127.127.1.0 	# 本地時鐘伺服器
           

3.服務端測試—主要是2個指令,具體含義可以自行Google

重新開機ntp服務
	systemctl restart ntpd
檢視同步狀态
[[email protected] network-scripts]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 120.25.115.20   10.137.53.7      2 u    2   64    1   44.838  -15.378   0.000
 203.107.6.88    10.137.55.181    2 u    1   64    1   21.400  -14.319   0.000
*LOCAL(0)        .LOCL.           5 l    -   64    1    0.000    0.000   0.000

 [[email protected] network-scripts]# timedatectl 
     	 Local time: 一 2019-03-29 23:35:21 CST
 		 Universal time: 一 2019-03-29 15:35:21 UTC
         RTC time: 一 2019-03-29 15:35:21
         Time zone: Asia/Shanghai (CST, +0800)
     	 NTP enabled: yes
		 NTP synchronized: yes
		 RTC in local TZ: no
        DST active: n/a

           

4.用戶端測試

當用戶端與服務端的時間差較大時,采用配置檔案的形式同步會出錯,可以使用
	ntpdate -u cdh11(或者ip位址的形式先同步時間在配置ntp.conf檔案)
修改用戶端的配置檔案ntp.conf
	#注釋掉下面的4行
		#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 192.168.11.11 iburst
重新開機用戶端
	systemctl restart ntpd
檢視同步狀态
[[email protected] etc]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*cdh11           203.107.6.88     3 u   21   64    1    0.282  -16.845   0.131
           

注意:

ntpd服務不可與ntpdate同時使用,一般在實踐上采用C/S架構。配置用戶端同步服務端,但是要注意的時啟用ntpd服務以後就不能使用ntpdate同步時間會提示端口被占用,也有部分公司采用crontab定時排程ntpdate指令同步這裡給一個例子,自行參考。

#10分鐘同步一次
*/10 * * * * ntpdate 192.168.11.11  #域名或IP
           

繼續閱讀