CentOS下快速编译安装NTP时间同步服务器

本文详细介绍如何在服务器上搭建NTP时间同步服务,并配置客户端实现自动时间同步。包括ntpserver的编译安装、配置文件修改、服务启动及状态检查等步骤。

一、搭建时间同步服务器
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
PS: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服务

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值