在CentOS 8/Rhel 8上安装Sensu Go Monitoring工具

时间:2020-02-23 14:39:19  来源:igfitidea点击:

Sensu是一种开源监控工具,能够监控公共,私人,混合云和基于容器的基础架构环境。
Sensu被设计为简单,可扩展和可延展的框架,使我们可以自定义监控以满足业务需求。
本教程将在CentOS 8/Rhel 8 Linux机器上使用Sensu Go Monitoring工具的安装。

Sensu架构

Sensu在服务器 - 客户端模型中工作,其中要监视的所有系统运行Sensu客户端软件。
此客户端应用程序负责执行本地检查,管理客户端订阅和注册,并满足Sensu Server请求的检查。

CentOS 8/Rhel 8安装Sensu Go

Sensu Monitoring工具有三个主要部分。

第1步:在CentOS 8/Rhel 8上安装Sensu后端

添加后端存储库:

curl -s https://packagecloud.io/install/repositories/sensu/stable/script.rpm.sh | sudo bash

如果存储库配置成功,则输出将如下所示。

Complete!
Generating yum cache for sensu_stable...
Importing GPG key 0x0A3F7426:
 Userid     : "https://packagecloud.io/sensu/stable (https://packagecloud.io/docs#gpg_signing) <Hyman@theitroad>"
 Fingerprint: CB16 05C4 E988 C91F 4382 49E3 A5BC 3FB7 0A3F 7426
 From       : https://packagecloud.io/sensu/stable/gpgkey
Generating yum cache for sensu_stable-source...
The repository is setup! You can now install packages.
..

添加到CentOS 8/RHEL 8上安装Sensu后端:

sudo yum install sensu-go-backend

接受安装提示符:

Dependencies resolved.
========================================================================================================================================================
 Package                                 Architecture                  Version                                Repository                           Size
========================================================================================================================================================
Installing:
 sensu-go-backend                        x86_64                        5.20.1-12427                           sensu_stable                         14 M
Transaction Summary
========================================================================================================================================================
Install  1 Package
Total download size: 14 M
Installed size: 38 M
Is this ok [y/N]: y

第2步:在CentOS 8/Rhel 8上配置Sensu后端

从文档中复制配置模板:

sudo curl -L https://docs.sensu.io/sensu-go/latest/files/backend.yml -o /etc/sensu/backend.yml

编辑它以你喜欢:

sudo vi /etc/sensu/backend.yml

这就是我的配置的样子:

--
# Sensu backend configuration
# backend configuration
state-dir: "/var/lib/sensu/sensu-backend"
cache-dir: "/var/cache/sensu/sensu-backend"
config-file: "/etc/sensu/backend.yml"
debug: false
log-level: "debug" # available log levels: panic, fatal, error, warn, info, debug
##
# agent configuration
##
agent-port: 8081
##
# api configuration
##
api-listen-address: "[::]:8080" # listen on all IPv4 and IPv6 addresses
#api-url: "http://localhost:8080"
##
# dashboard configuration
##
#dashboard-cert-file: "/path/to/ssl/cert.pem"
#dashboard-key-file: "/path/to/ssl/key.pem"
dashboard-host: "[::]" # listen on all IPv4 and IPv6 addresses
dashboard-port: 3000
##
# ssl configuration
##
#cert-file: "/path/to/ssl/cert.pem"
#key-file: "/path/to/ssl/key.pem"
#trusted-ca-file: "/path/to/trusted-certificate-authorities.pem"
#insecure-skip-tls-verify: false
##
# store configuration
##
#etcd-advertise-client-urls: "http://localhost:2379"
#etcd-cert-file: "/path/to/ssl/cert.pem"
#etcd-client-cert-auth: false
#etcd-initial-advertise-peer-urls: "http://127.0.0.1:2380"
#etcd-initial-cluster: "default=http://127.0.0.1:2380"
#etcd-initial-cluster-state: "new" # new or existing
#etcd-initial-cluster-token: "sensu"
#etcd-key-file: "/path/to/ssl/key.pem"
#etcd-listen-client-urls: "http://127.0.0.1:2379"
#etcd-listen-peer-urls: "http://127.0.0.1:2380"
#etcd-name: "default"
#etcd-peer-cert-file: "/path/to/ssl/cert.pem"
#etcd-peer-client-cert-auth: false
#etcd-peer-key-file: "/path/to/ssl/key.pem"
#etcd-peer-trusted-ca-file: "/path/to/ssl/key.pem"
#etcd-trusted-ca-file: "/path/to/ssl/key.pem"
#no-embed-etcd: false
#etcd-cipher-suits
#  - TLS_EXAMPLE

