使用prometheus监控redis集群
1.安装下载redis_exporter
下载地址:
https://github.com/oliver006/redis_exporter/releases
tar -xvf redis_exporter-v1.55.0.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/
mv redis_exporter-v1.55.0.linux-amd64/ redis_exporter
2 启动
cd /usr/local/redis_exporter
nohup ./redis_exporter -redis.addr 172.20.2.18:6379 &
nohup ./redis_exporter -redis.addr 172.20.2.18:6380 &
多实例(有密码)
cd /usr/local/redis_exporter
nohup ./redis_exporter -redis.addr 172.2.1.3:6380 -redis.password=oj+xjlARRfJqbC+A --web.listen-address=:9120 &
nohup ./redis_exporter -redis.addr 172.2.1.3:6381 -redis.password=oj+xjlARRfJqbC+A --web.listen-address=:9121 &
3 配置systemctl并加入开机自启(此步骤可省略)
3.1 redis无密码版
cat > /etc/systemd/system/redis_exporter.service << "EOF"
[Unit]
Description=redis_exporter
After=local-fs.target network-online.target network.target
Wants=local-fs.target network-online.target network.target
[Service]
ExecStart=/usr/local/redis_exporter/redis_exporter -redis.addr 172.22.201.32:6380
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
3.2 redis有密码版
cat > /etc/systemd/system/redis_exporter.service << "EOF"
[Unit]
Description=redis_exporter
After=local-fs.target network-online.target network.target
Wants=local-fs.target network-online.target network.target
[Service]
ExecStart=/usr/local/bin/redis_exporter -redis.addr 172.22.201.32:6380 -redis.password=oj+xjlARRfJqbC+A --web.listen-address=:9120
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
如果有多个实例,就创建多个service文件即可
systemctl daemon-reload
systemctl enable redis_exporter
systemctl start redis_exporter
systemctl status redis_exporter
3.3配置prometheus
vim prometheus.yaml
- job_name: 'redis_exporter_cluster'
static_configs:
- targets:
- redis://172.22.1.4:6380
- redis://172.22.1.4:6381
params:
check-keys: ["metrics:*"]
metrics_path: /scrape
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 172.22.15.84:9121
#监控redis
- job_name: 'redis_exporter'
static_configs:
- targets:
- 172.22.15.84:9121
原文链接:https://blog.csdn.net/m0_53563073/article/details/136401334