一、背景
用prometheus+grafana+redis_exporter监控redis,对redis 1主1从3哨兵 实例做一些业务分析。
prometheus、grafana安装机器: 192.168.1.101
redis_exporter 安装机器: 192.168.1.102
二、安装redis_exporter
在redis主从哨兵的maser节点(192.168.1.102):
wget https://github.com/oliver006/redis_exporter/releases/download/v0.21.2/redis_exporter-v0.21.2.linux-amd64.tar.gz
tar -zxf redis_exporter-v0.21.2.linux-amd64.tar.gz
mkdir /usr/local/redis_exporter
mv redis_exporter /usr/local/redis_exporter/
vim /usr/lib/systemd/system/redis_exporter.service
####################################################
[Unit]
Description=Redis Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=root
Group=root
Type=simple
ExecStart=/usr/local/redis_exporter/redis_exporter \
-web.listen-address ":9121" \
-redis.addr "redis://192.168.1.102:6381" \
-redis.password "Redis@123"
[Install]
WantedBy=multi-user.target
####################################################
systemctl daemon-reload
systemctl start redis_exporter
systemctl enable redis_exporter
systemctl status redis_exporter
ss -tan | grep 9121
LISTEN 0 1024 [::]:9121 [::]:*
ESTAB 0 0 [::ffff:192.168.1.102]:9121 [::ffff:192.168.1.102]:42594
image.png
三、安装prometheus、grafana
在一台空闲新机器上:
安装prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.33.3/prometheus-2.33.3.linux-amd64.tar.gz
mkdir /var/lib/prometheus
tar -zxf prometheus-2.33.3.linux-amd64.tar.gz
mv prometheus-2.33.3.linux-amd64 /usr/local/prometheus
vim /usr/lib/systemd/system/prometheus.service
##################################################
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=root
Group=root
WorkingDirectory=/usr/local/prometheus
ExecStart=/usr/local/prometheus/prometheus \
--web.listen-address=0.0.0.0:9090 \
--storage.tsdb.path="/var/lib/prometheus" \
--config.file=prometheus.yml
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
##################################################
vim /usr/local/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:
- job_name: "redis-server"
static_configs:
- targets: ["192.168.1.102:9121"]
###############################################################################
systemctl start prometheus
systemctl enable prometheus
systemctl status prometheus
# ss -tan | grep -w 9090
LISTEN 0 65535 [::]:9090 [::]:*
image.png
用浏览器访问:http://192.168.1.101:9090/
image.png image.png安装grafana
yum -y install https://dl.grafana.com/oss/release/grafana-6.0.2-1.x86_64.rpm
systemctl start grafana-server
systemctl enable grafana-server
systemctl status grafana-server
image.png
四、prometheus 和 grafana 集成
用浏览区打开 grafana web:http://192.168.1.101:3000
默认用户名和密码:admin
添加数据源 Prometheus,点击配置,点击 Data Sources
image.png image.png image.png image.png image.png image.png image.png
五、导入prometheus-redis_rev1.json模板
https://grafana.com/api/dashboards/763/revisions/1/download
image.png如果启动多个redis实例,那么这个列表就会展示出所有的redis实例
上面也说到用redis_exporter 0.24版本,有redis.file 参数,可以将所有的redis实例写到一个文件中。
六、参考
Prometheus监控redis
https://www.cnblogs.com/layzer/articles/prometheus_redis.html
Grafana Prometheus系统监控Redis服务
https://blog.csdn.net/wyl9527/article/details/97151685
Prometheus监控Redis
https://blog.csdn.net/wc1695040842/article/details/107014209
Prometheus部署+简单监控
https://www.cnblogs.com/layzer/articles/prometheus_install_monitor.html
Prometheus 监控Redis的正确姿势(redis集群)
https://www.cnblogs.com/fsckzy/p/12053604.html
Prometheus 和 Grafana 集成
https://blog.csdn.net/weixin_45417821/article/details/123729143
prometheus.service启动、停止、重启、自启动
https://blog.csdn.net/qq_32014795/article/details/121852659
How to Setup a Redis Exporter for Prometheus
https://blog.ruanbekker.com/blog/2020/05/05/how-to-setup-a-redis-exporter-for-prometheus
网友评论