ntp客户端安装
#yum install ntp -y
手动时间同步
#/usr/sbin/ntpdate pool.ntp.org
26 Feb 17:45:00 ntpdate[14681]: adjust time server 85.199.214.100 offset 0.004657 sec
添加计划任务
#vim /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
0 0 * * * /usr/sbin/ntpdate pool.ntp.org && /usr/sbin/hwclock --systohc
注:ntp使用的是udp 123端口 在防火墙上一定要放开
#firewall-cmd --zone=public --add-port=123/udp --permanent
#firewall-cmd --reload
Ntp服务器的安装配置
ntpd安装
#yum install ntp -y
#systemctl start ntpd
您在 /var/spool/mail/root 中有新邮件
#systemctl status ntpd
● ntpd.service - Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)
Active: active (running) since 日 2017-02-26 17:53:24 CST; 7s ago
Process: 14877 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 14878 (ntpd)
CGroup: /system.slice/ntpd.service
└─14878 /usr/sbin/ntpd -u ntp:ntp -g
2月 26 17:53:24 ftp ntpd[14878]: Listen and drop on 1 v6wildcard :: UDP 123
2月 26 17:53:24 ftp ntpd[14878]: Listen normally on 2 lo 127.0.0.1 UDP 123
2月 26 17:53:24 ftp ntpd[14878]: Listen normally on 3 ens160 10.1.41.54 UDP 123
2月 26 17:53:24 ftp ntpd[14878]: Listen normally on 4 lo ::1 UDP 123
2月 26 17:53:24 ftp ntpd[14878]: Listen normally on 5 ens160 fe80::250:56ff:fe85:598c UDP 123
2月 26 17:53:24 ftp ntpd[14878]: Listening on routing socket on fd #22 for interface updates
2月 26 17:53:24 ftp ntpd[14878]: 0.0.0.0 c016 06 restart
2月 26 17:53:24 ftp ntpd[14878]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM
2月 26 17:53:24 ftp ntpd[14878]: 0.0.0.0 c011 01 freq_not_set
2月 26 17:53:31 ftp ntpd[14878]: 0.0.0.0 c614 04 freq_mode
查看ntp服务器有无和上层ntp连通
#ntpstat
synchronised to NTP server (51.15.41.135) at stratum 3
time correct to within 165 ms
polling server every 64 s
检查时间服务器的同步状态
#ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*ntp3.itcomplian 5.103.128.88 2 u 20 64 377 206.590 4.816 0.801
+ntp4.flashdance 77.40.226.114 2 u 24 64 361 261.990 24.804 5.351
+ntp3.flashdance 194.58.202.148 2 u 27 64 173 234.689 17.706 1.152
到客户端去测试
#ntpdate 10.1.41.54
26 Feb 17:55:37 ntpdate[12641]: adjust time server 10.1.41.54 offset -0.009717 sec
OK ntp的教程完成