【监控】Hertzbeat在docker的安装与部署

【监控】Hertzbeat在docker的安装与部署_第1张图片

目录

  • 前言
  • TDengine
    • 安装部署
    • 数据库配置
  • Hertzbeat
    • 配置与安装部署
    • 运行
  • 参考

前言

HertzBeat赫兹跳动 是一个拥有强大自定义监控能力,无需 Agent 的开源实时监控告警系统。集 监控+告警+通知 为一体,支持对应用服务,数据库,操作系统,中间件,云原生,网络等监控,阈值告警通知一步到位,只需在浏览器配置YML就能使用这些协议去自定义采集任何想要的指标。拥有更自由化的阈值规则(计算表达式),邮件 Discord Slack Telegram 钉钉 微信 飞书 短信 Webhook 等方式及时送达。

本文记录hertzbeat在docker的简单安装部署:

前期环境配置可以参考:

1)【虚拟机】vmware虚拟机创建 centos7系统配置

2)【虚拟机】【ssh】本地ssh连接虚拟机 - Xshell配置与虚拟机ip配置

3)【Docker】【IDEA】springboot项目在服务器docker容器化部署,IDEA远程debug

TDengine

TDengine 是一款开源、云原生的时序数据库,专为物联网、工业互联网、金融、IT 运维监控等场景设计并优化。HertzBeat的历史数据存储依赖时序数据库 TDengine。我们先安装TDengine时序数据集.

安装部署

docker拉取TDengine镜像:

docker pull tdengine/tdengine

结果如下:

[root@docker zengweiyu]# docker pull tdengine/tdengine
Using default tag: latest
Trying to pull repository docker.io/tdengine/tdengine ...
latest: Pulling from docker.io/tdengine/tdengine
7c457f213c76: Pull complete
4f4fb700ef54: Pull complete
ace7bebcf257: Pull complete
1f27396f6efc: Pull complete
1943f503fd5c: Pull complete
5f19bc842b7f: Pull complete
Digest: sha256:a7b599a377e088232204b9a996beba6fd78c7ee836a1992a61801c3331a42032
Status: Downloaded newer image for docker.io/tdengine/tdengine:latest

【监控】Hertzbeat在docker的安装与部署_第2张图片

启动前需要先把需要挂载的目录先创建好,我们有命令:

mkdir -p /usr/tdengine/taos/data
mkdir -p /usr/tdengine/taos/log

注意:TDengine启动前 /usr/tdengine/taos/data 目录必须清空,否则无法启动。

我们启动TDengine:

docker run -d -p 6030-6049:6030-6049 -p 6030-6049:6030-6049/udp \
     -e TZ=Asia/Shanghai \
     -v /usr/tdengine/taos/data:/var/lib/taos \
     -v /usr/tdengine/taos/log:/var/log/taos \
     --name tdengine --privileged=true tdengine/tdengine:latest
	 

其中:

--name tdengine:指定容器名称
-p 6030-6035:6030-6035
-p 6030-6035:6030-6035/udp 映射taos客户端使用端口,必须包含TCP和UDP
-v /usr/tdengine/taos/data:/var/lib/taos:映射数据目录
-v /usr/tdengine/taos/log:/var/log/taos:映射日志目录

执行后有:


[root@docker tdengine]# docker run -d -p 6030-6049:6030-6049 -p 6030-6049:6030-6049/udp \
>      -e TZ=Asia/Shanghai \
>      -v /usr/tdengine/taos/data:/var/lib/taos \
>      -v /usr/tdengine/taos/log:/var/log/taos \
>      --name tdengine --privileged=true tdengine/tdengine:latest
d338e4e2bf7829717b69b51583a3ae3f67c02e61974dff01b9ab24585139617c

在这里插入图片描述

docker 查看 container进程:

docker ps

【监控】Hertzbeat在docker的安装与部署_第3张图片

TDengine启动成功。

数据库配置

接下来进入TDengine中初始化我们用于记录监控数据需要的数据库和数据表:

docker exec -it tdengine /bin/bash

依次输入

taos
show databases;
CREATE DATABASE hertzbeat KEEP 90 DURATION 10 BUFFER 16;
alter user root pass '123456';
quit
exit

如下:

