习惯用ntpd同步时间,换CentOS7也一样,无意中发现ntpd老是不能随机启动,设置没问题。
上网搜索后,才发现,CentOS7后,用chrony替代了ntpd,虽然后者一样能用,但默认系统已经enable了chrony服务,这导致了ntpd的启动失败。
今天干脆把ntpd卸载了,直接用系统默认的chrony。
- 安装
sudo yum -y install chrony
- 设置/etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# 同步时间源,可以多加
server 0.asia.pool.ntp.org iburst
server 1.asia.pool.ntp.org iburst
server 2.asia.pool.ntp.org iburst
server 3.asia.pool.ntp.org iburst
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
# Ignore stratum in source selection.
stratumweight 0
# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift
# Enable kernel RTC synchronization.
rtcsync
# In first three updates step the system clock instead of slew
# if the adjustment is larger than 10 seconds.
makestep 10 3
# Allow NTP client access from local network.
# 允许同步的IP地址
allow 192.168.1.0/24
allow 10.150.20.0/24
# Listen for commands only on localhost.
bindcmdaddress 127.0.0.1
bindcmdaddress ::1
# Serve time even if not synchronized to any NTP server.
local stratum 10
keyfile /etc/chrony.keys
# Specify the key used as password for chronyc.
commandkey 1
# Generate command key if missing.
generatecommandkey
# Disable logging of client accesses.
noclientlog
# Send a message to syslog if a clock adjustment is larger than 0.5 seconds.
logchange 0.5
logdir /var/log/chrony
#log measurements statistics tracking
- 防火墙设置
sudo firewall-cmd --permanent --add-service=ntp --zone=public #因不对外开放服务,只对内网开放,所以要指定内网的zone
sudo firewall-cmd --reload
- 启动服务
sudo systemctl enable chronyd
sudo systemctl start chronyd
- 查看工作情况
chronyc
具体命令可以用help查询
例:显示系统时间信息
chronyc> tracking
Reference ID : 202.118.1.130 (202.118.1.130)
Stratum : 3
Ref time (UTC) : Mon Jun 19 08:42:53 2017
System time : 0.000746357 seconds fast of NTP time
Last offset : +0.001556008 seconds
RMS offset : 0.001894219 seconds
Frequency : 2.438 ppm fast
Residual freq : +0.142 ppm
Skew : 4.184 ppm
Root delay : 0.059651 seconds
Root dispersion : 0.004491 seconds
Update interval : 518.1 seconds
Leap status : Normal
chronyc>