Linux下同步系統時鐘

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)



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章