一、环境准备
部署模式:单节点部署。
安装包:heartbeat安装包下载地址
二、安装部署
2.1 下载安装包到指定文件夹,并解压
# 进入安装目录 cd /opt/module # 解压安装包 tar xf heartbeat-8.11.0.tar.gz
2.2 复制证书文件
# 进入配置文件目录 cd heartbeat-8.11.0/config # 创建证书文件夹 mkdir certs # 将es的证书文件复制到certs文件夹下 cp /opt/module/elasticsearch-8.11.0/config/certs/* certs/
2.3 编辑配置文件
vim heartbeat.yml
heartbeat.config.monitors: # Directory + glob pattern to search for configuration files path: ${path.config}/monitors.d/*.yml # If enabled, heartbeat will periodically check the config.monitors path for changes reload.enabled: false # How often to check for changes reload.period: 5s # Configure monitors inline heartbeat.monitors: - type: http enabled: true id: logstash-226 name: logstash-226 urls: ["http://192.168.122.226:9600/_node"] schedule: '@every 30s' check.response.status: [200] ipv4: true ipv6: true mode: any - type: tcp id: es-161 name: es-161 schedule: '@every 30s' hosts: ["192.168.10.161:9200"] ssl: certificate_authorities: ["/opt/module/metricbeat-8.11.0/certs/elasticsearch-ca.pem"] certificate: "/opt/module/metricbeat-8.11.0/certs/instance.crt" key: "/opt/module/metricbeat-8.11.0/certs/instance.key" - type: http # Set enabled to true (or delete the following line) to enable this monitor enabled: true # ID used to uniquely identify this monitor in Elasticsearch even if the config changes id: springboot-demo-test # Human readable display name for this service in Uptime UI and elsewhere name: springboot-demo-test # List of URLs to query urls: ["http://localhost:8080/test/hello"] # Configure task schedule schedule: '@every 10s' check.response.status: [200] ipv4: true ipv6: true mode: any # Total test connection and data exchange timeout #timeout: 16s # Name of corresponding APM service, if Elastic APM is in use for the monitored service. #service.name: my-apm-service-name # Experimental: Set this to true to run heartbeat monitors exactly once at startup #heartbeat.run_once: true # ======================= Elasticsearch template setting ======================= setup.template.settings: index.number_of_shards: 1 index.codec: best_compression setup.template.name: "heartbeat" setup.template.pattern: "heartbeat-*" setup.ilm.enabled: false # =================================== Kibana =================================== # Starting with Beats version 6.0.0, the dashboards are loaded via the Kibana API. # This requires a Kibana endpoint configuration. setup.kibana: # Kibana Host # Scheme and port can be left out and will be set to the default (http and 5601) # In case you specify and additional path, the scheme is required: http://localhost:5601/path # IPv6 addresses should always be defined as: https://[2001:db8::1]:5601 #host: "localhost:5601" host: "192.168.122.118:5601" # ---------------------------- Elasticsearch Output ---------------------------- output.elasticsearch: # Array of hosts to connect to. hosts: ["https://192.168.122.118:9200","https://192.168.122.119:9200","https://192.168.122.120:9200"] protocol: "https" username: "elastic" password: "elastic" ssl.certificate_authorities: ["/opt/module/metricbeat-8.11.0/certs/elasticsearch-ca.pem"] ssl.certificate: "/opt/module/metricbeat-8.11.0/certs/instance.crt" ssl.key: "/opt/module/metricbeat-8.11.0/certs/instance.key" # Protocol - either `http` (default) or `https`. #protocol: "https" # Authentication credentials - either API key or username/password. #api_key: "id:api_key" #username: "elastic" #password: "changeme" # ================================= Processors ================================= processors: - add_observer_metadata:
2.4 设置模板
# 设置模板 ./heartbeat setup
2.5 启动服务
# 编写启动命令文件 echo "nohup ./heartbeat -e > ./heartbeat.log 2>&1 &" > start.sh # 启动服务 ./start.sh # 查看日志 tail -200f /opt/module/heartbeat-8.11.0/heartbeat.log
2.6 检查es是否收到数据
登入kibana ,进入observability,添加 uptime,检查 heartbeat 状态。正常后即可在observability >uptime看到监控的实例
2.6 备用配置
附上一段备用配置,适用各种场景的监控
heartbeat.monitors: - type: http # Set enabled to true (or delete the following line) to enable this monitor enabled: true # ID used to uniquely identify this monitor in Elasticsearch even if the config changes id: ipu-cbs-server-test # Human readable display name for this service in Uptime UI and elsewhere name: ipu-cbs-server-test # List of URLs to query urls: ["http://192.168.122.251:10002/healthCheck/ready"] # Configure task schedule schedule: '@every 30s' check.response.status: [200] ipv4: true ipv6: true mode: any - type: http enabled: true id: ipu-cbs-server-dev name: ipu-cbs-server-dev urls: ["http://192.168.122.239:10002/healthCheck/ready"] schedule: '@every 30s' check.response.status: [200] ipv4: true ipv6: true mode: any - type: http enabled: true id: kibana-118 name: kibana-118 enabled: true schedule: '@every 30s' # 定期检查间隔 urls: ["http://192.168.122.118:5601/login"] check.response.status: 200 check.response.body: "kibana" # 检查响应体中是否包含指定的字符串 - type: http enabled: true id: kibana-119 name: kibana-119 enabled: true schedule: '@every 30s' # 定期检查间隔 urls: ["http://192.168.122.119:5601/login"] check.response.status: 200 check.response.body: "kibana" # 检查响应体中是否包含指定的字符串 - type: http enabled: true id: logstash-226 name: logstash-226 urls: ["http://192.168.122.226:9600/_node"] schedule: '@every 30s' check.response.status: [200] ipv4: true ipv6: true mode: any - type: http enabled: true id: logstash-98 name: logstash-98 urls: ["http://192.168.122.98:9600/_node"] schedule: '@every 30s' check.response.status: [200] ipv4: true ipv6: true mode: any - type: tcp id: es-161 name: es-161 schedule: '@every 30s' hosts: ["192.168.10.161:9200"] ssl: certificate_authorities: ["/opt/module/metricbeat-8.11.0/certs/elasticsearch-ca.pem"] certificate: "/opt/module/metricbeat-8.11.0/certs/instance.crt" key: "/opt/module/metricbeat-8.11.0/certs/instance.key" - type: tcp id: es-162 name: es-162 schedule: '@every 30s' hosts: ["192.168.10.162:9200"] ssl: certificate_authorities: ["/opt/module/metricbeat-8.11.0/certs/elasticsearch-ca.pem"] certificate: "/opt/module/metricbeat-8.11.0/certs/instance.crt" key: "/opt/module/metricbeat-8.11.0/certs/instance.key" - type: tcp id: es-163 name: es-163 schedule: '@every 30s' hosts: ["192.168.10.163:9200"] ssl: certificate_authorities: ["/opt/module/metricbeat-8.11.0/certs/elasticsearch-ca.pem"] certificate: "/opt/module/metricbeat-8.11.0/certs/instance.crt" key: "/opt/module/metricbeat-8.11.0/certs/instance.key" - type: tcp id: redis-28 name: redis-28 enabled: true schedule: '@every 10s' hosts: ["192.168.122.28:6379"] check.send: "AUTH Redis@123456\r\n" - type: tcp schedule: '@every 10s' hosts: ["192.168.10.159:3306"] check.send: "SELECT 1;" enabled: true name: "mysql-159" id: "mysql-159" timeout: 10s max_retries: 10 username: "tm_aseanbank_dev" password: "tm_aseanbank_dev" on_response_error: - action: log max_size: 10000 keep_source: true