怎么在CentOS7系统中搭建Prometheus监控-创新互联
今天就跟大家聊聊有关怎么在CentOS7系统中搭建Prometheus 监控,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
我们提供的服务有:成都网站建设、成都网站制作、微信公众号开发、网站优化、网站认证、顺城ssl等。为1000多家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的顺城网站制作公司简介
prometheus可以拆分成多个节点进行指标收集。
安装环境:CentOS7
wget -c https://github.com/prometheus/prometheus/releases/download/v2.23.0/prometheus-2.23.0.linux-amd64.tar.gz
tar zxvf prometheus-2.23.0.linux-amd64.tar.gz -C /opt/
cd /opt/
ln -s prometheus-2.23.0.linux-amd64 prometheus
cat > /etc/systemd/system/prometheus.service <
[Unit]
Description=prometheus
After=network.target
[Service]
Type=simple
WorkingDirectory=/opt/prometheus
ExecStart=/opt/prometheus/prometheus --config.file="/opt/prometheus/prometheus.yml"
LimitNOFILE=65536
PrivateTmp=true
RestartSec=2
StartLimitInterval=0
Restart=always
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable prometheus
systemctl start prometheus
配置Prometheus
这里配置的是监听/opt/prometheus/servers/目录下的json文件
cat > /opt/prometheus/prometheus.yml <
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=
` to any timeseries scraped from this config. - job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
- job_name: 'servers'
file_sd_configs:
- refresh_interval: 61s
files:
- /opt/prometheus/servers/*.json
EOF
systemctl restart prometheus
json格式
{
"targets": [
"192.168.1.164:9100"
],
"labels": {
"instance": "192.168.1.164",
"job": "node_exporter"
}
},
{
"targets": [
"192.168.1.167:9100"
],
"labels": {
"instance": "192.168.1.167",
"job": "node_exporter"
}
}
]
安装node_exporter
安装到/opt/node_exporter路径下,保持默认的端口
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 -C /opt/
cd /opt/
ln -s node_exporter-1.0.1.linux-amd64 node_exporter
cat > /etc/systemd/system/node_exporter.service <
[Unit]
Description=node_exporter
After=network.target
[Service]
Type=simple
WorkingDirectory=/opt/node_exporter
ExecStart=/opt/node_exporter/node_exporter
LimitNOFILE=65536
PrivateTmp=true
RestartSec=2
StartLimitInterval=0
Restart=always
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable node_exporter
systemctl start node_exporter
图形展示
直接安装grafana进行展示
yum -y install https://dl.grafana.com/oss/release/grafana-7.3.6-1.x86_64.rpm
systemctl enable grafana-server
systemctl start grafana-server
启动之后,grafana默认监听的是3000端口,直接使用浏览器进行访问就可以了,默认用户名密码是admin/admin,第一次登陆之后会提示修改。
配置数据源:鼠标左边的菜单 Configuration -> Data Source -> Add data source -> 选择prometheus -> url那栏填入prometheus的地址就可以了 -> 最后 Save & test 就可以了。
grafana.com/grafana/dashboards 官网已经有人做好的模板,我们直接import进来就可以了。
导入面板:鼠标左边的菜单 Dashboards -> Import -> 填入id -> Load -> 选择数据源就可以了。
我经常用的是:1860 、8919 这两个来查看node_exporter监控
看完上述内容,你们对怎么在CentOS7系统中搭建Prometheus 监控有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。
原文地址:https://www.toutiao.com/i6914917162675192324/
分享文章:怎么在CentOS7系统中搭建Prometheus监控-创新互联
分享网址:http://cdiso.cn/article/disehg.html