安装NTP:
yum install ntp
1)[root@localhost ~]# cat /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.115.110 mask 255.255.255.0 nomodify notrap[U1]
restrict133.100.11.8 mask 255.255.255.0 nomodify notrap[U2]
server133.100.11.8 prefer[U3]
server ntp.nasa.gov
server0.centos.pool.ntp.org
server1.centos.pool.ntp.org
server2.centos.pool.ntp.org
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
driftfile/var/lib/ntp/drift
keys /etc/ntp/keys
logfile/var/log/ntp[U4]
2)[root@localhost ~]# cat /etc/ntp/step-tickers [U5]
Server 133.100.11.8
serverntp.nasa.gov
3)[root@localhost ~]# vim /etc/sysconfig/ntpd
# Drop root toid 'ntp:ntp' by default.
OPTIONS="-untp:ntp -p /var/run/ntpd.pid"
# Set to 'yes'to sync hw clock after successful ntpdate
SYNC_HWCLOCK=yes[U6]
# Additionaloptions for ntpdate
NTPDATE_OPTIONS=""
4)[root@localhost ~]# service ntpd restart
ntpd: 同步时间服务器:[确定]
同步硬件时钟到系统时钟 [确定]
启动 ntpd:[确定]
[root@localhost~]# netstat -lnup|grep ntpd #查看123端口是否打开
udp 0 0 192.168.115.110:123 0.0.0.0:* 4359/ntpd
……..
5)开机自启动设置
[root@localhost~]# chkconfig --list ntpd
ntpd 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭
[root@localhost~]# chkconfig --level 35 ntpd on
[root@localhost~]# chkconfig --list ntpd
ntpd 0:关闭 1:关闭 2:关闭 3:启用 4:关闭 5:启用 6:关闭
6)查看时间是否正确
[root@localhost~]# date #查看系统时间
2013年 07月 20日星期六 18:39:46 CST
[root@localhost~]# hwclock #查看Bios时间
2013年07月20日星期六 19时07分32秒 -0.491867 seconds
7)设置防火墙,不然客户端不能与NTP Server同步
[root@localhost~]# iptables -A INPUT -p UDP -i eth0 -s 192.168.115.0/24 --dport 123 -j ACCEPT
8)查看日志信息
[root@localhost~]# cat /var/log/ntp
20 Jul 18:15:46ntpd[4359]: synchronized to LOCAL(0), stratum 10
20 Jul 18:15:46ntpd[4359]: synchronized to 202.112.31.197, stratum 2
20 Jul 18:21:05ntpd[4359]: synchronized to 133.100.11.8, stratum 1
9)[root@localhost ~]# ntpstat
unsynchronised
polling server every 64 s
[root@localhost~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*clock.tl.fukuok.GPS. 1 u 83 64 326 226.603 -31.129 20.566
xntp-nasa.arc.na.GPS. 1 u 21 64 273 339.440 -143.72 13.075
+dns1.synet.edu.202.118.1.46 2 u 16 64 377 67.670 -51.317 13.595
+dns2.synet.edu.202.118.1.46 2 u 21 64 377 66.114 -50.780 13.107
LOCAL(0) .LOCL. 10 l 24 64 377 0.000 0.000 0.015
[root@30 ~]# ntpdate -u 133.100.11.8
10 Oct 15:46:30 ntpdate[2329]: step time server 133.100.11.8 offset 126250583.351436 sec
Linux 客户端同步
Vim /etc/crontab
0 */2 * * * root /usr/sbin/ntpdate –u ntp.nasa.com
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1
restrict 192.168.110.0 mask 255.255.255.0 nomodify notrap
server 192.168.110.1
server 192.168.110.131
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
logfile /var/log/ntp
[root@desktop2 ~]# cat /etc/ntp/step-tickers //当NTP服务启动时,会自动与该文件中的记录的上层NTP服务进行时间校对
# List of servers used for initial synchronization.
192.168.0.254
[root@desktop2 ~]# cat /etc/sysconfig/ntpd //允许BIOS与系统时间同步
# Drop root to id 'ntp:ntp' by default.
SYNC_HWCLOCK=yes
OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -g"
3、启动NTP服务
[root@desktop2 ~]# service ntpd start
[root@desktop2 ~]# chkconfig ntpd on
4、NTP的测试
[root@desktop2 ~]# ntpstat
synchronised to NTP server (192.168.0.254) at stratum 12 //进行时间校对的NTP服务器
time correct to within 958 ms //本地与上层NTP服务器的时间差
polling server every 64 s //下次同步时间
[root@desktop2 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*instructor.exam LOCAL(0) 11 u 26 64 377 0.807 0.030 0.219
LOCAL(0) .LOCL. 10 l 27 64 377 0.000 0.000 0.000