0
点赞
收藏
分享

微信扫一扫

Prometheus+Grafana 运维监控部署

Sophia的玲珑阁 2022-01-22 阅读 142

文章目录

安装Prometheus

官方文档请参考:Prometheus:https://prometheus.io/

1.下载地址:https://github.com/prometheus/prometheus/releases

wget https://github.com/prometheus/prometheus/releases/downloa d/v2.33.0/prometheus-2.33.0-rc.1.linux-amd64.tar.gz

2.解压安装包

tar -zxvf prometheus-2.33.0.linux-amd64.tar.gz 

3.设置软连接

ln -s /usr/local/prometheus-2.33.0.linux-amd64 /usr/local/prometheus

4.设置systemd服务

cat <<EOF > /usr/lib/systemd/system/prometheus.service
[Unit]
Description=prometheus
After=network.target
[Service]
Type=simple
User=root
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/usr/local/prometheus/data/ --web.enable-lifecycle --storage.tsdb.retention.time=30d
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
  • –config.file: 指定配置文件
  • –web.enable-lifecycle: 支持通过http请求重载配置
  • –storage.tsdb.path:指定数据存储目录(默认当前目录的的data目录,若不存在则新建)
  • –storage.tsdb.retention.time: 指定数据保留时间(默认15d)

5.启动服务

systemctl daemon-reload
systemctl start prometheus
systemctl status prometheus && systemctl enable prometheus

6.确认端口已经被监听

 ss -lantp | grep 9090

浏览器访问:localhost:9090

健康检查

curl  http://localhost:9090/-/healthy

检查是否启动

curl  http://localhost:9090/-/ready

通过web接口重载,启动时需增加选项 --web.enable-lifecycle

curl -XPOST http://localhost:9090/-/reload

安装Grafana

1.下载安装包并配置

wget https://dl.grafana.com/oss/release/grafana-7.1.4-1.x86_64.rpm
yum -y install grafana-7.1.4-1.x86_64.rpm

2.配置启动

systemctl daemon-reload 
systemctl enable grafana-server && systemctl start grafana-server

3.检查端口

ss -lantp | grep 3000

Grafana添加Prometheus数据源

  • 访问grafana的3000端口进行登录,默认用户名和密码为: admin/admin
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

在这里插入图片描述

安装node_exporter

node_exporter用于收集主机运行信息,比如CPU、内存、磁盘等资源使用情况。
常用exporter清单:https://prometheus.io/docs/instrumenting/exporters/

cd /usr/local
wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz

解压并配置

tar -zxvf node_exporter-1.0.1.linux-amd64.tar.gz 

ln -s node_exporter-1.0.1.linux-amd64 node_exporter

添加systemd 启动

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

systemctl daemon-reload
systemctl enable node_exporter && systemctl start node_exporter
systemctl status node_exporter

查看监听端口

ss -lantp | grep 9100

调整Prometheus获取主机及应用监控数据

vim /usr/local/prometheus/prometheus.yml

增加以下配置,其中job_name为自定义

  - job_name: 'agent1'
    static_configs:
    - targets: ['localhost:9100']

重载Prometheus配置文件

curl -XPOST http://localhost:9090/-/reload

使用Grafana添加图形,便于展示!(监控Linux主机推荐使用9276模板)!
在这里插入图片描述
在这里插入图片描述

生成效果如图
在这里插入图片描述
监控Linux主机强烈推荐使用8919模板!该模板获取主机的指标更加的详细!
在这里插入图片描述

举报

相关推荐

0 条评论