NTP配置实践

本文发布时间: 2019-Mar-22
前言NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议。无论是平时使用的私人计算机还是在工作中搭建的服务器集群,时间的统一性和准确性是十分重要的。本文以自己公司的NTP配置实践过程为例,过程本身并不复杂,原理部分请参考扩展阅读。时间同步真的很重要更新历史2015年06月26日 - 初稿阅读原文 - http://wsgzao.github.io/post/ntp/扩展阅读NTP - http://www.ntp.org/ NTP 服务器 - http://vbird.dic.ksu.edu.tw/linux_server/0440ntp.php准备工作检查NTP是否安装如果缺少NTP服务,请从官方下载适合自己系统的版本#检查rpm包 rpm -qa | grep ntpntp-4.2.4p8-1.16.1yast2-ntp-client-2.17.14-1.10.14手动修改时间选择正确的时区,控制误差在5分钟以内#查看当前时间date2008年 12月 12日 星期五 14:44:12 CSTFri Jun 26 14:51:37 CST 2015#手动修改时间(月/日/年时:分:秒)date -s '1/1/09 00:01'2009年 01月 01日 星期四 00:01:00 CST#手动修改分秒date -s 21:21NTP配置NTP服务端配置服务端时间来源选择上海交通大学网络中心NTP服务器地址#NTP服务端系统版本cat /etc/SuSE-release SUSE Linux Enterprise Server 11 (x86_64)VERSION = 11PATCHLEVEL = 2#编辑ntp配置文件vi /etc/ntp.confserver 202.120.2.101 prefer#server ntp.sjtu.edu.cn#加入自动启动chkconfig ntp on#启动ntp服务service ntp startservice ntp statusservice ntp stop完整的/etc/ntp.conf配置文件如下################################################################################## /etc/ntp.conf#### Sample NTP configuration file.## See package 'ntp-doc' for documentation, Mini-HOWTO and FAQ.## Copyright (c) 1998 S.u.S.E. GmbH Fuerth, Germany.#### Author: Michael Andres, <[email protected]>## Michael Skibbe, <[email protected]>###################################################################################### Radio and modem clocks by convention have addresses in the ## form 127.127.t.u, where t is the clock type and u is a unit ## number in the range 0-3. #### Most of these clocks require support in the form of a ## serial port or special bus peripheral. The particular ## device is normally specified by adding a soft link ## /dev/device-u to the particular hardware device involved, ## where u correspond to the unit number above. ## ## Generic DCF77 clock on serial port (Conrad DCF77)## Address: 127.127.8.u## Serial Port: /dev/refclock-u## ## (create soft link /dev/refclock-0 to the particular ttyS?)### server 127.127.8.0 mode 5 preferserver 202.120.2.101 prefer#### Undisciplined Local Clock. This is a fake driver intended for backup## and when no outside source of synchronized time is available.##server 127.127.1.0 # local clock (LCL)fudge 127.127.1.0 stratum 10# LCL is unsynchronized#### Add external Servers using## # rcntp addserver <yourserver>## #### Miscellaneous stuff##driftfile /var/lib/ntp/drift/ntp.drift # path for drift filelogfile /var/log/ntp # alternate log file# logconfig =syncstatus + sysevents# logconfig =all# statsdir /tmp/ # directory for statistics files# filegen peerstats file peerstats type day enable# filegen loopstats file loopstats type day enable# filegen clockstats file clockstats type day enable## Authentication stuff#keys /etc/ntp.keys # path for keys filetrustedkey 1 # define trusted keysrequestkey 1 # key (7) for accessing server variables# controlkey 15 # key (6) for accessing server variablesNTP客户端配置如无特殊要求,一般使用crontab计划任务同步时间1.crontab计划任务方式配置crontab -e0 0 * * * /usr/sbin/sntp -P no -r 172.16.0.3;hwclock -w2.以服务进程方式实时同步#编辑客户端配置文件vi /etc/ntp.confserver 198.16.2.135#启动服务chkconfig ntp onservice ntp restart#如果相差时间较长,请先手动同步sntp -P no -r 198.16.2.135ntpdate –d 198.16.2.135检查NTP同步状态NTP协议为UDP端口是123,offset时间偏移量以毫秒为单位,注意防火墙的控制策略#查看服务连接和监听ntp:~ # netstat -tlunp | grep ntp udp 0 0 198.17.1.224:123 0.0.0.0:* 28916/ntpd udp 0 0 198.16.2.224:123 0.0.0.0:* 28916/ntpd udp 0 0 127.0.0.2:123 0.0.0.0:* 28916/ntpd udp 0 0 127.0.0.1:123 0.0.0.0:* 28916/ntpd udp 0 0 0.0.0.0:123 0.0.0.0:* 28916/ntpd udp 0 0 ::1:123 :::* 28916/ntpd udp 0 0 fe80::250:56ff:feb9:123 :::* 28916/ntpd udp 0 0 fe80::250:56ff:feb9:123 :::* 28916/ntpd udp 0 0 :::123 :::* 28916/ntpd #查看网络中的NTP服务器,同时显示客户端和每个服务器的关系ntp:~ # ntpq -p remote refid st t when poll reach delay offset jitter==============================================================================*202.120.2.101 202.118.1.81 3 u 5 1024 377 265.748 -2.819 16.138 LOCAL(0) .LOCL. 10 l 34 64 377 0.000 0.000 0.001


(以上内容不代表本站观点。)
---------------------------------
本网站以及域名有仲裁协议。
本網站以及域名有仲裁協議。

2024-Mar-04 02:09pm
栏目列表