linux的NTP时间服务器
NTP时间服务器
作用:提供标准时间
• Network Time Protocol(网络时间协议)
• 它用来同步网络中各个计算机的时间的协议
• 210.72.145.39 (国家授时中心服务器IP地址)
• Stratum(分层设计)
• Stratum层的总数限制在15以内(包括15)
虚拟机A:时间服务器
1.安装软件包chrony
[root@svr7 /]# yum -y install chrony [root@svr7 /]# rpm -q chrony
2.修改配置文件
[root@svr7 /]# vim /etc/chrony.conf #server 0.centos.pool.ntp.org iburst #与谁同步时间 #server 1.centos.pool.ntp.org iburst #iburst表示快速同步 #server 2.centos.pool.ntp.org iburst #server 3.centos.pool.ntp.org iburst 26行 allow all #开头的#去掉,修改为允许所有客户端 29行 local stratum 10 #设置本机为第10层的时间服务器
3.重启时间服务
[root@svr7 /]# systemctl restart chronyd
虚拟机B:客户端
1.安装软件包chrony
[root@pc207 /]# yum -y install chrony
2.修改配置文件
[root@pc207 /]# vim /etc/chrony.conf server 192.168.4.7 iburst #与192.168.4.7同步时间 #server 1.centos.pool.ntp.org iburst #iburst表示快速同步 #server 2.centos.pool.ntp.org iburst #server 3.centos.pool.ntp.org iburst
3.重启时间服务
[root@pc207 /]# systemctl restart chronyd
4.测试:
[root@pc207 /]# date -s "2008-1-1" [root@pc207 /]# date [root@pc207 /]# systemctl restart chronyd [root@pc207 /]# date [root@pc207 /]# date 2020年 11月 19日 星期四 15:44:22 CST
[root@pc207 /]# [root@pc207 /]# chronyc sources -v #列出时间服务器信息
案例1:NTP时间同步
1.1 问题
本例要求配置一台NTP时间服务器,需要完成下列任务:
部署一台NTP时间服务器
设置时间服务器上层与0.centos.pool.ntp.org同步
设置本地服务器层级数量为10
允许192.168.4.0/24网络的主机同步时间
客户端验证时间是否同步
1.2 步骤
实现此案例需要按照如下步骤进行。
步骤一:虚拟机A构建NTP时间服务器
1)使用yum安装bind、bind-chroot软件包
[root@svr7 ~]# yum -y install chrony 已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfiledvd | 3.6 kB 00:00 软件包 chrony-3.2-2.el7.x86_64 已安装并且是最新版本无须任何处理 [root@svr7 ~]# rpm -q chrony chrony-3.2-2.el7.x86_64 [root@svr7 ~]#
2)修改配置文件/etc/chrony.conf
[root@proxy ~]# vim /etc/chrony.conf server 0.centos.pool.ntp.org iburst //server用户客户端指向上层NTP服务器 allow 192.168.4.0/24 //允许那个IP或网络访问NTP local stratum 10 //设置NTP服务器的层数量.. ..
3)重启chronyd服务
[root@mail ~]# systemctl restart chronyd [root@svr7 ~]# firewall-cmd --set-default-zone=trusted #设置防火墙
步骤二:虚拟机B构建NTP时间同步的客户端
1)修改/etc/chrony.conf文件
[root@pc207 ~]# vim /etc/chrony.conf server 192.168.4.7 iburst
2)重启chronyd服务
[root@pc207 ~]# systemctl restart chronyd [root@svr7 ~]# firewall-cmd --set-default-zone=trusted #设置防火墙
3)修改时间进行测试
[root@pc207 ~]# date -s "2008-9-1" 2008年 09月 01日 星期一 00:00:00 CST [root@pc207 ~]# date 2008年 09月 01日 星期一 00:00:01 CST [root@pc207 ~]# systemctl restart chronyd [root@pc207 ~]# date 2008年 09月 01日 星期一 00:01:42 CST [root@pc207 ~]# date 2020年 04月 13日 星期一 18:44:56 CST [root@pc207 ~]# chronyc sources –v #专业查看时间服务端信息命令