惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
罗磊的独立博客
SecWiki News
SecWiki News
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Schneier on Security
IT之家
IT之家
博客园 - 聂微东
T
The Exploit Database - CXSecurity.com
Recorded Future
Recorded Future
大猫的无限游戏
大猫的无限游戏
Know Your Adversary
Know Your Adversary
Latest news
Latest news
Vercel News
Vercel News
G
GRAHAM CLULEY
D
DataBreaches.Net
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
SegmentFault 最新的问题
博客园_首页
雷峰网
雷峰网
T
Tenable Blog
Spread Privacy
Spread Privacy
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
酷 壳 – CoolShell
酷 壳 – CoolShell
Cisco Talos Blog
Cisco Talos Blog
V
Visual Studio Blog
J
Java Code Geeks
博客园 - Franky
The Cloudflare Blog
Apple Machine Learning Research
Apple Machine Learning Research
C
CERT Recently Published Vulnerability Notes
T
Threatpost
Google DeepMind News
Google DeepMind News
F
Fortinet All Blogs
P
Privacy International News Feed
T
Threat Research - Cisco Blogs
T
The Blog of Author Tim Ferriss
V
Vulnerabilities – Threatpost
Recent Announcements
Recent Announcements
Blog — PlanetScale
Blog — PlanetScale
Security Latest
Security Latest
U
Unit 42
M
MIT News - Artificial intelligence
Y
Y Combinator Blog
K
Kaspersky official blog
有赞技术团队
有赞技术团队
B
Blog
腾讯CDC

博客园 - 林杰的博客

7z系列之一:7zip SDK中C++模块的编译 WORD2012 中使用“全屏阅读” Office2012中使用“冻结窗格”功能锁定标题栏 开发工具:Visual Studio 2005下方便宜用的代码行统计工具 为Visual Assist设置快捷键 Visual Studio 2010的Python支持工具 Linux 使用pid文件结束nginx 让Win7资源管理器显示图片内容预览 Python 单元测试带案例名称输出 Editplus中.proto文件的高亮文件 c#美味: 微软图表控件MSChart安装部署 测试工具:用性能监视器查看程序的性能 C#美味:Linq入门 讲座 C++零食:使用Unicode版的预定义宏__FUNCTION__ C++零食:VC中使用ForceInclude来强制包含stdafx.h C++零食:重启后消失的注册表键值 C++零食:WTL中使用双缓冲避免闪烁 C++零食:wprintf 中使用%I64d格式化输出LONGLONG C++零食:HRESULT 与 Windows Error Codes 不是一回事
Linux 系统安装配置NTP时间服务器
林杰的博客 · 2011-03-13 · via 博客园 - 林杰的博客

NTP(The Network Time Protocol) 是网络时间协议,用以同步网络内计算机的时间。
它通过udp包交换,用特定算法进行协商,从而把计算机上的时间与时间服务器上的
时间保持一致。通过互联网它支持的误差是10毫秒,局域网则可以达到200微秒。

NTP时间服务器分为多层,从0层到4层,每层依次与上一次服务器同步,最高层的服务器
则直接连接一个高精度的时钟设备,比如原子钟、GPS或者电波时等。

自己搭建时间服务器需要指定一个上层的时间服务器,然后它可以向局域网内的其它机器
提供同步服务。

详细信息可以见:

    http://en.wikipedia.org/wiki/Network_Time_Protocol

安装NTP Server

Linux系统内核提供了对NTP的支持,因此只需要再安装一个NTP Server的守护进程即可。
常用的ntpd由ntp.org提供。

下载安装ntpd的稳定版本。目前是ntp-4.2.6p3.
   
    http://www.ntp.org/downloads.html

示范脚本::
   
    wget http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-4.2.6p3.tar.gz
    tar zxf ntp-4.2.6p3.tar.gz
    mkdir /app/ntp
    cd ntp-4.2.6p3
    ./configure --prefix=/app/ntp --enable-all-clocks --enable-parse-clocks
    make clean && make check && make && make intall
   
注意:/app/ntp为ntpd的安装后文件路径

配置

1. 配置文件位置为::
   
    /etc/ntp.conf

2. 修改配置允许局域网内机器与该服务器进行时间同步。

    将下面语句::

        restrict default kod nomodify notrap nopeer noquery

    修改为::
       
        restrict default nomodify

3. 修改上一层的时间服务器。

    ntp.org现在提供NTP POOL PROJECT,即ntp 服务器池项目。在中国区域,配置如下即可::

        server 0.cn.pool.ntp.org
    server 0.asia.pool.ntp.org
    server 2.asia.pool.ntp.org

    其中0.cn 是中国服务器池,后面两个是亚洲的服务器池。
   
    最新列表见:
   
        http://www.pool.ntp.org/zone/cn

启动 NTP 服务器

进入ntpd安装后的路径,如/app/ntd, 启动参数如下::

    ./ntpd -c /etc/ntp.conf -p /tmp/ntpd.pid -l /app/ntp/log/ntp.log

注意启动后需要等几分钟,否则其它机器来同步时会得到
   
    no server suitable for synchronization found

的错误。

Linux客户端机器配置

客户端机器使用ntpdate 程序来执行同步。 格式如下::
   
    ntpdate  ntp-server-ip

如果需要配置计划任务,命令如下::

    # 查看是否已经添加时间同步的计划任务
    cat /etc/crontab
   
    # 如果没有则添加下列行,每30分钟同步一次:
    echo '*/30 * * * * root /usr/sbin/ntpdate 10.20.219.43' >> /etc/crontab
   
    # 将计划任务设为自动,默认是启动的【可选】
    chkconfig crond on
   
    # 启动计划任务服务
    service crond restart

    # 有些机器需要设置时区为中国
    cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

Windows客户端机器配置

微软从Windows 2000后支持NTP,由Win32 Time服务提供。

配置的命令行代码如下::

    rem : 将时间同步服务设为自动,默认被禁用 :
    sc config W32Time start= AUTO
    rem : 启动时间同步服务 :
    net start W32Time
    rem : 设置同步选项 , 10.20.222.2 为时间服务器ip 
    w32tm /config /syncfromflags:manual /manualpeerlist:10.20.222.2

    rem : 更新同步选项 :
    w32tm /config /update
    rem : 执行同步 :
    w32tm /resync