1、轻量级,不启动服务,使用ntpdate和crontab做定时时间修正,比较暴力
#安装ntpdate
yum -y install ntpdate;
#时间修正,同aliyun的时间服务器
ntpdate ntp1.aliyun.com;
#修改crontab作业列表,重启系统或重启crond服务即可定时修正时间
/bin/crontab -l > /tmp/crontab.bak;
echo '* */1 * * * /sbin/ntpdate ntp1.aliyun.com ntp2.aliyun.com ntp3.aliyun.com ntp4.aliyun.com ntp5.aliyun.com ntp6.aliyun.com ntp7.aliyun.com;/sbin/hwclock -w;' >> /tmp/crontab.bak;
/bin/crontab /tmp/crontab.bak;
2、自动校时,需启动ntp服务,时间慢慢校正
#安装ntp
yum -y install ntp;
#修改/etc/ntp.conf配置文件
/usr/bin/sed -i.ori 's#restrict default.*noquery#restrict default nomodify#;13i\restrict 0.centos.pool.ntp.org nomodify notrap noqueryrestrict 1.centos.pool.ntp.org nomodify notrap noqueryrestrict 2.centos.pool.ntp.org nomodify notrap noqueryrestrict 3.centos.pool.ntp.org nomodify notrap noqueryrestrict 4.ntp1.aliyun.com nomodify notrap noquery' /etc/ntp.conf;
/usr/bin/sed -i.ori '29a\server ntp1.aliyun.comserver time.nist.gov' /etc/ntp.conf;
#启
#安装ntpdate
yum -y install ntpdate;
#时间修正,同aliyun的时间服务器
ntpdate ntp1.aliyun.com;
#修改crontab作业列表,重启系统或重启crond服务即可定时修正时间
/bin/crontab -l > /tmp/crontab.bak;
echo '* */1 * * * /sbin/ntpdate ntp1.aliyun.com ntp2.aliyun.com ntp3.aliyun.com ntp4.aliyun.com ntp5.aliyun.com ntp6.aliyun.com ntp7.aliyun.com;/sbin/hwclock -w;' >> /tmp/crontab.bak;
/bin/crontab /tmp/crontab.bak;
2、自动校时,需启动ntp服务,时间慢慢校正
#安装ntp
yum -y install ntp;
#修改/etc/ntp.conf配置文件
/usr/bin/sed -i.ori 's#restrict default.*noquery#restrict default nomodify#;13i\restrict 0.centos.pool.ntp.org nomodify notrap noqueryrestrict 1.centos.pool.ntp.org nomodify notrap noqueryrestrict 2.centos.pool.ntp.org nomodify notrap noqueryrestrict 3.centos.pool.ntp.org nomodify notrap noqueryrestrict 4.ntp1.aliyun.com nomodify notrap noquery' /etc/ntp.conf;
/usr/bin/sed -i.ori '29a\server ntp1.aliyun.comserver time.nist.gov' /etc/ntp.conf;
#启
