5 May 19:56:25 ntpdate[27227]: adjust time server 192.168.2.28 offset 0.000300 sec
E. 启动客户端的ntp服务
[root@localhost ~]# service ntpd status
ntpd dead but pid file exists
[root@localhost ~]# service ntpd start
Starting ntpd: [ OK ]
[root@localhost ~]# service ntpd status
ntpd (pid 27248) is running…
[root@localhost ~]#
配置其自启动的级别
[root@localhost ~]# chkconfig --list |grep ntp
ntpd 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭
[root@localhost ~]# chkconfig --level 5 ntpd on
[root@localhost ~]# chkconfig --list |grep ntp
ntpd 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:启用 6:关闭
[root@localhost ~]#
##########################################################################
方法二:
环境:ntp server是redhat4
client是centos5
除了用上面的ntp协议来实现时间的同步外,还可以用date和ntpdate命令做定时任务来实现和远程服务器同步时间。例如
(一)。ntp server端的配置:
1.查看ntp协议是否安装
2.修改ntp.conf
3.启动ntp服务
实际步骤:
1.查看ntp协议是否安装
[root@svr-db-test ~]# rpm -qa | grep ntp
ntp-4.2.2p1-5.el5
chkfontpath-1.10.1-1.1
You have new mail in /var/spool/mail/root
如果没有安装,可以用rpm -Uvh ntp*.rpm或者yum命令安装
2.修改ntp.conf
修改这个配置文件是为了让远程客户端有权来同步时间
[root@svr-db-test ~]# vi /etc/ntp.conf
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
#skate modify
#restrict default kod nomodify notrap nopeer noquery
#restrict -6 default kod nomodify notrap nopeer noquery
#skate modify
#skate add
restrict default kod nomodify nopeer noquery
restrict -6 default kod nomodify nopeer noquery
#skate add
# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict -6 ::1
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool .
server 0.rhel.pool.ntp.org
server 1.rhel.pool.ntp.org
server 2.rhel.pool.ntp.org
#broadcast 192.168.1.255 key 42 # broadcast server
#broadcastclient # broadcast client
#broadcast 224.0.1.1 key 42 # multicast server
#multicastclient 224.0.1.1 # multicast client
#manycastserver 239.255.254.254 # manycast server
#manycastclient 239.255.254.254 key 42 # manycast client
# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available.
server 127.127.1.0 # local clock
server 192.168.2.245
fudge 127.127.1.0 stratum 10
# Drift file. Put this in a directory which the daemon can write to.
# No symbolic links allowed, either, since the daemon updates the file
# by creating a temporary in the same directory and then rename()'ing
# it to the file.
driftfile /var/lib/ntp/drift
# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys
# Specify the key identifiers which are trusted.
#trustedkey 4 8 42
# Specify the key identifier to use with the ntpdc utility.
#requestkey 8
# Specify the key identifier to use with the ntpq utility.
#controlkey 8
[root@svr-db-test ~]#
注意:这个文件这里有两种修改方法:
A、第几种配置:允许任何IP的客户机都可以进行时间同步
将"restrict default kod nomodify notrap nopeer noquery"这行修改成:
restrict default kod nomodify notrap nopeer
B、第二种配置:只允许192.168.211.***网段的客户机进行时间同步
在restrict default kod nomodify notrap nopeer noquery(表示默认拒绝所有IP的时间同步)之后增加一行:
restrict 192.168.211.0 mask 255.255.255.0 nomodify notrap
但是在我的修改中我只是把"restrict default kod nomodify notrap nopeer noquery"改为
"restrict default kod nomodify nopeer noquery"
为什么这么做呢?如果不去掉notrap的话,在客户端同步时间会报错,例如:
[root@localhost ~]# ntpdate 192.168.2.203
5 May 21:35:14 ntpdate[27467]: no server suitable for synchronization found
[root@localhost ~]# ntpdate -u 192.168.2.203
5 May 21:35:07 ntpdate[27466]: no server suitable for synchronization found
[root@localhost ~]# ntpdate -d 192.168.2.203
5 May 21:35:20 ntpdate[27470]: ntpdate 4.2.0a@1.1190-r Mon Jul 28 11:06:17 EDT 2008 (1)
Looking for host 192.168.2.203 and service ntp
host found : 192.168.2.203
transmit(192.168.2.203)
transmit(192.168.2.203)
transmit(192.168.2.203)
transmit(192.168.2.203)
transmit(192.168.2.203)
192.168.2.203: Server dropped: no data
server 192.168.2.203, port 123
stratum 0, precision 0, leap 00, trust 000
refid [192.168.2.203], delay 0.00000, dispersion 64.00000
transmitted 4, in filter 4
reference time: 00000000.00000000 Thu, Feb 7 2036 14:28:16.000
originate timestamp: 00000000.00000000 Thu, Feb 7 2036 14:28:16.000
transmit timestamp: cf8bf29b.578ef34d Wed, May 5 2010 21:35:23.342
filter delay: 0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000
filter offset: 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000
delay 0.00000, dispersion 64.00000
offset 0.000000
5 May 21:35:24 ntpdate[27470]: no server suitable for synchronization found


热门课程培训
热门培训机构
