centos 系统使用chronyd 进行局域网时间同步
注意: 没有编写程序介绍说明, 纯操作流程
-
安装
chrony程序sudo yum install -y chrony -
编辑配置文件
/etc/chronyd.conf## 注意修改配置文件后需要重启才能生效 vim /etc/chrony.conf -
添加配置信息
## 设置为阿里云 ntp 时间同步 server ntp1.aliyun.com iburst server ntp2.aliyun.com iburst server ntp3.aliyun.com iburst ## 允许网段配置 allow 110.0.0.0/16 -
全部配置信息(局域网同步服务器)
# Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). #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 ## 设置为阿里云 ntp 时间同步 server ntp1.aliyun.com iburst server ntp2.aliyun.com iburst server ntp3.aliyun.com iburst # Record the rate at which the system clock gains/losses time. driftfile /var/lib/chrony/drift # Allow the system clock to be stepped in the first three updates # if its offset is larger than 1 second. makestep 1.0 3 # Enable kernel synchronization of the real-time clock (RTC). rtcsync # Enable hardware timestamping on all interfaces that support it. #hwtimestamp * # Increase the minimum number of selectable sources required to adjust # the system clock. #minsources 2 # Allow NTP client access from local network. ## 允许网段配置 allow 0.0.0.0/16 # Serve time even if not synchronized to a time source. #local stratum 0 # Specify file containing keys for NTP authentication. #keyfile /etc/chrony.keys # Specify directory for log files. logdir /var/log/chrony # Select which information is logged. #log measurements statistics tracking -
从节点服务器配置
## 设置主要同步服务器id 例如: 110.0.100.136 server 110.0.100.136 iburst -
chrony相关命令#### centos7 #### ## 查看服务状态 sudo systemctl status chronyd ## 启动服务 sudo systemctl start chronyd ## 停止服务 sudo systemctl stop chronyd ## 重启服务 sudo systemctl restart chronyd ## 检验时间同步状态 sudo chronyc tracking #### centos7 #### #### centos6.5 #### ## 只需要将 systemctl 改为 service 即可,并且 操作动作放置后面 ## 例如: 启动服务 ## sudo service chronyd start #### centos6.5 #### -
设置为开机启动()
#### centos7 #### ## 设置开机启动 sudo systemctl enable chronyd ## 查看是否设置成开机启动 sudo systemctl is-enabled chronyd #### centos7 #### #### centos6.5 #### ## 设置开机启动 sudo chkconfig chronyd on ## 查看是否设置成开机启动 systemctl list-unit-files --type=service | grep chronyd #### centos6.5 #### -
检查时间
## 简单显示出当前时间 date ## 详细显示日期时间等信息 timedatectl
遇到的问题及解决方案
-
执行
yum install chrony -y##无法检索镜像列表问题 ## 解决方案- 更换镜像源(阿里云镜像源) sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak sudo curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo ## 清理并重建缓存 sudo yum clean all sudo yum makecache
浙公网安备 33010602011771号