1. NTP简介
NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议。它的用途是把计算机的时钟同步到世界协调时UTC,其精度在局域网内可达0.1ms,在互联网上绝大多数的地方其精度可以达到1-50ms。
NTP服务器就是利用NTP协议提供时间同步服务的。
2. 环境准备
操作系统 | IP地址 | 主机名 | 备注 |
Centos 7.6 | 192.168.1.20 | NTP-Serve | |
Centos 7.6 | 192.168.1.21 | Client |
3. NTP服务器安装
# 系统自带ntp
[root@NTP-Server ~]# rpm -qa ntp
ntp-4.2.6p5-28.el7.centos.x86_64
#如果没有安装执行以下命令进行安装
[root@NTP-Server ~]# yum -y install ntp
4. 配置NTP服务
[root@NTP-Server ~]# vim /etc/ntp.conf
# 将默认时间同步源注释改用可用源
#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 ntp.aliyun.com iburst
5. 启动NTP服务器
# 如果计划任务有时间同步,先注释,两种用法会冲突。
[root@NTP-Server ~]# crontab -e
#time sync
*/5 * * * * /usr/sbin/ntpdate ntp.aliyun.com >/dev/null
#启动NTP服务
[root@NTP-Server ~]# systemctl start ntpd
[root@NTP-Server ~]# systemctl enable ntpd
6. 客户机时间同步
#客户端修改时间,营造时间不同一致的现象
[root@Client ~]# date -s 20180101
Mon Jan 1 00:00:00 CST 2018
客户机要等几分钟再与新启动的ntp服务器进行时间同步,否则会提示no server suitable for synchronization found错误。
[root@Client ~]# ntpdate 192.168.1.20
1 Jan 00:01:15 ntpdate[8003]: no server suitable for synchronization found
[root@Client ~]# ntpdate 192.168.1.20
28 May 09:51:36 ntpdate[8004]: step time server 203.107.6.88 offset 44272199.612407 sec
# 将命令放入计划任务即可,每个一段时间同步一次
[root@Client ~]# crontab -e
*/5 * * * * /usr/sbin/ntpdate 192.168.1.20 > /dev/null
7. 使用chrony软件搭建NTP服务
安装chrony软件
[root@NTP-Server ~]# yum -y install chrony
配置chrony软件
[root@NTP-Server ~]# vim /etc/chrony.conf
##注释掉系统默认的同步源,在最下面添加可用源
# server 0.centos.pool.ntp.org iburst
# server 1.centos.pool.ntp.org iburst
# server 2.centos.pool.ntp.org iburst
server ntp.aliyun.com iburst
启动chronyd服务
[root@NTP-Server ~]# systemctl start chronyd
[root@NTP-Server ~]# systemctl enable chronyd
编写定时计划
# 如果计划任务有时间同步,先注释,两种用法会冲突。
[root@NTP-Server ~]# crontab -e
#time sync
*/5 * * * * /usr/sbin/ntpdate ntp.aliyun.com >/dev/null
© 版权声明
本站所有内容(包括但不限于文字、图片、视频等)均受到版权法保护,归作者所有,未经授权不得转载、复制或用于其他任何商业目的。
转载请注明出处,并保留原文链接。对于未经授权的使用,我们将保留追究法律责任的权利。
THE END
暂无评论内容