ntp时间服务器项目,CentOS项目实例之八--NTP时钟服务器配置

在ZZSRV1上安装并配置了NTP服务,通过yum安装ntp相关包,手动校对时间后使用ntpdate与192.168.1.11同步。配置文件中设置为从centos.pool.ntp.org的四个服务器获取时间。启动ntpd服务,并设置为开机启动。通过netstat验证监听状态。在另一台Linux和Windows系统上成功校时,创建cron脚本每天定时校准时间。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 4.2.6p5@1.2349-o 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值