2024年6月12日发(作者:)

.....................

ELECTRIC POWER ICT

中图分类号:TP273 文献标志码:A 文章编号:2095-641X(2020)12-066-05 DOI:10.16543/.2020.12.010

著录格式:汪伟,黄少雄,黄太贵,等.Linux对时服务器时钟跳变故障模拟及解决方案[J].电力信息与通信技术,2020,18(12):66-70.

Linux对时服务器时钟跳变故障

模拟及解决方案

汪伟,黄少雄,黄太贵,马金辉

(国网安徽省电力有限公司,安徽 合肥 230022)

Fault Simulation and Solution of Clock Hopping in Linux Time Server

WANG Wei, HUANG Shaoxiong, HUANG Taigui, MA Jinhui

(State Grid Anhui Electric Power Co., Ltd., Hefei 230022, China)

摘要:Linux操作系统由于其运行速度、可高度定制和安全性,成为工业系统服务器应用的广泛解决方案。

对时系统为工业控制系统的正常运行以及数据分析提供了统一的时钟源,是保证系统协调控制与稳定运行

的重要前提。为应对Linux时间服务器可能出现的时钟跳变对系统造成的风险,文章对时钟跳变故障进行

事件模拟,发现时钟跳变故障能够由时间同步命令的漏洞产生。通过模拟故障出现条件,分析了发生时钟

跳变故障的必要条件,通过实验得出2种方案来解决该问题,可以确保服务器系统时钟源的统一与稳定。

方案1保证对时服务器的唯一和准确,确保系统中只有一个对时服务器,或者必须保证不同的对时服务器

之间不存在时间差;方案2用柔性时间调整策略,可以让时间的变化和调整尽量减少对业务的影响。

关键词:时间服务器;时间同步;时钟源;时钟跳变

Abstract: Linux operating system is a popular solution for the application of industrial system servers due to

its speed, high customization and security. The time synchronization system provides a unified clock source

for the normal operation and data analysis of the industrial control system, which is an important prerequisite

for the coordinated control and stable operation of the system. In this paper, event simulation of clock hopping

fault is carried out, and it is found that clock hopping fault can be generated by time synchronization command

vulnerability. In this paper, the necessary conditions for the occurrence of clock hopping fault are analyzed

by simulating the fault occurrence conditions, and two schemes are obtained to solve the problem through

experiments, which can ensure the unification and stability of the clock source of the server system. Scheme 1

guarantees the uniqueness and accuracy of the time server through ensuring that there is only one timing server

in the system or there is no lag between different timing servers. In scheme 2, the flexible time adjustment

strategy can minimize the impact of time changes and adjustments on the business.

Key words: time server; time synchronization; clock source; clock hopping

0 引言

工业控制系统与大规模网络协调控制系统都依

赖于统一的基准时钟

[1]

,以确保控制过程步调的一

致性。在电力系统中,所采用的对时时钟源主要有3

种:北斗卫星、GPS、原子钟

[2-7]

[8]

Prediction System,OPS)

、广域测量系统(Wide

[9]

Area Measurement System,WAMS)

、广域监测

分析保护控制系统(Wide Area Monitoring Analysis

[10]

Protection-control,WARMAP)

等,对时间同步的

需求更为迫切。一旦出现时钟跳变故障,就会导致

电网时间不同步,使电网调度、电网故障分析判断、

实时控制和实时监测系统受到严重的影响,给电网

的正常安全和可靠性运行带来巨大影响

[11-12]

。由于

Linux系统具有开源、透明、可定制的特点,运行速

。对时的方式则采

用脉冲对时、报文对时、B码对时和网络对时等方

式。随着数字电网建设的加快,一些新型的实时监