[root@docker tdengine]# docker exec -it tdengine /bin/bash
root@d338e4e2bf78:~# taos
Welcome to the TDengine Command Line Interface, Client Version:3.0.5.0
Copyright (c) 2022 by TDengine, all rights reserved.

  ********************************  Tab Completion  ************************************
  *   The TDengine CLI supports tab completion for a variety of items,                 *
  *   including database names, table names, function names and keywords.              *
  *   The full list of shortcut keys is as follows:                                    *
  *    [ TAB ]        ......  complete the current word                                *
  *                   ......  if used on a blank line, display all supported commands  *
  *    [ Ctrl + A ]   ......  move cursor to the st[A]rt of the line                   *
  *    [ Ctrl + E ]   ......  move cursor to the [E]nd of the line                     *
  *    [ Ctrl + W ]   ......  move cursor to the middle of the line                    *
  *    [ Ctrl + L ]   ......  clear the entire screen                                  *
  *    [ Ctrl + K ]   ......  clear the screen after the cursor                        *
  *    [ Ctrl + U ]   ......  clear the screen before the cursor                       *
  **************************************************************************************

Server is Community Edition.

taos> show databases;
              name              |
=================================
 information_schema             |
 performance_schema             |
Query OK, 2 row(s) in set (0.002187s)

taos> CREATE DATABASE hertzbeat KEEP 90 DURATION 10 BUFFER 16;
Create OK, 0 row(s) affected (0.711618s)

taos> alter user root pass '123456';
Query OK, 0 row(s) affected (0.002944s)

taos> quit
root@d338e4e2bf78:~# exit
exit
[root@docker tdengine]#
[root@docker tdengine]#

这里在TDengine创建一个名为 hertzbeat 的库,这个库的数据将保留90天(超过90天将被自动删除),每 10 天一个数据文件,内存块数为 16,允许更新数据。



Hertzbeat

配置与安装部署

docker拉取Hertzbeat镜像:

docker pull tancloud/hertzbeat

有如下:

[root@docker tdengine]# docker pull tancloud/hertzbeat
Using default tag: latest
Trying to pull repository docker.io/tancloud/hertzbeat ...
latest: Pulling from docker.io/tancloud/hertzbeat
751ef25978b2: Pull complete
140e22108c7d: Pull complete
993077aca88e: Pull complete
d1a940e1e4e8: Pull complete
fa84f2de330f: Pull complete
91a75a310198: Pull complete
b0d19efe1871: Pull complete
4f4fb700ef54: Pull complete
Digest: sha256:7c4526d0e4f8b4f1e637670f5af80fc5aef3d13a23208952d37e1d9a49855082
Status: Downloaded newer image for docker.io/tancloud/hertzbeat:latest

【监控】Hertzbeat在docker的安装与部署_第4张图片

创建/data/hertzbeat目录:

mkdir -p /data/hertzbeat

/data/hertzbeat ,我们配置一下hertzbeat的配置文件application.yml和sureness.yml:

vi application.yml

完整配置如下:

# application.yml
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
server:
  port: 1157
