Centos下NTP时间服务器配置详解
NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议。它的用途是把计算机的时钟同步到世界协调时UTC,其精度在局域网内可达0.1ms,在互联网上绝大多数的地方其精度可以达到1-50ms。 NTP服务器就是利用NTP协议提供时间同步服务的。NTP简介
NTP服务器安装
# 系统自带ntp软件包 [root@node ~]# rpm -qa ntp ntp-4.2.6p5-5.el6.centos.x86_64 # 如果没有就安装 [root@node ~]# yum -y install ntp
配置NTP服务
[root@node ~]# vim /etc/ntp.conf
# restrict default kod nomodify notrap nopeer noquery
restrict default nomodify
# nomodify客户端可以同步
# 将默认时间同步源注释改用可用源
# 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 s2m.time.edu.cn #北京教育网时间服务器
启动NTP服务器
# 如果计划任务有时间同步,先注释,两种用法会冲突。 [root@node ~]# crontab -e # time sync cron #[i]/3 [/i] [i] [/i] * /usr/sbin/ntpdate ntp1.aliyun.com >/dev/null 2>&1 [root@node ~]# /etc/init.d/ntpd start Starting ntpd: [ OK ] [root@node ~]# ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== *ntp1.aliyun.com 10.137.38.86 2 u 22 64 1 525.885 -42.367 0.000 [root@node ~]# ntpstat synchronised to NTP server (110.75.186.247) at stratum 3 time correct to within 4257 ms polling server every 64 s
客户机要等几分钟再与新启动的ntp服务器进行时间同步,否则会提示no server suitable for synchronization found错误。客户机时间同步
[root@node ~]# ntpdate 10.0.1.110 (ntp_server_ip) 27 Mar 18:40:16 ntpdate[1453]: step time server 10.0.1.110 offset 40.880807 sec # 将命令放入计划任务即可。