linux局域网时间统一,Linux 系统局域网时间同步(示例代码)

相对于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] ~]#

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值