Jquery中文网 www.jquerycn.cn
Jquery中文网 >  操作系统  >  centos/Redat  >  正文 CentOS下编译安装NTP时间同步服务器的教程

CentOS下编译安装NTP时间同步服务器的教程

发布时间:2014-07-20   编辑:www.jquerycn.cn
CentOS下快速编译安装NTP时间同步服务器的教程

本文教您在centos下编译安装NTP时间同步服务器,感兴趣的朋友可以参考下。

一、搭建时间同步服务器
1、编译安装ntp server

复制代码 代码如下:
[root@server ]# mkdir tools
[root@server ]# cd tools
[root@server tools]# wget http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2.6p5.tar.gz
[root@server tools]# tar xf ntp-4.2.6p5.tar.gz
[root@server tools]# cd ntp-4.2.6p5
[root@server ntp-4.2.6p5]# ./configure --prefix=/usr/local/ntp --enable-all-clocks --enable-parse-clocks
[root@server ntp-4.2.6p5]# make && make install

2、修改配置文件ntp.conf

复制代码 代码如下:
[root@server ~]# cp /etc/ntp.conf /etc/ntp.conf.bak
[root@server ~]# vi /etc/ntp.conf

1)允许任何IP的客户机都可以进行时间同步
将“restrict default kod nomodify notrap nopeer noquery”这行修改成:
restrict default nomodify

2)只允许192.168.1.*网段的客户机进行时间同步
在“restrict default nomodify notrap noquery(表示默认拒绝所有IP的时间同步)”之后增加一行:
restrict 192.168.1.0 mask 255.255.255.0 nomodify

3、启动NTP服务并设置随机启动

复制代码 代码如下:
[root@server ~]# service ntpd start
[root@server ~]# chkconfig --level 35 ntpd on

4、查看ntp服务器工作情况

复制代码 代码如下:
[root@server ~]# netstat -unl |grep 123         #查看123端口,操作结果如图
udp        0      0 192.168.1.41: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:*                             
udp        0      0 fe80::20c:29ff:feb1:123     :::*                                  
udp        0      0 ::1:123                     :::*                                  
udp        0      0 :::123                      :::*

5、查看ntp进程是否正常启动

复制代码 代码如下:
[root@server ~]# ps -ef|grep ntp
ntp      17589     1  0 21:20 ?        00:00:00 ntpd -u ntp:ntp -p /var/run/ntpd.pid -g
root     17607  4441  0 21:26 pts/0    00:00:00 grep ntp

注意:ntpd启动后,客户机要等几分钟再与其进行时间同步,否则会提示“no server suitable for synchronization found”错误。

二、配置时间同步客户机

复制代码 代码如下:

[root@client ~]# date    #同步之前系统时间
2012年 10月 12日 星期五 22:44:08 CST

[root@client ~]# ntpdate 192.168.1.41  #192.168.1.41是NTP服务器的IP

[root@client ~]# hwclock -w   #把时间写入BIOS

[root@client ~]# date    #同步之后系统时间
2012年 10月 11日 星期四 21:45:30 CST 

[root@client ~]# crontab -e   #每天凌晨4点Linux系统自动进行网络时间校准
00 04 * * * /usr/sbin/ntpdate 192.168.1.41; /sbin/hwclock -w

[root@client ~]# service crond restart  #重启crond服务

原文链接:http://300second.blog.51cto.com/7582/1031021

您可能感兴趣的文章:
CentOS下编译安装NTP时间同步服务器的教程
centos和win7双系统时间错误的问题
一键安装与配置NTP server的脚本
MySQL5.7 的编译安装的完整教程
centOS如何升级python
CentOS 下三种 PHP 拓展安装方法
用于 centos6.2 优化的shell脚本
怎么升级python版本
CentOS系统下Apache环境安装GBK编码程序网页乱码问题
如何将Laravel项目搬迁到服务器上

[关闭]