Press "Enter" to skip to content

月度归档: 2018年9月

KVM VPS重启后hwclock时间发生变化

hwclock就是硬件时间, 类似于物理机上的BIOS time. 这个时间是可以和操作系统的时间不一样的. 如果hwclock是一个错误的时间的话, 一些强烈依赖时间的service就有可能会出错, 本文介绍Ubuntu下面的解决方法.

hwclock时间通常可以使用以下命令来查看

hwclock -r            #查看hwclock时间
hwclock -w --systohc  #将操作系统时间写入hwclock时间

1, 安装htpdate(非必需步骤)
此项非必需. 仅仅是因为我的CloudCone vps屏蔽了ntp使用的UDP 123端口, 我才需要这一步, 对于大多数KVM VPS来说, 这一项是不必要的.

$ apt-get install htpdate
$ systemctl status htpdate.service  #此时应该是默认进入运行状态且系统时间已经同步正确了
 
$ grep -v ^# /etc/default/htpdate   #查看其配置
HTP_SERVERS="www.pool.ntp.org www.ntp.br www.wikipedia.org"
HTP_OPTIONS="-D -s"

2, 编写systemd服务
请注意, 如果你没有执行第一步的话, 请把下方文件中的htpdate.service去掉.

$ vim /etc/systemd/system/hwclock-sync.service    #写入如下内容
[Unit]
  Description=update hwclock time
  After=network-online.target htpdate.service
  Wants=network-online.target htpdate.service

[Service]
  Type=onshot
  ExecStart=/sbin/hwclock -w --systohc
  RemainAfterExit=yes

[Install]
  WantedBy=multi-user.target
Leave a Comment

为什么ntp服务已经运行, 系统时间仍是错误的?(Ubuntu)

用的是CloudCone的VPS, 发现一件很诡异的事情. 系统从没有动过, 安装的ntp服务一直也在运行, 时区也是正确的, 偏偏系统时间是错误的. 即使卸载再重新安装ntp服务也是一样.

问题排除

$ ntpdate -ud ntp.ubuntu.com

17 Sep 14:05:04 ntpdate[9117]: ntpdate [email protected] (1)
Looking for host ntp.ubuntu.com and service ntp
91.189.89.198 reversed to chilipepper.canonical.com
host found : chilipepper.canonical.com
transmit(91.189.89.198)
transmit(91.189.89.199)
transmit(91.189.94.4)
transmit(91.189.91.157)
transmit(91.189.89.198)
transmit(91.189.89.199)
transmit(91.189.94.4)
transmit(91.189.91.157)
transmit(91.189.89.198)
transmit(91.189.89.199)
transmit(91.189.94.4)
transmit(91.189.91.157)
transmit(91.189.89.198)
transmit(91.189.89.199)
transmit(91.189.94.4)
transmit(91.189.91.157)
transmit(91.189.89.198)
transmit(91.189.89.199)
transmit(91.189.94.4)
transmit(91.189.91.157)
91.189.89.198: Server dropped: no data
91.189.89.199: Server dropped: no data
91.189.94.4: Server dropped: no data
91.189.91.157: Server dropped: no data
server 91.189.89.198, port 123
stratum 0, precision 0, leap 00, trust 000
refid [91.189.89.198], 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:  df49c296.3d0a1d7b  Mon, Sep 17 2018 14:05:10.238
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

server 91.189.89.199, port 123
stratum 0, precision 0, leap 00, trust 000
refid [91.189.89.199], 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:  df49c296.703703de  Mon, Sep 17 2018 14:05:10.438
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

server 91.189.94.4, port 123
stratum 0, precision 0, leap 00, trust 000
refid [91.189.94.4], 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:  df49c296.a3685167  Mon, Sep 17 2018 14:05:10.638
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

server 91.189.91.157, port 123
stratum 0, precision 0, leap 00, trust 000
refid [91.189.91.157], 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:  df49c296.d69f3de6  Mon, Sep 17 2018 14:05:10.838
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

17 Sep 14:05:12 ntpdate[9117]: no server suitable for synchronization found
Leave a Comment

Filebeat or Logstash?

Filebeat和Logstash都是ES套件(ES stack)中的组成部分, 其中, Filebeat还是beats家族的成员之一. Filebeat和Logstash都可以将日志文件输出到ElasticSearch, 且众所周知, Filebeat非常轻量级, 而Logstash由于使用JVM的原因性能堪忧, 那么是不是说我们可以抛弃笨重的Logstash了呢?

What is the difference between Logstash and Beats?

Beats are lightweight data shippers that you install as agents on your servers to send specific types of operational data to Elasticsearch. Beats have a small footprint and use fewer system resources than Logstash.

Logstash has a larger footprint, but provides a broad array of input, filter, and output plugins for collecting, enriching, and transforming data from a variety of sources.

翻译:

Logstash和Beats有什么区别?

Beats是轻量级数据托运者,您可以在服务器上将其作为代理安装,以将特定类型的操作数据发送到Elasticsearch。与Logstash相比,节拍占用空间小,使用的系统资源更少。

Logstash具有更大的占用空间,但提供了大量的输入,过滤和输出插件,用于收集,丰富和转换来自各种来源的数据。

Leave a Comment