相对于NTP服务, rdate显得更轻巧,而且配置、操作都极其简单。
以CentOS6.x系统为例(zabbix为时间服务器, oracle为客户端):
一、选一台服务器作为时间同步服务器,开启time-stream,由于其是由xinetd守护进程管理的,确定已经安装。[[email protected] ~]#
[[email protected] ~]# chkconfig –list | egrep ‘(xinetd|time-stream)‘
xinetd 0:off1:off2:off3:on4:on5:on6:off
xinetd based services:
daytime-stream:off
time-stream: off
[[email protected] ~]#
可以确认守护进程xinetd已经安装,但time-stream是关闭的
二、开启time-stream服务[[email protected] ~]# vi /etc/xinetd.d/time-stream
service time
{
# This is for quick on or off of the service
disable = no
保证, disable = no 即可, 重启xinetd服务[[email protected] ~]# service xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
[[email protected] ~]# chkconfig –list | egrep ‘(xinetd|time-stream)‘
xinetd 0:off1:off2:off3:on4:on5:on6:off
xinetd based services:
daytime-stream:off
time-stream: on
[[email protected] ~]# netstat -antp | grep xinetd
tcp 0 0 :::37 :::* LISTEN 2185/xinetd
[[email protected] ~]#
time-stream已经开启, 由于此服务使用的是tcp 37端口,请确定防火墙已经开放。
三、需要同步时间的服务器,安装rdate工具即可实现同步了[[email protected] xinetd.d]# yum install -y rdate
[[email protected] xinetd.d]# rpm -q rdate
rdate-1.4-16.el6.x86_64
[[email protected] xinetd.d]# rdate 172.16.1.60
rdate: [172.16.1.60]Tue Oct 25 22:32:32 2016
[[email protected] xinetd.d]# rdate -s 172.16.1.60
[[email protected] xinetd.d]# date
Tue Oct 25 22:32:45 CST 2016
[[email protected] xinetd.d]#
不指定参数可查看时间服务器的时间, 指定“-s”参数即可实现同步。
当然, 服务器端也可是使用udp协议,只需要开启time-dgram服务即可[[email protected] ~]# chkconfig –list | grep -E ‘(dgram|stream)‘
chargen-dgram: off
chargen-stream:off
daytime-dgram: off
daytime-stream:off
discard-dgram: off
discard-stream:off
echo-dgram: off
echo-stream: off
time-dgram: on
time-stream: on
[[email protected] ~]# netstat -anp | grep xinetd|grep 37
tcp 0 0 :::37 :::* LISTEN 2185/xinetd
udp 0 0 :::37 :::* 2185/xinetd
[[email protected] ~]#
客户端查看和同步服务器时间需要指定 “-u”参数[[email protected] ~]#
[[email protected] ~]# rdate -u 172.16.1.60
rdate: [172.16.1.60]Tue Oct 25 22:39:56 2016
[[email protected] ~]# rdate -s -u 172.16.1.60
[[email protected] ~]#
[[email protected] ~]# date
Tue Oct 25 22:40:03 CST 2016
[[email protected] ~]#