安装 Kapacitor

1、下载 Kapacitor 二进制文件。
从浏览器下载 Kapacitor 二进制文件。
如果需要,将下载的存档展开 C:\Program Files\InfluxData\ 并重命名文件。
  • Windows Binaries (64-bit) - using PowerShell
> Expand-Archive .\kapacitor-1.6.5_windows_amd64.zip -DestinationPath 'C:\Program Files\InfluxData\'
> mv 'C:\Program Files\InfluxData\kapacitor-1.6.5-1' 'C:\Program Files\InfluxData\kapacitor'
启动 Kapacitor

在Powershell中,通过运行守护进程导航 C:\Program Files\InfluxData\kapacitor 并启动 Kapacitor :kapacitord

首先生成符合当前系统的配置

> cd -Path 'C:\Program Files\InfluxData\kapacitor'
> ./kapacitord config > kapacitor.generated.conf

拷贝 kapacitor.generated.conf 文件中的内容到 kapacitor.conf 并修改配置:

hostname = "localhost"
data_dir = "C:\\Users\\Administrator\\.kapacitor"
skip-config-overrides = false
default-retention-policy = ""

[alert]
  persist-topics = true
  topic-buffer-length = 5000

[auth]
  enabled = false
  cache-expiration = "0s"
  bcrypt-cost = 0
  meta-addr = ""
  meta-username = ""
  meta-password = ""
  meta-use-tls = false
  meta-ca = ""
  meta-cert = ""
  meta-key = ""
  meta-insecure-skip-verify = false

[http]
  bind-address = ":9092"
  auth-enabled = false
  log-enabled = true
  write-tracing = false
  pprof-enabled = false
  https-enabled = false
  https-certificate = "/etc/ssl/kapacitor.pem"
  https-private-key = ""
  shutdown-timeout = "10s"
  shared-secret = ""

[replay]
  dir = "C:\\Users\\Administrator\\.kapacitor\\replay"

[storage]
  boltdb = "C:\\Users\\Administrator\\.kapacitor\\kapacitor.db"

[task]
  dir = "C:\\Users\\Administrator\\.kapacitor\\tasks"
  snapshot-interval = "1m0s"

[fluxtask]
  enabled = false
  task-run-influxdb = ""
  task-run-bucket = "kapacitor_fluxtask_logs"
  task-run-org = ""
  task-run-orgid = ""
  task-run-measurement = "runs"
  default-influxdb = ""

[load]
  enabled = false
  dir = "C:\\Users\\Administrator\\.kapacitor\\load"

[[influxdb]]
  enabled = true
  name = "default"
  default = false
  urls = ["http://localhost:8086"]
  username = ""
  password = ""
  token = "8rjMx1vKndkAq-I7jLymtDWP_YYmFfJ85vpDvJw8u_xE4wFlJb8gQixqJzuuyzOvDGjWckE0gmVlfb9DZySncA=="
  http-shared-secret = false
  ssl-ca = ""
  ssl-cert = ""
  ssl-key = ""
  insecure-skip-verify = false
  timeout = "0s"
  disable-subscriptions = true
  subscription-protocol = "http"
  subscription-mode = "cluster"
  kapacitor-hostname = ""
  http-port = 0
  udp-bind = ""
  udp-buffer = 1000
  udp-read-buffer = 0
  startup-timeout = "5m0s"
  subscriptions-sync-interval = "1m0s"
  subscription-path = ""
  compression = "gzip"
  [influxdb.excluded-subscriptions]
    _kapacitor = ["autogen"]

[logging]
  file = "STDERR"
  level = "DEBUG"

[config-override]
  enabled = true

[tls]
  min-version = ""
  max-version = ""

[collectd]
  enabled = false
  bind-address = ":25826"
  database = "collectd"
  retention-policy = ""
  batch-size = 5000
  batch-pending = 10
  batch-timeout = "10s"
  read-buffer = 0
  typesdb = "/usr/share/collectd/types.db"
  security-level = "none"
  auth-file = "/etc/collectd/auth_file"
  parse-multivalue-plugin = "split"

[opentsdb]
  enabled = false
  bind-address = ":4242"
  database = "opentsdb"
  retention-policy = ""
  consistency-level = "one"
  tls-enabled = false
  certificate = "/etc/ssl/influxdb.pem"
  batch-size = 1000
  batch-pending = 5
  batch-timeout = "1s"
  log-point-errors = true

[alerta]
  enabled = false
  url = ""
  insecure-skip-verify = false
  token = ""
  token-prefix = ""
  environment = ""
  origin = ""
  timeout = "0s"

[bigpanda]
  enabled = false
  global = false
  app-key = ""
  token = ""
  state-changes-only = false
  insecure-skip-verify = false
  url = "https://api.bigpanda.io/data/v2/alerts"
  auto-attributes = "tags,fields"

[[discord]]
  enabled = false
  default = true
  workspace = ""
  url = ""
  timestamp = false
  username = ""
  avatar-url = ""
  embed-title = ""
  global = false
  state-changes-only = false
  ssl-ca = ""
  ssl-cert = ""
  ssl-key = ""
  insecure-skip-verify = false

[hipchat]
  enabled = false
  url = ""
  token = ""
  room = ""
  global = false
  state-changes-only = false

[[kafka]]
  enabled = false
  id = "default"
  timeout = "0s"
  batch-size = 0
  batch-timeout = "0s"
  use-ssl = false
  ssl-ca = ""
  ssl-cert = ""
  ssl-key = ""
  insecure-skip-verify = false
  sasl-username = ""
  sasl-password = ""
  sasl-mechanism = ""
  sasl-gssapi-service-name = ""
  sasl-gssapi-auth-type = ""
  sasl-gssapi-disable-pafxfast = false
  sasl-gssapi-kerberos-config-path = ""
  sasl-gssapi-key-tab-path = ""
  sasl-gssapi-realm = ""
  sasl-access-token = ""

