【Prometheus-Mongodb Exporter安装配置指南,开机自启】

目录

内容概述

本教程详细演示了如何在Linux系统中部署MongoDB Exporter以监控MongoDB数据库,并将其集成到Prometheus监控体系。教程涵盖以下核心步骤:

  1. 创建具备监控权限的MongoDB专用用户
  2. 安装配置MongoDB Exporter二进制包
  3. 创建Systemd服务实现守护进程管理
  4. 配置Prometheus抓取Exporter指标
  5. 基础服务管理命令演示

一、创建MongoDB监控专用用户

bash 复制代码
mongo -u admin -p 123456 --authenticationDatabase admin
  1. 切换至admin数据库
javascript 复制代码
use admin
  1. 创建监控用户(包含集群监控和本地库读权限)
javascript 复制代码
db.createUser({
  user: "mongodb_expo",
  pwd: "SecurePassword",
  roles: [
    { role: "clusterMonitor", db: "admin" },
    { role: "read", db: "local" }
  ]
});
  1. 验证用户创建
javascript 复制代码
db.getUser("mongodb_expo")
  1. 退出MongoDB
bash 复制代码
ctrl+z

二、安装MongoDB Exporter

bash 复制代码
# 创建安装目录
mkdir -p /usr/local/mongodb_exporter

# 解压安装包(需提前下载对应版本)
tar -zxvf mongodb_exporter-0.20.5.linux-amd64.tar.gz -C /usr/local/mongodb_exporter --strip-components=1

三、启动Exporter服务

bash 复制代码
# 基础启动命令
/usr/local/mongodb_exporter/mongodb_exporter \
  --mongodb.uri='mongodb://mongodb_expo:SecurePassword@192.168.15.131:27017/admin' \
  --web.listen-address=:9216 \
  --compatible-mode

# 查看帮助参数
/usr/local/mongodb_exporter/mongodb_exporter --help

四、配置Systemd服务

bash 复制代码
vim /usr/lib/systemd/system/mongodb_exporter.service
ini 复制代码
[Unit]
Description=MongoDB Exporter
After=network.target

[Service]
User=root
Group=root
Type=simple
ExecStart=/usr/local/mongodb_exporter/mongodb_exporter \
  --mongodb.uri=mongodb://mongodb_expo:SecurePassword@192.168.15.131:27017/admin \
  --web.listen-address=:9216 \
  --compatible-mode
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target

五、服务管理命令

bash 复制代码
# 重载systemd配置
systemctl daemon-reload

# 设置开机自启
systemctl enable mongodb_exporter

# 服务控制
systemctl stop mongodb_exporter
systemctl restart mongodb_exporter
systemctl status mongodb_exporter

六、Prometheus集成配置

bash 复制代码
vim /usr/local/prometheus/prometheus.yml
yaml 复制代码
scrape_configs:
  - job_name: 'mongodb'
    static_configs:  
    - targets: ['192.168.15.131:9216']
bash 复制代码
# 应用配置变更(注意:原命令中的postgres_exporter应为笔误)
systemctl restart mongodb_exporter

七、Grafana看板

相关推荐
code_pgf4 分钟前
Jetson Orin NX 16G设备上配置AI服务自动启动的方案,包括Ollama、llama-server和OpenClaw Gateway三个组件
数据库·人工智能·安全·gateway·边缘计算·llama
SelectDB5 分钟前
doris404发版
大数据·数据库·数据分析
SelectDB7 分钟前
SelectDB search 函数
大数据·数据库·数据分析
2301_818419019 分钟前
Python虚拟环境(venv)完全指南:隔离项目依赖
jvm·数据库·python
蒸汽求职10 分钟前
蒸汽教育求职分享:2026年数据工程师就业优势分析与职业发展路径指南
数据库·人工智能·面试·求职招聘·美国求职
IDC02_FEIYA10 分钟前
SQL Server 2016及SQL Server Management Studio下载,SQL Server 2016数据库安装教程图解
服务器·数据库·性能优化
程序员buddha16 分钟前
Java面试八股文数据库篇
java·数据库·面试
hutengyi29 分钟前
开源的Text-to-SQL工具WrenAI
数据库·sql·开源
l1t33 分钟前
DeepSeek总结的postgresql EXPLAIN 的其他超能力
数据库·postgresql
2401_8732046536 分钟前
Python深度学习入门:TensorFlow 2.0/Keras实战
jvm·数据库·python