linux服务之NTP时间服务器

1. NTP简介

NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议。它的用途是把计算机的时钟同步到世界协调时UTC,其精度在局域网内可达0.1ms,在互联网上绝大多数的地方其精度可以达到1-50ms。

NTP服务器就是利用NTP协议提供时间同步服务的。

2. NTP服务器安装

本机环境:

[root@ntp ~]# cat /etc/redhat-release
CentOS release 6.9 (Final)
[root@ntp ~]# uname -r
2.6.32-696.el6.x86_64

ntp服务器IP :172.16.1.5

# 系统自带ntp

[root@ntp ~]# rpm -qa ntp

ntp-4.2.6p5-5.el6.centos.x86_64

# 如果没有就安装

yum -y install ntp

3. 配置NTP服务

[root@ntp ~]# 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 time.nist.gov             #美国标准技术院的时间自动同步服务器

4. 启动NTP服务器

# 如果计划任务有时间同步,先注释,两种用法会冲突。
[root@ntp ~]# crontab -e
# time sync by ntp at 2016-2-1
#*/5 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1
[root@ntp ~]# /etc/init.d/ntpd start
Starting ntpd:                                             [  OK  ]

[root@ntp~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*time5.aliyun.co 10.137.38.86 2 u 124 64 376 6.887 38.508 12.887
time-c-b.nist.g .STEP. 16 u - 512 0 0.000 0.000 0.000


[root@ntp ~]# ntpstat
synchronised to NTP server (182.92.12.11) at stratum 3
time correct to within 51 ms
polling server every 64 s


[root@lb01 ~]# ntpdate 172.16.1.5
5 Nov 17:04:35 ntpdate[23575]: the NTP socket is in use, exiting

5. 客户机时间同步

 客户机要等几分钟再与新启动的ntp服务器进行时间同步,否则会提示no server suitable for synchronization found错误。

[root@mysql ~]# ntpdate 172.16.1.5
 5 Nov 17:08:46 ntpdate[8747]: adjust time server 172.16.1.5 offset 0.002811 sec
 # 将命令加入定时任务即可

 

posted @ 2017-11-05 17:11  沉心十年  阅读(433)  评论(0编辑  收藏  举报