centos7二进制部署prometheus+alertmanager+grafana

prometheus 是一个基于golang 编写,编译后的软件包,不依赖于任何的第三方依赖。用户只需要下载对应平台的二进制包,解压并且添加基本的配置即可正常启动Prometheus Server

我们首先需要准备一些部署包,可以去这个地址去下载:https://prometheus.io/download/

wget https://github.com/prometheus/prometheus/releases/download/v2.45.3/prometheus-2.45.3.linux-amd64.tar.gz
wget https://github.com/prometheus/alertmanager/releases/download/v0.26.0/alertmanager-0.26.0.linux-amd64.tar.gz
wget https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz

我们开始部署prometheus

tar -zxvf prometheus-2.45.3.linux-amd64.tar.gz
mv prometheus-2.45.3.linux-amd64 /usr/local/prometheus

添加系统启动服务

cat >/etc/systemd/system/prometheus.service<<EOF
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target
[Service]
Restart=on-failure
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus --web.external-url=http://0.0.0.0:9090
[Install]
WantedBy=multi-user.target
EOF

启动prometheus并设置开机启动

systemctl start prometheus
systemctl enable prometheus

启动以后我们就可以通过http://ip:9090端口访问prometheus页面了。

上述prometheus server部署好以后我们接着添加监控对象,就是exporter,可以根据自己需求添加各种监控对象,目前官网列出了几种exporter,如果是其他的exporter可以查看各官网,例如NVIDIA监控exporter是prometheus-dcgm。

我们添加node-exporter用于采集类UNIX内核的硬件以及系统指标

首先我们需要去监控对象节点部署node_exporter

tar -zxvf node_exporter-1.7.0.linux-amd64.tar.gz
mv node_exporter-1.7.0.linux-amd64 /usr/local/node_exporter

然后将node_exporter添加系统服务

cat >/etc/systemd/system/node_exporter.service<<EOF
[Unit]
Description=node_exporter
After=network.target
[Service]
Restart=on-failure
ExecStart=/usr/local/node_exporter/node_exporter
[Install]
WantedBy=multi-user.target
EOF

启动并设置开机启动

systemctl start node_exporter
systemctl enable node_exporter

修改/usr/local/prometheus/prometheus.yml文件

我们在scrape_configs下添加job

  - job_name: 'host31'           
    static_configs:
      - targets: ["192.168.1.76:9100"]

改完保存退出后重启prometheus服务

systemctl restart prometheus

然后我们接着去prometheus页面在Targets页面下可以看到我们添加的监控对象了。

微信截图_20240304114901.png

接着我们开始部署告警组件alertmanager

Prometheus支持故障触发告警功能,但是告警功能由Alertmanager组件实现,Alertmanager支持多种告警媒介类型,如:邮件、短信、微信、钉钉等告警功能,不同的报警媒介,告警的配置方式也有所不同。

tar -zxvf alertmanager-0.26.0.linux-amd64.tar.gz
mv alertmanager-0.26.0.linux-amd64 /usr/local/alertmanager

添加alertmanager系统服务

cat >/etc/systemd/system/alertmanager.service<<EOF
[Unit]
Description=Alertmanager
After=network-online.target
[Service]
Restart=on-failure
ExecStart=/usr/local/alertmanager/alertmanager --config.file=/usr/local/alertmanager/alertmanager.yml
[Install]
WantedBy=multi-user.target
EOF

启动并设置开机启动

systemctl start alertmanager
systemctl enable alertmanager

告警组件部署好以后可以浏览http://ip:9093进行访问

最后我们安装grafana,我们可以直接下载rpm包进行安装,目前最新版本是10.3.3。

wget https://mirrors.tuna.tsinghua.edu.cn/grafana/yum/rpm/Packages/grafana-10.3.3-1.x86_64.rpm
yum localinstall grafana-10.3.3-1.x86_64.rpm

启动并设置开机启动

systemctl start grafana-server
systemctl enable grafana-server

启动好以后我们可以浏览http://ip:3000进行访问,第一次登录需要修改密码,默认账户密码是admin/admin

grafana监控模板下载地址:https://grafana.com/grafana/dashboards/

以上就是prometheus及其相关组件的部署,后面再有时间更新其他exporter和alertmanager、grafana相关配置。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://sulao.cn/post/973.html

我要评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。