#!/usr/bin/env bash
# filename: chrony_install.sh
# descript: NTP Service for CentOS-7/RHEL-7
# author: qiush@2016


export bind

yum -y install --enablerepo=base chrony
\mv /etc/chrony.conf /etc/chrony.conf@origin

cat > /etc/chrony.conf <<EOF
# filename: /etc/chrony.conf
#bindaddress 127.0.0.1
bindcmdaddress 127.0.0.1
bindcmdaddress ::1

# More NTP 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

# 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 192.168.30.0/27
#allow 127.0.0.1

#deny 192.168.0.0/16

# Serve time even if not synchronized to a time source.
#local stratum 10

keyfile /etc/chrony.keys
commandkey 1
generatecommandkey

# Specify directory for log files.
logdir /var/log/chrony
EOF

/bin/systemctl restart chronyd
/bin/systemctl enable chronyd
