2345技术员联盟

CentOS下搭建时间同步服务器方法

一、搭建时间同步服务器

1、编译安装ntp server

  1. [root@server ]# mkdir tools 
  2. [root@server ]# cd tools 
  3. [root@server tools]# wget http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2.6p5.tar.gz 
  4. [root@server tools]# tar xf ntp-4.2.6p5.tar.gz  
  5. [root@server tools]# cd ntp-4.2.6p5 
  6. [root@server ntp-4.2.6p5]# ./configure --prefix=/usr/local/ntp --enable-all-clocks --enable-parse-clocks 
  7. [root@server ntp-4.2.6p5]# make && make install 

2、修改配置文件ntp.conf

  1. [root@server ~]# cp /etc/ntp.conf /etc/ntp.conf.bak 
  2. [root@server ~]# vi /etc/ntp.conf 

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

  1. restrict default nomodify 

2)只允许192.168.1.*网段的客户机进行时间同步

在“restrict default nomodify notrap noquery(表示默认拒绝所有IP的时间同步)”之后增加一行:

  1. restrict 192.168.1.0 mask 255.255.255.0 nomodify 

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

  1. [root@server ~]# service ntpd start 
  2. [root@server ~]# chkconfig --level 35 ntpd on 

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

  1. [root@server ~]# netstat -unl |grep 123         #查看123端口,操作结果如图 
  2. udp        0      0 192.168.1.41:123            0.0.0.0:*                                
  3. udp        0      0 127.0.0.1:123               0.0.0.0:*                                
  4. udp        0      0 0.0.0.0:123                 0.0.0.0:*                                
  5. udp        0      0 fe80::20c:29ff:feb1:123     :::*                                     
  6. udp        0      0 ::1:123                     :::*                                     
  7. udp        0      0 :::123                      :::* 

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

  1. [root@server ~]ps -ef|grep ntp  
  2. ntp      17589     1  0 21:20 ?        00:00:00 ntpd -u ntp:ntp -p /var/run/ntpd.pid -g 
  3. root     17607  4441  0 21:26 pts/0    00:00:00 grep ntp 

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

二、配置时间同步客户机

  1. [root@client ~]# date    #同步之前系统时间 
  2. 2012年 10月 12日 星期五 22:44:08 CST 
  3. [root@client ~]# ntpdate 192.168.1.41  #192.168.1.41是NTP服务器的IP 
  4. [root@client ~]# hwclock -w   #把时间写入BIOS 
  5. [root@client ~]# date    #同步之后系统时间 
  6. 2012年 10月 11日 星期四 21:45:30 CST   
  7. [root@client ~]# crontab -e   #每天凌晨4点Linux系统自动进行网络时间校准 
  8. 00 04 * * * /usr/sbin/ntpdate 192.168.1.41; /sbin/hwclock -w 
  9. [root@client ~]# service crond restart  #重启crond服务 
本文来自电脑技术网www.it892.com),转载本文请注明来源.
本文链接:http://www.it892.com/content/system/centos/2014/article5672.html
热点排行
无觅相关文章插件,快速提升流量