LINUX服务器系统时钟同步

说明:同步8LINUX服务器。

l192.168.1.1NTP服务器,其它7部服务器为NTP Client

其他的服务器IP分别为192.168.1.2 1.3 1.4 1.5 1.6 1.7 1.8

1. 配置NTP SERVER

1)查看1.1上是否安装NTP服务器

#rpm -qa | grep^ntp

ntp-4.2.2p1-15.el5_7.1

2)修改配置文件/etc/ntp.conf

#vim/etc/ntp.conf

restrict defaultkod nomodify notrap nopeer noquery

restrict -6default kod nomodify notrap nopeer noquery

restrict127.0.0.1

restrict -6 ::1

restrict192.168.1.0 mask 255.255.255.0 nomodify

server 127.127.1.0 # local clock

fudge 127.127.1.0 stratum 10

driftfile/var/lib/ntp/drift

keys /etc/ntp/key

3)启动ntp服务

service ntpdstart

Startingntpd: [ OK ]

4)查看端口

netstat -tlunp |grep ntp

udp 0 0 192.168.1.1:123 0.0.0.0:* 6604/ntpd

udp 0 0 127.0.0.1:123 0.0.0.0:* 6604/ntpd

udp 0 0 0.0.0.0:123 0.0.0.0:* 6604/ntpd

udp 0 0 ::1:123 :::* 6604/ntpd

udp 0 0 fe80::a00:27ff:fe02:123 :::* 6604/ntpd

udp 0 0 :::123 :::* 6604/ntpd

5)查看NTP服务器是否与上层联机。

# ntpstat

unsynchronised

time server re-starting

polling server every 64 s

上面表示未同步,注意,严格来说,这并不是一个错误,而是由于每次重启NTP服务器之后大约要35分钟客户端才能与server建立正常的通讯连接。当此时用客户端连接服务端就会报这样的信息。一般等待几分钟就可以了

# ntpstat

synchronised tolocal net at stratum 11

timecorrect to within 73 ms

polling server every 64 s

当显示如上面时,表示已经同步。

6)需要放行NTP SERVER port123防火墙( iptables)。

2. 配置NTP Client

1)在NTP Client端主机中crontab –e中新增一行(192.168.1.1NTP SERVERIP),表示每天00:00同步NTP SERVER时钟,并将系统时钟同步到硬件时钟

# crontab –e

00 00 * * *(/usr/sbin/utpdate 192.168.1.1 && hwclock -w)