1. Check whether the ntpd service is installed
For operating systems after centos6, the ntp service has been installed by default. The command to view is as follows:
[root@master ~]# rpm -qa |grep ntp ntpdate-4.2.6p5-1.el6.centos.x86_64 fontpackages-filesystem-1.41-1.1.el6.noarch ntp-4.2.6p5-1.el6.centos.x86_64
As above, it means that NTP is installed correctly
2. Check whether the upper-layer NTP server is normally connected
The following three addresses are the commonly used upper-layer NTP server addresses in China.
210.72.145.44 # China National Time Receiving Center 202.112.10.36 # 1.cn.pool.ntp.org 59.124.196.83 # 0.asia.pool.ntp.org
According to the online example to test, dealing with the external network ntp server, I have failed here, as shown below.
[root@slave1 ~]# ntpdate 210.72.145.44 6 Jul 09:43:06 ntpdate[29799]: no server suitable for synchronization found [root@slave1 ~]# ntpdate -q 210.72.145.44 server 210.72.145.44, stratum 0, offset 0.000000, delay 0.00000 6 Jul 09:43:45 ntpdate[29934]: no server suitable for synchronization found [root@slave1 ~]# ntpdate -q 1.cn.pool.ntp.org server 202.118.1.81, stratum 0, offset 0.000000, delay 0.00000 server 110.75.190.198, stratum 0, offset 0.000000, delay 0.00000 server 182.92.12.11, stratum 0, offset 0.000000, delay 0.00000 server 115.28.122.198, stratum 0, offset 0.000000, delay 0.00000 6 Jul 09:44:07 ntpdate[29953]: no server suitable for synchronization foundLater, I found some information on the Internet, and said that the reason for this is that the current official ntp server has restrictions, and ntpdate cannot be used to directly synchronize the time. To synchronize the time with the official ntp server, use the command rdate -s serviceip
Current solution?
Answer: An NTP server is built on a server on the intranet, other machines synchronize time with this server, and the NTP service machine should be able to communicate with the external network. This server uses rdate -s serviceip to time the external network. synchronised time.
The advantage of this solution is that what we actually need to do in the actual project is to ensure that all the machines in the cluster are time-synchronized (and usually, the cluster is deployed on the intranet and cannot communicate with the external network), not Be sure to synchronize with the standard time; at this time, we only need to remove the scheduled task of rdate -s serviceip.
3. Specific implementation details
3.1. Configure rdate to synchronize time with the external network
The execution command is as follows:
[root@slave1 ~]# rdate -s 1.cn.pool.ntp.org # Go to the upper server to synchronize the time every 15 minutes [root@slave1 ~]# */15 * * * * rdate -s 0.asia.pool.ntp.org
Tips:
The official time synchronization server address provided by China is as follows: http://www.pool.ntp.org/zone/cn
3.2. Build an ntp server on the intranet
- Change setting
It is very simple to build an intranet ntp service. You only need to modify the file /etc/ntp.conf. The changes are as follows, and you can follow the gourd.
#Allow the host of the 192.168.238.0/n network segment to perform time synchronization, but not allow the client to modify it. Log in to my NTP server. In my experimental environment, the intranet uses the 192.168.238.0/12 network segment. # Hosts on local network are less restricted. restrict 192.168.238.0 mask 255.255.255.0 nomodify notrap #Allow clients of any IP to perform time synchronization restrict default nomodify #Shield the upper-level time synchronization server, because I use rdate for external time here # 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 #server 1.centos.pool.ntp.org #server 2.centos.pool.ntp.org # Undisciplined Local Clock. This is a fake driver intended for backup # and when no outside source of synchronized time is available. # When the external time server is unavailable, use the local time as the time service server 127.127.1.0 # local clock fudge 127.127.1.0 stratum 10
- start ntp service
[root@slave1 ~]# service ntpd start Starting ntpd: [ OK ]
- Auto start at boot
[root@slave1 ~]# chkconfig ntpd on [root@slave1 ~]# chkconfig --list ntpd ntpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
温馨提示:
此时启动ntpd服务器,客户端立刻使用ntpdate来同步时间,会报如下错误
"no server suitable for synchronization found "
原因分析:
在ntp server上启动ntp服务后,ntp server自身或者与其server的同步的须要一个时候段(我这种配置屏蔽了与外部的时间同步,以本身时间作为时间服务),这个过程可能是5分钟,在这个时候之内涵客户端运行ntpdate号令时会产生no server suitable for synchronization found的错误。
3.3.客户端同步时间
[root@master ~]# ntpdate 192.168.238.133 5 Jul 18:34:35 ntpdate[8667]: adjust time server 192.168.238.133 offset -0.013669 sec #在crontab例行任务中添加没15分钟同步一次时间,如下所示 */15 * * * * /usr/sbin/ntpdate 192.168.27.35;hwclock -w
按照如下博客配置ntp.conf,以前是可以的,现在master与外网同步时间不行了,不知道是不是我的网络问题
http://acooly.iteye.com/blog/1993484