1、yum install -y ntp
2、修改配置文件 /etc/ntp.conf
如果能够连通外网的情况
把配置文件下面四行注释掉:
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
然后在下面添加这几行:
server 0.cn.pool.ntp.org iburst
server 1.cn.pool.ntp.org iburst
server 2.cn.pool.ntp.org iburst
server 3.cn.pool.ntp.org iburst
如果不能,连通外网的情况
#配置允许NTP Server时间服务器主动修改本机的时间
restrict 10.2.96.200 nomodify notrap noquery
#注释掉其他时间服务器
#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服务器
server 10.2.96.200
3、启动服务
# centos7
systemctl start ntpd
systemctl enable ntpd
# centos6
service ntpd start
chkconfig ntpd on
4、测试服务,查看同步服务
ntpq -p
5、客户端配置/etc/ntp.conf
driftfile /var/lib/ntp/drift
restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict ::1
restrict 10.188.31.168 nomodify notrap noquery
server 10.188.31.168
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor