---
title: "搭建NTP时间服务器 "
author: "falchion"
date: "2010-07-16T11:22:38Z"
tags: ["Linux"]
categories: ["操作系统"]
slug: "ntp"
draft: false
lastmod: "2010-07-16T11:22:38Z"
id: 714222
url: "https://falchion.iteye.com/blog/714222"
---

系统环境：RHEL5 \[ 2.6.18-8.el5xen ]

一. 配置NTP时间服务器器(192.168.1.1)

shell&gt; vi /etc/ntp.conf  
restrict default kod nomodify notrap nopeer noquery  
restrict 127.0.0.1  
#server 0.rhel.pool.ntp.org #//设置网络时间服务器，作为更新源  
#server 1.rhel.pool.ntp.org #//内网中可以注释掉这些行，采用本机硬件时钟作为同步基准  
#server 2.rhel.pool.ntp.org  
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap #//设置客户端网络  
server 127.127.1.0 #//采用本机硬件时钟作为时间源  
fudge 127.127.1.0 stratum 10

shell&gt; /etc/init.d/ntpd start #//等大约5分钟完成本机时间同步以后，方可作为时间服务器使用

二、在客户机进行时间同步

1\. Linux客户机  
shell&gt; ntpdate 192.168.1.1  
shell&gt; hwclock --systohc //以当前系统时间设置硬件时间  
shell&gt; crontab -e  
\* /20 * * * /usr/sbin/ntpdate 192.168.1.1 && hwclock --systohc

※　前面五个\*号代表五个数字，数字的取值范围和含义如下：

分钟（0-59）　小時（0-23）　日期（1-31）　月份（1-12）　星期（0-6）//0代表星期天

设定完毕后，可使用# crontab –l 查看上面的设定。

shell&gt; /etc/init.d/crond start