测控制系统,如电网预防控制在线预测系统(Online

66

电力信息与通信技术

2020年第18卷第12期

ELECTRIC POWER ICT

.....................

度与可靠性均具有明显优势,在包括电网在内的工

业系统服务器有广泛的应用。基于Linux服务器的

对时系统会在特定情况下偶发性地出现时钟跳变现

象,这会给工业应用带来隐患。

时钟跳变现象是指在系统中存在多台服务器为

其他机器提供时间服务时,由于2台时间服务器没有

进行相互同步和备份设置,相互可能存在时间差异,

由此造成系统中的不同机器时间不同步的现象。假

设某服务器由于某种原因发生时间跳变故障,主备机

管理机制会使得该服务器认为包括自身在内的所有

服务器全部超时。该服务器所有应用的状态均被判

定为断网,从而找不到主机,出现数据不刷新的情况。

同时该服务器由于时钟跳变导致无法远程登录,直连

鼠标、键盘无任何响应,显示器无输出,引起部分依托

工作站的应用软件与控制系统瘫痪,带来巨大风险。

为了预防Linux服务器时钟跳变造成的巨大风

险,本文利用3台Linux服务器模拟对时服务协调

过程,并在数据分析的基础上验证了2台对时服务

器时差能够造成使用时间服务的客户机发生时钟跳

变故障。同时还分析了发生时钟跳变故障的必要条

件,并针对同步命令ntpdate的漏洞提出了2种解决

方案。

客户机

workstation

服务器

timeserver2

服务器

timeserver1

表1 服务器和对时客户机配置

Table 1 Server and timing client configuration

Product Name:Hp ProLiant DL180 G6

CPU:Intel(R)Xeon(R)****************

CPU Core:24 core

Mem:48 G

系统版本:Rocky OS 6.0.42.41 x86_64 security (2016-12-01)

ntp软件包版本:ntp 4.2.8p8-x86_64-linx1-Rocky4.2

Ip:172.16.0.126

Product Name:Supermicro X9DRL-3F/IDiF

CPU:Intel(R)Xeon(R)********************

CPU Core:24 core

Mem:16 G

系统版本:Rocky OS 6.0.42.41 x86_64 security (2016-12-01)

ntp 软件包版本:ntp 4.2.8p8-x86_64-linx1-Rocky4.2

Ip:172.16.0.160

Product Name:M4A785TD-V EVO

CPU:AMD Phenom(tm) II X4 945 Processor

CPU Core:4 core

Mem:8 G

系统版本:Rocky OS 6.0.42.41 x86_64 security (2018-05-11)

ntp软件包版本:ntp 4.2.8p10-x86_64-linx-Rocky4.2

Ip:172.16.0.138

1)将时间服务器timeserver2与标准时间服务

器timeserver1之间设置一定时差;

2)在workstation上用root用户执行命令ntpdate

与timeserver1对时,确保workstation时间准确;

3)在workstation上用root用户执行抓包命

令:tcpdump -i eth0 udp port 123 -w two_server_

4)在workstation上使用root用户反复执行多

个ntpdate命令,分别与时间服务器timeserver1和

timeserver2进行对时收集时间记录至 two_server_

5)经过30 min后停止脚本及抓包命令运行,收

集two_server_日志及测试期间

抓取的数据包two_server_文件。

根据对时工作站与标准timeserver1时钟源的时

间差(单位:s)绘制时间跳变曲线,得到3组数据的

对比图形(见图1)。

在workstation上同时运行2个以上ntpdate进

程,分别与2台对时服务器timeserver1和timeserver2

进行对时操作,此时时间开始出现震荡现象,震荡幅

度逐步扩大,从最初的几秒至最后的数百秒,且不可

自行恢复。

测试过程中,多次查看timeserver1和timeserver2

的时间,确定timeserver1和timeserver2时钟源未出

电力信息与通信技术

2020年第18卷第12期

1 时钟跳变故障模拟

为了分析时钟跳变故障所产生的影响和产生故

障的原因,通过更换对时服务器人为设置一定时差,

模拟客户机之后的一系列对时动作,并且对实验数

据进行分析。

离线设置对时客户机workstation和2台对时

服务器timeserver1和timeserver2,通过分析客户机

workstation的对时过程来分析发生时钟跳变故障的

原因,其软件和硬件配置如表1所示。

在测试环境上将对时服务器timeserver1调整

成标准时间,假设由于更换服务器timeserver1操作,

将对时服务器timeserver2与timeserver1之间人为

设置一定时差。对时工作站workstation先与对时服

务器timeserver1对时,确定与timeserver1时间一致

后,模拟发生该现象时系统对时情况。在对时工作

站workstation上用脚本启动多个ntpdate命令,分

别与timeserver1和timeserver2开始对时。选取了

2台时钟源时间相差5 s、30 s、60 s来测试ntpdate

对时功能。其基本步骤如下:

67

.....................

ELECTRIC POWER ICT

5E+09