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
查看同步状态
[root@cdh11 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

 [root@cdh11 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
查看同步状态
[root@cdh12 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

你可能感兴趣的:(Linux相关)