夜莺部署
部署夜莺
概述
首先我们来看下面的架构图,夜莺的服务端有两个模块:n9e-webapi 和 n9e-server,n9e-webapi 用于提供 API 给前端 JavaScript 使用,n9e-server 的职责是告警引擎和数据转发器。依赖的组件有 MySQL、Redis、时序库,时序库我们这里使用 Prometheus。
[图片]
组件安装
下载夜莺
https://github.com/ccfos/nightingale/releases
准备依赖
install mysql
yum -y install mariadb*
systemctl enable mariadb
systemctl restart mariadb
mysql -e "SET PASSWORD FOR 'root'@'localhost' = PASSWORD('1234');"
install redis
yum install -y redis
systemctl enable redis
systemctl restart redis
导入数据库表结构
mysql -uroot -p1234 < n9e.sql
启动夜莺
./n9e
//或者后台运行
nohup ./n9e &> n9e.log &
//如果启动成功,夜莺默认会监听在 17000 端口,通过下面的命令可以查看端口是否正常在监听:
ss -tlnp|grep 17000
//通过下面的命令可以查看进程是否正常在运行:
ps -ef|grep n9e
//如果是 nohup 方式启动,在 n9e.log 中可以查看夜莺的日志。如果是 systemd 方式启动,可以通过 journalctl 来查看日志(假设 service 名字是 n9e):
journalctl -fu n9e
修改夜莺配置文件对接时序库
夜莺作为 pushgateway,需要告诉夜莺时序库的地址在哪里。夜莺的配置文件是 etc/config.toml,修改 [[Pushgw.Writers]] 部分即可,比如对接 VictoriaMetrics 单机版:
[[Pushgw.Writers]]
Url = "http://127.0.0.1:8428/api/v1/write"
注意上面的 IP 改成你自己环境的 VictoriaMetrics 的 IP,如果对接的是 Prometheus,则配置就是:
[[Pushgw.Writers]]
Url = "http://127.0.0.1:9090/api/v1/write"
部署p8s
概述
Prometheus 的安装非常简单,就是一个二进制,下载启动就可以了。之所以还要单列一个章节来说明,是因为 Prometheus 要想作为时序库接收 remote write 协议的数据,即夜莺收到时序数据之后,要想转发给 Prometheus,需要 Prometheus 添加一个特定的启动参数 ,否则夜莺转发数据的时候会报 404,因为没有这个参数,Prometheus 就不会开启 /api/v1/write 接口的处理监听。这个启动参数是:
- --enable-feature=remote-write-receiver 这是老版本的写法
- --web.enable-remote-write-receiver 这是新版本的写法
要想确定你的 Prometheus 具体应该使用哪个写法,可以通过 help 信息来确认:
./prometheus --help | grep receiver
部署Prometheus
下面是一段小脚本,用于安装 Prometheus,供参考:
version=2.28.0
filename=prometheus-{version}/
{filename}.tar.gz
cp -far ${filename}/* /opt/prometheus/
service cat <<EOF >/etc/systemd/system/prometheus.service
[Unit]
Description="prometheus"
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
ExecStart=/opt/prometheus/prometheus --config.file=/opt/prometheus/prometheus.yml --storage.tsdb.path=/opt/prometheus/data --web.enable-lifecycle --web.enable-remote-write-receiver
Restart=on-failure
SuccessExitStatus=0
LimitNOFILE=65536
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=prometheus
[Install]
WantedBy=multi-user.target
EOF
systemctl enable prometheus
systemctl restart prometheus
systemctl status prometheus
部署采集器
概述
采集方面,夜莺支持多种不同的采集器,比如 Categraf、Telegraf、Datadog-agent、Grafana-agent 等,Categraf 和夜莺的整合最为丝滑,最为推荐。
新版本的 Categraf 可以采集机器的元信息并上报夜莺,而且内置了命令执行能力,省去了 ibex-agent 的部署也可以完成告警自愈,其次,夜莺内置的告警规则、仪表盘大都是针对 Categraf 定制的,所以采集器优选 Categraf。
架构
对于监控系统而言,核心就是采集数据并存储,然后做告警判定、数据展示分析,这里详细讲解了这个数据流架构,整个流程图如下:
[图片]
Categraf 不但可以采集 OS、MySQL、Redis、Oracle 等常见的监控对象,也准备提供日志采集能力和 trace 接收能力,这是夜莺主推的采集器。
部署
下载
- github: https://github.com/flashcatcloud/categraf
配置
Categraf 采集到数据之后,通过 remote write 协议推给远端存储,Nightingale 恰恰提供了 remote write 协议的数据接收接口,所以二者可以整合在一起,重点是配置 Categraf 的 conf/config.toml 中的 writer 部分,其中 url 部分配置为 n9e 的 remote write 接口:
[writer_opt]
default: 2000batch = 2000# channel(as queue) sizechan_size = 10000
[[writers]]
url = "http://10.54.168.219:17000/prometheus/v1/write"
Basic auth usernamebasic_auth_user = ""
Basic auth passwordbasic_auth_pass = ""
timeout settings, unit: mstimeout = 5000dial_timeout = 2500max_idle_conns_per_host = 100
启动
cp /opt/categraf/conf/categraf.service /etc/systemd/system/
systemctl daemon-reload
systemctl enable categraf
systemctl restart categraf
systemctl status categraf
//或者直接使用如下命令:use nohup to start categraf
nohup ./categraf &> stdout.log &
//如果修改了某个采集器的配置,需要重启 categraf 或者给 categraf 进程发送HUP信号,发送HUP信号的命令:
kill -HUP pidof categraf
categraf 命令汇总
//运行命令
test mode: just print metrics to stdout
./categraf --test
test system and mem plugins
./categraf --test --inputs system:mem
print usage message
./categraf --help
run
./categraf
run with specified config directory
./categraf --configs /path/to/conf-directory
only enable system and mem plugins
./categraf --inputs system:mem
参考
https://flashcat.cloud/docs/content/flashcat-monitor/nightingale-v6/agent/categraf/