1. ZZSRV1上的NTP配置
1.1. 安装NTP
# yum list | grep ntp
ntpdate.x86_64 4.2.6p5-18.el7.centos @anaconda
fontpackages-devel.noarch 1.44-8.el7 base
fontpackages-filesystem.noarch 1.44-8.el7 base
fontpackages-tools.noarch 1.44-8.el7 base
ntp.x86_64 4.2.6p5-18.el7.centos base
ntp-doc.noarch 4.2.6p5-18.el7.centos base
ntp-perl.noarch 4.2.6p5-18.el7.centos base
sntp.x86_64 4.2.6p5-18.el7.centos base
# rpm -qa | grep ntp
ntpdate-4.2.6p5-18.el7.centos.x86_64
手工校对一下时间, 现有生产环境中有一个时钟服务器192.168.1.11
# ntpdate 192.168.1.11
11 Aug 20:01:57 ntpdate[2450]: adjust time server 192.168.1.11 offset -0.082365 sec
# hwclock --systohc
# yum -y install ntp
autogen-libopts-5.18-5.el7.x86_64.rpm
ntp-4.2.6p5-18.el7.centos.x86_64.rpm
1.2. 配置
# rpm -qc ntp
/etc/ntp.conf
/etc/ntp/crypto/pw
/etc/sysconfig/ntpd
# cd /etc/
# cp ntp.conf ntp.conf.origin
# vi ntp.conf
删除所有内容,仅保留上游服务器
server 0.centos.pool.ntp.org
server 1.centos.pool.ntp.org
server 2.centos.pool.ntp.org
server 3.centos.pool.ntp.org
# service ntpd start
Redirecting to /bin/systemctl start ntpd.service
查看日志
systemd: Starting Network Time Service...
ntpd[2622]: ntpd [email protected] Wed Jun 18 21:20:36 UTC 2014 (1)
ntpd[2623]: proto: precision = 0.203 usec
ntpd[2623]: 0.0.0.0 c01d 0d kern kernel time sync enabled
ntpd[2623]: Listen and drop on 0 v4wildcard 0.0.0.0 UDP 123
ntpd[2623]: Listen and drop on 1 v6wildcard :: UDP 123
ntpd[2623]: Listen normally on 2 lo 127.0.0.1 UDP 123
ntpd[2623]: Listen normally on 3 eno16777728 192.168.188.11 UDP 123
ntpd[2623]: Listen normally on 4 lo ::1 UDP 123
ntpd[2623]: Listen normally on 5 eno16777728 fe80::20c:29ff:fea4:2e39 UDP 123
ntpd[2623]: Listening on routing socket on fd #22 for interface updates
systemd: Started Network Time Service.
ntpd[2623]: 0.0.0.0 c016 06 restart
ntpd[2623]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM
ntpd[2623]: 0.0.0.0 c011 01 freq_not_set
ntpd[2623]: 0.0.0.0 c614 04 freq_mode
# systemctl enable ntpd
ln -s ‘/usr/lib/systemd/system/ntpd.service‘ ‘/etc/systemd/system/multi-user.target.wants/ntpd.service‘
# netstat -an | grep 123
udp 0 0 192.168.188.11:123 0.0.0.0:*
udp 0 0 127.0.0.1:123 0.0.0.0:*
udp 0 0 0.0.0.0:123 0.0.0.0:*
udp6 0 0 fe80::20c:29ff:fea4:123 :::*
udp6 0 0 ::1:123 :::*
udp6 0 0 :::123 :::*
unix 3 [ ] STREAM CONNECTED 12323
unix 3 [ ] STREAM CONNECTED 16123
unix 3 [ ] STREAM CONNECTED 12324 /run/systemd/journal/stdout
1.3. 测试
在另外一台Linux上进行校时
# ntpdate 192.168.188.11
11 Aug 20:18:15 ntpdate[12840]: adjust time server 192.168.188.11 offset 0.004473 sec
在Windows上进行校时,成功
设置自动校时
# rpm -qc crontabs
/etc/crontab
/etc/sysconfig/run-parts
撰写每天进行校时脚本
# cd /etc/cron.daily/
# ll
total 16
-rwxr-xr-x. 1 root root 332 Jun 27 19:07 0yum-daily.cron
-rwx------. 1 root root 180 Jul 31 2013 logrotate
-rwxr-xr-x. 1 root root 618 Mar 18 00:19 man-db.cron
-rwxr-x---. 1 root root 192 Jan 27 2014 mlocate
# vi checktime.sh
ntpdate 192.168.188.11
hwclock --systohc
# chmod +x checktime.sh
测评一下脚本
# ./checktime.sh
11 Aug 20:25:49 ntpdate[12897]: adjust time server 192.168.188.11 offset 0.003041 sec
# ll
total 20
-rwxr-xr-x. 1 root root 332 Jun 27 19:07 0yum-daily.cron
-rwxr-xr-x 1 root root 41 Aug 11 20:25 checktime.sh
-rwx------. 1 root root 180 Jul 31 2013 logrotate
-rwxr-xr-x. 1 root root 618 Mar 18 00:19 man-db.cron
-rwxr-x---. 1 root root 192 Jan 27 2014 mlocate