搭建时间服务器实验

搭建时间服务器,客户端可在每天早晨的9:00整从ntp服务器更新自己的时间

搭建时间服务器

[root@bogon ~]# getenforce                            # 查看 selinux 状态
[root@bogon ~]# systemctl status firewalld            # 查看防火墙状态
[root@bogon ~]# yum install chrony -y                 # 装包
[root@bogon ~]# vim /etc/chrony.conf                  # 编辑配置文件
pool 2.rhel.pool.ntp.org iburst                       # 定义时间服务器从哪里获取
allow 192.168.168.168.0/24                            # 定义客户端同步时间的网段
[root@bogon ~]# systemctl restart chronyd             # 重启服务
[root@bogon ~]# date                                  # 查看时间
[root@bogon ~]# chronyc sources                       # 同步时间

测试

开启另外一台虚拟机并命名为客户端

[root@client ~]# yum install chrony -y                # 装包
[root@client ~]# vim /etc/chrony.conf                 # 编写配置文件
server 192.168.168.128 iburst                         # 从哪里同步时间
[root@client ~]# systemctl restart chronyd            # 重启服务
[root@client ~]# date                                 # 查看时间
[root@client ~]# chronyc sources                      # 同步时间
[root@client ~]# vim /etc/crontab                     # 编写计划任务配置文件
0 9 * * * root chronyc sources 1> /dev/null  2&1      # 每天 9 点执行 chrony sourcees 命令
原文地址:https://www.cnblogs.com/li-qing/p/14120321.html