当前位置: > CentOS > CentOS服务器 > 环境配置 >

Centos 7搭建NTP时间服务器

时间:2016-04-11 22:12来源:linux.it.net.cn 作者:IT
1. NTP简介

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

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

2. NTP服务器安装
1.# 系统自带ntp
2.[root@elk~]# rpm -qa ntp
3.ntp-4.2.6p5-22.el7.centos.1.x86_64
4.# 如果没有就安装
5.yum -y install ntp

3. 配置NTP服务
1.[root@elk~]# vim /etc/ntp.conf
2.# restrict default kod nomodify notrap nopeer noquery
3.restrict default nomodify
4.# nomodify客户端可以同步
5.# 将默认时间同步源注释改用可用源
6.# server 0.centos.pool.ntp.org iburst
7.# server 1.centos.pool.ntp.org iburst
8.# server 2.centos.pool.ntp.org iburst
9.# server 3.centos.pool.ntp.org iburst
10.server ntp1.aliyun.com
11.server time.nist.gov

4. 启动NTP服务器
1.# 如果计划任务有时间同步,先注释,两种用法会冲突。
2.[root@elk~]# crontab -e
3.#*/5 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1
4.[root@elk~]# systemctl start ntpd
5.[root@elk~]# ntpq -p
6. remote refid st t when poll reach delay offset jitter
7.==============================================================================
8.*ntp1.aliyun.com 10.137.38.86 2 u 22 64 1 525.885 -42.367 0.000
9.[root@elk~]# ntpstat
10.synchronised to NTP server (110.75.186.247) at stratum 3
11. time correct to within 4257 ms
12. polling server every 64 s
13.[root@elk~]# ntpdate 192.168.1.63
14. 7 Dec 18:43:07 ntpdate[26950]: the NTP socket is in use, exiting
15.[root@elk~]#firewall-cmd --add-port=123/udp
16.[root@elk~]#firewall-cmd --list-all
17.[root@elk~]#firewall-cmd --reload

5. 客户机时间同步

客户机要等几分钟再与新启动的ntp服务器进行时间同步,否则会提示no server suitable for synchronization found错误。
1.[root@elk~]# ntpdate 192.168.1.63
2. 7 Dec 18:40:16 ntpdate[1453]: step time server 192.168.1.63 offset 40.880807 sec
3. # 将命令放入计划任务即可。
(责任编辑:IT)
------分隔线----------------------------