[[mqtt]]
  enabled = false
  name = "default"
  default = false
  url = ""
  ssl-ca = ""
  ssl-cert = ""
  ssl-key = ""
  insecure-skip-verify = false
  client-id = ""
  username = ""
  password = ""

[opsgenie]
  enabled = false
  api-key = ""
  url = "https://api.opsgenie.com/v1/json/alert"
  recovery_url = "https://api.opsgenie.com/v1/json/alert/note"
  global = false

[opsgenie2]
  enabled = false
  api-key = ""
  url = "https://api.opsgenie.com/v2/alerts"
  recovery_action = "notes"
  global = false
  details = false

[pagerduty]
  enabled = false
  url = "https://events.pagerduty.com/generic/2010-04-15/create_event.json"
  service-key = ""
  global = false

[pagerduty2]
  enabled = false
  url = "https://events.pagerduty.com/v2/enqueue"
  routing-key = ""
  global = false

[pushover]
  enabled = false
  token = ""
  user-key = ""
  url = "https://api.pushover.net/1/messages.json"

[[httppost]]
  endpoint = "example"
  url = "http://example.com"
  alert-template = ""
  alert-template-file = ""
  row-template = ""
  row-template-file = ""
  [httppost.basic-auth]
    username = ""
    password = ""

[smtp]
  enabled = false
  host = "localhost"
  port = 25
  username = ""
  password = ""
  no-verify = false
  global = false
  state-changes-only = false
  from = ""
  idle-timeout = "30s"

[snmptrap]
  enabled = false
  addr = "localhost:162"
  community = "kapacitor"
  retries = 1

[sensu]
  enabled = false
  addr = ""
  source = "Kapacitor"

[servicenow]
  enabled = false
  url = "https://instance.service-now.com/api/global/em/jsonv2"
  source = ""
  username = ""
  password = ""
  global = false
  state-changes-only = false

[[slack]]
  enabled = false
  default = true
  workspace = ""
  url = ""
  token = ""
  channel = ""
  username = "kapacitor"
  icon-emoji = ""
  global = false
  state-changes-only = false
  ssl-ca = ""
  ssl-cert = ""
  ssl-key = ""
  insecure-skip-verify = false

[talk]
  enabled = false
  url = ""
  author_name = ""

[teams]
  enabled = false
  channel-url = ""
  global = false
  state-changes-only = false

[telegram]
  enabled = false
  url = "https://api.telegram.org/bot"
  token = ""
  chat-id = ""
  parse-mode = ""
  disable-web-page-preview = false
  disable-notification = false
  global = false
  state-changes-only = false

[victorops]
  enabled = false
  api-key = ""
  routing-key = ""
  url = "https://alert.victorops.com/integrations/generic/20131114/alert"
  global = false
  json-data = false

[zenoss]
  enabled = false
  url = "https://tenant.zenoss.io:8080/zport/dmd/evconsole_router"
  username = ""
  password = ""
  action = "EventsRouter"
  method = "add_event"
  type = "rpc"
  tid = 1
  collector = "Kapacitor"
  global = false
  state-changes-only = false
  [zenoss.severity-map]
    OK = "Clear"
    Info = "Info"
    Warning = "Warning"
    Critical = "Critical"

[reporting]
  enabled = true
  url = "https://usage.influxdata.com"

[stats]
  enabled = true
  stats-interval = "10s"
  database = "_kapacitor"
  retention-policy = "autogen"
  timing-sample-rate = 0.1
  timing-movavg-size = 1000

[udf]

[deadman]
  interval = "10s"
  threshold = 0.0
  id = "{{ .Group }}:NODE_NAME for task '{{ .TaskName }}'"
  message = "{{ .ID }} is {{ if eq .Level \"OK\" }}alive{{ else }}dead{{ end }}: {{ index .Fields \"emitted\" | printf \"%0.3f\" }} points/INTERVAL."
  global = false

基于配置文件启动:

> cd -Path 'C:\Program Files\InfluxData\kapacitor'
> ./kapacitord -config 'C:\Program Files\InfluxData\kapacitor\kapacitor.conf'

将 Kapacitor 注册为本地服务

从网上下载的Windows下的Kapacitor是控制台程序,打开窗口后,很容易被别人给关掉,因此考虑做成Windows服务,nssm正是解决该问题的利器。

1、下载nssm:

下载地址:http://www.nssm.cc/download

查看官网提示,如果是win10,并且更新到了“Creators Update”,应该下载 “nssm 2.24-101-g897c7ad” 版本,否则启动时会报错

2、解压下载的nssm,找到里面的64位版本(我的电脑也是64位的),放到和influxdb同级的目录

在Powershell中,通过运行守护nssm注册服务

> cd -Path 'C:\Program Files\InfluxData\kapacitor'
> ./nssm.exe install KapacitorService

在弹出框中选择Kapacitor的运行程序:

你也可以设置一些其他的服务信息(可选)

点击确定,则成功注册windows服务,如下所示:

到windows服务中,启动 KapacitorService 即可:

如需卸载服务

在Powershell中,通过运行守护nssm注册服务

> cd -Path 'C:\Program Files\InfluxData\kapacitor'
> ./nssm.exe remove KapacitorService

更多使用方式参考官方说明:http://www.nssm.cc/usage

作者:Jeebiz  创建时间:2023-02-08 21:19
最后编辑:Jeebiz  更新时间:2024-02-26 11:18