美文网首页
夜莺部署

夜莺部署

作者: sknfie | 来源:发表于2024-05-30 14:25 被阅读0次

部署夜莺

概述
首先我们来看下面的架构图,夜莺的服务端有两个模块: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}.linux-amd64 mkdir -p /opt/prometheus wget https://github.com/prometheus/prometheus/releases/download/v{version}/{filename}.tar.gz tar xf{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/

相关文章

  • 滴滴监控夜莺部署

    部署 reference n9e-source-standalone-deploy n9e-product-dep...

  • 夜莺,夜莺

    夜莺,夜莺, 你不懂夜的憔悴。 你那不惧秋风的柔美, 是为了谁的伤悲? 在冰凉中舒展羽翼, 在败叶残花间低回。 灯...

  • 夜莺

    夜莺,夜莺, 请在此驻足聆听。 蟋蟀与蝉将为你伴奏, 树与叶共演一场孤寂。 夜莺,夜莺, 请伸手遮住眼睛。 黑暗将...

  • 夜莺

    蓝色的布幔缀着深色的宝石 公主洁白的手腕 拂过金色夕阳 窗口飘过一片云 你取下夜莺的金丝笼 夜莺便开始歌唱 你满心...

  • 夜莺

    别问我为什么 害怕黑暗与光明的交接 因我 正努力唤醒大地的眼睛 你听 黎明前我用清亮的声音 正打开着天际的一道光芒...

  • 夜莺

    我是一只夜莺 我在黑夜里歌颂黑夜 黑夜,让一切虚幻的色彩得以永恒 倘若可以,请剜去我的双眸 让我用最纯朴的情感 将...

  • 夜莺

    夜色拉开了帷幕 大野深处 挣扎着朦胧眼睛的孤灯 快要闭目而睡 夜风呼啸着,卷起一丝缭绕 将沉睡的梦惊起一波涟漪 月...

  • 夜莺

    偶然情况下,拜读了林微因先生译的《夜莺与玫瑰》。不敢以自己微知拙见来评论,只是心有所感,便不吐不快。 趁性便又上网...

  • 夜莺

    黄昏时分 一株瘦削的野花 和着轻风 弹奏着安魂曲 被勾了魂的 无头亡灵们 汇聚成一条洁净的溪流 淹没了野花和草原 ...

  • 夜莺

    谁思念你 灵魂里啼叫的夜莺 随流浪的印记寻去吧 还能求得一个雨季

网友评论

      本文标题:夜莺部署

      本文链接:https://www.haomeiwen.com/subject/jucrqjtx.html