spring:
  application:
    name: ${HOSTNAME:@hertzbeat@}${PID}
  profiles:
    active: prod
  mvc:
    static-path-pattern: /**
  jackson:
    default-property-inclusion: ALWAYS
  web:
    resources:
      static-locations:
        - classpath:/dist/
        - classpath:../dist/
  # need to disable spring boot mongodb auto config, or default mongodb connection tried and failed..
  autoconfigure:
    exclude: org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration, org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration
  thymeleaf:
    prefix: classpath:/templates/
    check-template-location: true
    cache: true
    suffix: .html
    mode: HTML
	
management:
  endpoints:
    web:
      exposure:
        include: '*'
    enabled-by-default: off
	
sureness:
  auths:
    - digest
    - basic
    - jwt
  jwt:
    secret: 'CyaFv0bwq2Eik0jdrKUtsA6bx3sDJeFV643R
             LnfKefTjsIfJLBa2YkhEqEGtcHDTNe4CU6+9
             8tVt4bisXQ13rbN0oxhUZR73M6EByXIO+SV5
             dKhaX0csgOCTlCxq20yhmUea6H6JIpSE2Rwp'
			 
---
spring:
  config:
    activate:
      on-profile: prod
  datasource:
    driver-class-name: org.h2.Driver
    username: sa
    password: 123456
    url: jdbc:h2:./data/hertzbeat;MODE=MYSQL
    hikari:
      max-lifetime: 120000
  jpa:
    hibernate:
      ddl-auto: update
  # Not Require, Please config if you need email notify
  # 非必填:不使用邮箱作为警告通知可以去掉spring.mail配置
  mail:
    # Attention: this is mail server address.
    # 请注意此为邮件服务器地址:qq邮箱为 smtp.qq.com qq企业邮箱为 smtp.exmail.qq.com
    host: smtp.exmail.qq.com
    username: [email protected]
    # Attention: this is not email account password, this requires an email authorization code
    # 请注意此非邮箱账户密码 此需填写邮箱授权码
    password: example
    port: 465
    default-encoding: UTF-8
    properties:
      mail:
        smtp:
          socketFactoryClass: javax.net.ssl.SSLSocketFactory
          ssl:
            enable: true
        debug: false
		
warehouse:
  store:
    td-engine:
      enabled: true
      driver-class-name: com.taosdata.jdbc.rs.RestfulDriver
      url: jdbc:TAOS-RS://192.168.10.200:6041/hertzbeat
      username: root
      password: 123456
    iot-db:
      enabled: false
      host: 127.0.0.1
      rpc-port: 6667
      username: root
      password: root
      # org.apache.iotdb.session.util.Version: V_O_12 || V_0_13
      version: V_0_13
      # if iotdb version >= 0.13 use default queryTimeoutInMs = -1; else use default queryTimeoutInMs = 0
      query-timeout-in-ms: -1
      # 数据存储时间:默认'7776000000'(90天,单位为毫秒,-1代表永不过期)
      # data expire time, unit:ms, default '7776000000'(90 days, -1:never expire)
      expire-time: '7776000000'
    memory:
      enabled: true
      init-size: 1024
    redis:
      enabled: false
      host: 127.0.0.1
      port: 6379
      password: 123456
	  
alerter:
  # custom console url
  console-url: https://console.tancloud.cn
  # base of alert eval interval time, unit:ms. The next time is 2 times the previous time.
  alert-eval-interval-base: 600000
  # max of alert eval interval time, unit:ms
  max-alert-eval-interval: 86400000
  # system alert(available alert, reachable alert...) trigger times
  system-alert-trigger-times: 1

依次按:wq保存退出。

application.yml我们改动过的配置项为:

warehouse:
  store:
    td-engine:
      enabled: true
      driver-class-name: com.taosdata.jdbc.rs.RestfulDriver
      url: jdbc:TAOS-RS://192.168.10.200:6041/hertzbeat
      username: root
      password: 123456

其中usernamepassword为我们在TDengine的设置的账号密码,url地址中的ip改为docker所在的主机IP,而不是localhost。虽然Hertzbeat和TDengine部署在一个docker,但容器之间默认不能用127.0.0.1通讯。

sureness.yml 配置遵循默认即可,

vi sureness.yml
# hertzbeat用户和用户权限配置-sureness.yml
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
 
## -- sureness.yml文本数据源 -- ##
 
# 加载到匹配字典的资源,也就是需要被保护的,设置了所支持角色访问的资源
# 没有配置的资源也默认被认证保护,但不鉴权
# eg: /api/v1/source1===get===[admin] 表示 /api/v2/host===post 这条资源支持 admin 这一种角色访问
# eg: /api/v1/source2===get===[] 表示 /api/v1/source2===get 这条资源不支持任何角色访问
resourceRole:
  - /api/account/auth/refresh===post===[admin,user,guest]
  - /api/apps/**===get===[admin,user,guest]
  - /api/monitor/**===get===[admin,user,guest]
  - /api/monitor/**===post===[admin,user]
  - /api/monitor/**===put===[admin,user]
  - /api/monitor/**===delete==[admin]
  - /api/monitors/**===get===[admin,user,guest]
  - /api/monitors/**===post===[admin,user]
  - /api/monitors/**===put===[admin,user]
  - /api/monitors/**===delete===[admin]
  - /api/alert/**===get===[admin,user,guest]
  - /api/alert/**===post===[admin,user]
  - /api/alert/**===put===[admin,user]
  - /api/alert/**===delete===[admin]
  - /api/alerts/**===get===[admin,user,guest]
  - /api/alerts/**===post===[admin,user]
  - /api/alerts/**===put===[admin,user]
  - /api/alerts/**===delete===[admin]
  - /api/notice/**===get===[admin,user,guest]
  - /api/notice/**===post===[admin,user]
  - /api/notice/**===put===[admin,user]
  - /api/notice/**===delete===[admin]
  - /api/tag/**===get===[admin,user,guest]
  - /api/tag/**===post===[admin,user]
  - /api/tag/**===put===[admin,user]
  - /api/tag/**===delete===[admin]
  - /api/summary/**===get===[admin,user,guest]
  - /api/summary/**===post===[admin,user]
  - /api/summary/**===put===[admin,user]
  - /api/summary/**===delete===[admin]
# 需要被过滤保护的资源,不认证鉴权直接访问
# /api/v1/source3===get 表示 /api/v1/source3===get 可以被任何人访问 无需登录认证鉴权
excludedResource:
  - /api/account/auth/**===*
  - /api/i18n/**===get
  - /api/apps/hierarchy===get
  - /actuator/**===get
  # web ui 前端静态资源
  - /===get
  - /dashboard/**===get
  - /monitors/**===get
  - /alert/**===get
  - /account/**===get
  - /setting/**===get
  - /passport/**===get
  - /**/*.html===get
  - /**/*.js===get
  - /**/*.css===get
  - /**/*.ico===get
  - /**/*.ttf===get
  - /**/*.png===get
  - /**/*.gif===get
  - /**/*.jpg===get
  - /**/*.svg===get
  - /**/*.json===get
  # swagger ui 资源
  - /swagger-resources/**===get
  - /v2/api-docs===get
  - /v3/api-docs===get
  # h2 database
  - /h2-console/**===*
# 用户账户信息
# 下面有 admin tom lili 三个账户
# eg: admin 拥有[admin,user]角色,密码为hertzbeat
# eg: tom 拥有[user],密码为hertzbeat
# eg: lili 拥有[guest],明文密码为lili, 加盐密码为1A676730B0C7F54654B0E09184448289
account:
  - appId: admin
    credential: hertzbeat
    role: [admin,user]
  - appId: tom
    credential: hertzbeat
    role: [user]
  - appId: guest
    credential: hertzbeat
    role: [guest]
  - appId: lili
    # 注意 Digest认证不支持加盐加密的密码账户
    # 加盐加密的密码,通过 MD5(password+salt)计算
    # 此账户的原始密码为 lili
    credential: 1A676730B0C7F54654B0E09184448289
    salt: 123
    role: [guest]

依次按:wq保存退出。

我们启动Hertzbeat,输入如下命令,端口默认1157:

docker run -dti -p 1157:1157 \
    -e LANG=zh_CN.UTF-8 \
    -v /data/hertzbeat/data:/opt/hertzbeat/data \
    -v /data/hertzbeat/logs:/opt/hertzbeat/logs \
    -v /data/hertzbeat/application.yml:/opt/hertzbeat/config/application.yml \
    -v /data/hertzbeat/sureness.yml:/opt/hertzbeat/config/sureness.yml \
    --restart=always \
    --name hertzbeat --privileged=true tancloud/hertzbeat:latest

有如下:

[root@docker hertzbeat]# docker run -dti -p 1157:1157 \
>     -e LANG=zh_CN.UTF-8 \
>     -v /data/hertzbeat/data:/opt/hertzbeat/data \
>     -v /data/hertzbeat/logs:/opt/hertzbeat/logs \
>     -v /data/hertzbeat/application.yml:/opt/hertzbeat/config/application.yml \
>     -v /data/hertzbeat/sureness.yml:/opt/hertzbeat/config/sureness.yml \
>     --restart=always \
>     --name hertzbeat --privileged=true tancloud/hertzbeat:latest
8ccc44cdec783117f39dbba56944ec48d0bf38041ebb054011a6852feb302038

【监控】Hertzbeat在docker的安装与部署_第5张图片

运行

docker ps -a

可以看到我们启动的TDengine和Hertzbeat:

【监控】Hertzbeat在docker的安装与部署_第6张图片

我们顺便把之前的springboot服务起一下:

在这里插入图片描述

访问Hertzbeat:http://192.168.10.200:1157

其中192.168.10.200是主机IP,1157为Hertzbeat对外端口,可以有如下:

【监控】Hertzbeat在docker的安装与部署_第7张图片
账号密码默认是 admin/hertzbeat,进入后可以自己配置指标监控如下:

【监控】Hertzbeat在docker的安装与部署_第8张图片

参考

https://hertzbeat.com/zh-cn/docs/start/docker-deploy

https://blog.csdn.net/fisherish/article/details/126195370

https://blog.csdn.net/cnskylee/article/details/128761948

https://blog.csdn.net/qq_36961626/article/details/123161896

你可能感兴趣的:(测试与监控,docker,容器,运维)