在linux下,我们可以通过自带的NTP(Network Time Protocol)协议通过网络使自己的系统保持精确的时间。可用的公共时间服务器列表可以从下面的地址获取:
http://ntp.isc.org/bin/view/Servers/NTPPoolServers
NTP是用来使系统和一个精确的时间源保持时间同步的协议。建议大家在自己管理的网络中建立至少一台时间服务器来同步本地时间,这样可以使得在不同的系统上处理和收集日志和管理更加容易。
介绍一下环境:179为本地时间服务器,其他服务器和179同步。179和网上时间服务器同步。
一、配置179时间服务器
1、首先查询NTP软件版本
rpm -qa|grep ntp
ntp-4.1.2-4.EL3.1
如果没有可以从linux安装盘上查找,安装此ntp包
2、编辑配置文件
vi /etc/ntp.conf
- server pool.ntp.org # 首先定义服务器
- restrict default nomodify notrap noquery
- restrict 192.168.0.0 mask 255.255.255.0 notrust nomodify notrap #从192.168.0.1-192.168.0.254的服务器都可以使用我们的NTP服务器来同步时间。
- # 注释掉以下一行
- #restrict default ignore
3、启动NTP服务器
- #chkconfig ntpd on
- #/etc/init.d/ntpd start
- #/etc/init.d/ntpd stop
- #/etc/init.d/ntpd restart
默认情况下,我们配置的NTP服务器不会去时间源那里同步时间,所以必须修改/etc/ntp/step-tickers文件,加入我们的时间源,这样每次通过/etc/init.d/ntpd 来启动服务的时候就会自动更新时间了
检查服务器同步状态:
ntpq -p
ntptrace 192.168.0.179
如果输出正确,则说明时间服务器成功。每次启动服务器,会自动同步时间。
二、配置LINUX客户端
在linux客户端上执行ntpdate ntp_server_ip 就可以根据时间服务器统一局域网的时间了,将上面的命令放到cron里每天早上3点定期执行,crontab –e 然后输入:
- 0 3 * * * /usr/sbin/ntpdate 192.168.0.179
************************************************
时间服务器的IP为:192.168.10.1
1). # rpm -ivh ntp-4.1.2-4.EL3.1.i386.rpm
2). # vi /etc/ntp.conf
注释一行
restrict default ignore
加入一行
restrict 192.168.10.0 mask 255.255.255.0 notrust nomodify notrap
3). # vi /etc/ntp/step-tickers
加入一行
pool.ntp.org
这样每次ntpd启动时,会自动连接该国际标准时间服务器;
4). # service ntpd start
5). # netstat -an |grep 123
确保该端口以udp方式开放
时间客户端配置(192.168.10.2)
a. # ntpdate 192.168.10.2
应该显示同步成功
b. # crond -e
加入
0-59/10 * * * * /usr/sbin/ntpdate 192.168.10.1
表示每隔10分钟同步一次时间。
Related Links
Build and Install
Program Manual Pages
- ntpd – Network Time Protocol (NTP) daemon
- ntpq – standard NTP query program
- ntpdc – special NTP query program
- ntpdate – set the date and time via NTP
- sntp – Simple Network Time Protocol (SNTP) client
- ntptrace – trace a chain of NTP servers back to the primary source
- tickadj – set time-related kernel variables
- ntptime – read and set kernel time variables
- ntp-keygen – generate public and private keys
- ntpdsim – Network Time Protocol (NTP) simulator
- Site Map
Configuration Commands and Options
Client and Server Configuration
Reference Clock Support
Reference Clock Audio Drivers
Miscellaneous
External Links
- Computer Network Time Synchronization – The Network Time Protocol (book)
- NTP Public Services Project (home page)
- NTP Research Project (home page)
- Executive Summary: Computer Network Time Synchronization
- The NTP Timescale and Leap Seconds
- NTP Timestamp Calculations
- The NTP Era and Era Numbering
- Timestamp Capture Principles
- Autonomous Configuration
- Autonomous Authentication
- Autokey Protocol
- Autokey Identity Schemes
- Site Map