Centos7 ntp 设置时间

主服务:hadoop1  ip:192.168.1.88
	其他服务器:hadoopxx  ip:192.168.1.xx
    
	 1)查看软件包是否安装
	 rpm -q ntp
        
    
	 1.png
	 2)如果没有 那么用yum install 软件包 进行安装
	 3)设置开启自启动  
	 systemctl enable ntpd
	 4)启动服务
	 systemctl start ntpd
	 5)设置主服务器 配置文件   标记处为修改内容
	 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 ::1

		# Hosts on local network are less restricted.
		#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
		
		
		#111111111111
		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
		
		#111111111111
		server 2.cn.pool.ntp.org
	   server 1.asia.pool.ntp.org
	   server 2.asia.pool.ntp.org


		#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
		
		#111111111111
		restrict 2.cn.pool.ntp.org nomodify notrap noquery
	  restrict 1.asia.pool.ntp.org nomodify notrap noquery
	  restrict 2.asia.pool.ntp.org nomodify notrap noquery
	  server 127.0.0.1 # local clock
	  fudge 127.0.0.1 stratum 10


		# Enable public key cryptography.
		#crypto

		includefile /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
	6)重启服务
	systemctl restart ntpd
	7)执行 ntpstat  如果显示下边结果 正在启动
	unsynchronised
		time server re-starting
			polling server every 64 s
	8)执行 ntpstat  如果显示下边结果 已经开始运行
	synchronised to NTP server (182.92.12.11) at stratum 3 
		time correct to within 17 ms
			polling server every 64 s

	9)修改非主服务器配置文件 标记处为修改内容
		vi /etc/
	 # 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 ::1

		# 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
		
		#1111111111
		server 192.168.1.88
	   restrict 192.168.1.88 nomodify notrap noquery
	   server 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.
		#crypto

		includefile /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
	10)查看同步情况  ntpq -p 
		remote           refid            st t   when  poll   reach   delay   offset  jitter
		==============================================================================
		*hadoop1         182.92.12.11     3  u   71    128    377     0.209   -1.088   0.367
		 localhost       .INIT.          16  l    -   1024     0      0.000    0.000   0.000
	参数解释: 
		● remote: 远程NTP服务器的IP地址或域名,带 “*” 的表示本地NTP服务器与该服务器同步。

		● refid: 远程NTP服务器的上层服务器的IP地址或域名。

		● st: 远程NTP服务器所在的层数。

		● t: 本地NTP服务器与远程NTP服务器的通信方式,u: 单播; b: 广播; l: 本地。

		● when: 上一次校正时间与现在时间的差值。!!!!!!!!!!!!!

		● poll: 本地NTP服务器查询远程NTP服务器的时间间隔。!!!!!!!!!!!

		● reach: 是一种衡量前8次查询是否成功的位掩码值,377表示都成功,0表示不成功。

		● delay: 网络延时,单位是10的-6次方秒。

		● offset: 本地NTP服务器与远程NTP服务器的时间偏移。

		● jitter: 查询偏差的分布值,用于表示远程NTP服务器的网络延时是否稳定,单位为10的-6次方秒。
	
	11)测试 
	        a. 暂时关闭ntp  timedatectl set-ntp 0   //不然会报错 Failed  to set time: Automatic time synchronization is enabled
		 b. 设置服务器时间 timedatectl set-time  '2018-08-08'
		 c.打开ntp服务  timedatectl set-ntp 1  
		 d.查看系统时间  date  一会儿就不是'2018-08-08'了  证明已经同步了
	


猜你喜欢

转载自blog.csdn.net/qq_36291682/article/details/79603959