一、搭建时间同步服务器
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服务
相关文章
本文链接:http://www.it892.com/content/system/centos/2014/article5672.html
推荐阅读
linux操作系统:Robolinux 7.6.2发布
Robolinux 7.6.2 发布,此版本包括 Robolinux Xfce 和 GNOME 7.6.2 ,包括了一些改进和工增强。... [详细]
热点排行