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


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

cat >/etc/ntp.conf <<EOF
# filename: ntp.conf

driftfile  /var/lib/ntp/drift
pidfile   /var/run/ntpd.pid
logfile /var/log/ntp.log

restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict ::1

# Allow Address
#restrict 10.10.0.0 mask 255.255.0.0 nomodify notrap

# NTP Server Address [Data From: http://www.ntp.org.cn/ http://www.pool.ntp.org/zone/asia]

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 127.127.1.0
fudge 127.127.0 stratum 10

includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
EOF

/bin/systemctl restart ntpd
/bin/systemctl enable ntpd