有关配置选项的完整列表,请参阅后端参考。

start sensu后端服务:

sudo systemctl enable --now  sensu-backend

检查服务状态:

systemctl status sensu-backend
● sensu-backend.service - The Sensu Backend service.
   Loaded: loaded (/usr/lib/systemd/system/sensu-backend.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2017-05-19 21:45:05 CEST; 14s ago
 Main PID: 2194 (sensu-backend)
    Tasks: 11 (limit: 26213)
   Memory: 25.8M
   CGroup: /system.slice/sensu-backend.service
           └─2194 /usr/sbin/sensu-backend start -c /etc/sensu/backend.yml
Jan 19 21:45:11 cent8.theitroad.com sensu-backend[2194]: {"backend_id":"861176a0-1874-4007-be62-c41f1b048dfe","component":"metricsd","level":"d>
Jan 19 21:45:12 cent8.theitroad.com sensu-backend[2194]: {"backend_id":"861176a0-1874-4007-be62-c41f1b048dfe","component":"metricsd","level":"d>
Jan 19 21:45:13 cent8.theitroad.com sensu-backend[2194]: {"backend_id":"861176a0-1874-4007-be62-c41f1b048dfe","component":"metricsd","level":"d>
Jan 19 21:45:16 cent8.theitroad.com sensu-backend[2194]: {"component":"cache","level":"debug","msg":"rebuilding the cache for resource type *v2>
Jan 19 21:45:16 cent8.theitroad.com sensu-backend[2194]: {"component":"cache","level":"debug","msg":"rebuilding the cache for resource type *v2>
Jan 19 21:45:16 cent8.theitroad.com sensu-backend[2194]: {"component":"cache","level":"debug","msg":"rebuilding the cache for resource type *v2>
Jan 19 21:45:16 cent8.theitroad.com sensu-backend[2194]: {"component":"tessend","level":"debug","metric_name":"auth_provider_count","metric_val>
Jan 19 21:45:16 cent8.theitroad.com sensu-backend[2194]: {"backend_id":"861176a0-1874-4007-be62-c41f1b048dfe","component":"metricsd","level":"d>
Jan 19 21:45:17 cent8.theitroad.com sensu-backend[2194]: {"backend_id":"861176a0-1874-4007-be62-c41f1b048dfe","component":"metricsd","level":"d>
Jan 19 21:45:18 cent8.theitroad.com sensu-backend[2194]: {"backend_id":"861176a0-1874-4007-be62-c41f1b048dfe","component":"metricsd","level":"d>

第3步:初始化Sensu后端

我们现在需要设置Sensu管理员用户名和密码。
运行以下命令以初始化Sensu后端:

export SENSU_BACKEND_CLUSTER_ADMIN_USERNAME=admin
export Hyman@theitroad
sensu-backend init

命令执行

{"component":"backend.seeds","level":"info","msg":"seeding etcd store with intial data","time":"2017-05-19T21:50:07+02:00"}

如果我们愿意响应用户名和密码的提示,我们还可以以交互模式运行sensu-bedend init命令:

sensu-backend init --interactive

更多详细信息,Sensu-Bection init,请参阅后端参考文档。

第4步:访问Sensu仪表板

Sensu Web UI提供了监视事件和用户友好工具的统一视图,以减少警报疲劳。

确认UI服务端口已启动。

$sudo ss -tunelp | grep 3000
tcp   LISTEN  0       128                         *:3000                *:*      users:(("sensu-backend",pid=2194,fd=18)) uid:994 ino:27800 sk:a v6only:0 <->

检查后端是否通过查询API Health运行:

$curl http://127.0.0.1:8080/health
{"Alarms":null,"ClusterHealth":[{"MemberID":9882886658148554927,"MemberIDHex":"8927110dc66458af","Name":"default","Err":"","Healthy":true}],"Header":{"cluster_id":4255616304056076734,"member_id":9882886658148554927,"raft_term":2}}

如果我们有主动防火墙服务,请允许端口3000。

sudo firewall-cmd --add-port=3000/tcp --permanent
sudo firewall-cmd --reload

在http://localhost:3000或者http://server_ip_or_hostname:3000上打开浏览器并访问Sensu仪表板。

使用前面设置的凭据登录。