On this page
在 Linux 上使用 SNMP 监视 MongoDB
在本页面
Enterprise Feature
SNMP 仅在MongoDB Enterprise中可用。
Overview
MongoDB Enterprise 可以通过 SNMP 提供数据库 Metrics,以支持集中式数据收集和聚合。此过程说明了mongod实例作为 SNMP 子代理的设置和配置,以及通过 MongoDB Enterprise 初始化和测试 SNMP 支持。
See also
Troubleshoot SNMP和使用 SNMP 监视 MongoDB Windows提供了有关在 Windows 系统上使用 MongoDB 和 SNMP 的完整说明。
Considerations
Configuration Files
MongoDB Enterprise 包含以下 SNMP 配置文件:
MONGOD-MIB.txt
:
Management 信息库(MIB)文件,用于定义 MongoDB 的 SNMP 输出。在 Ubuntu 和 Debian 平台上,此文件出厂时已压缩为MONGOD-MIB.txt.gz
,必须使用gunzip
解压缩。
mongod.conf.subagent
:
以mongod作为 SNMP 子代理运行的配置文件。该文件设置 SNMP 运行时配置选项,包括用于连接到 SNMP 主设备的agentXSocket
。
mongod.conf.master
:
以mongod作为 SNMP 主服务器运行的配置文件。该文件设置 SNMP 运行时配置选项,包括要运行的agentaddress
。
MongoDB Enterprise 安装随附了 MongoDB SNMP 配置文件,如下所示:
- 如果通过软件包 Management 器安装了 MongoDB Enterprise,则在软件包安装过程中会将这些文件安装到以下目录:
Platform | Path |
---|---|
RHEL/CentOS | /usr/share/doc/mongodb-enterprise-server-3.6.19 |
Ubuntu/Debian 的 | /usr/share/doc/mongodb-enterprise-server |
SUSE | /usr/share/doc/packages/mongodb-enterprise-server |
- 如果您是从
.tgz
tarball 安装 MongoDB Enterprise 的,这些文件将包含在 tarball 中。
Procedure
复制配置文件。
根据您的平台,将 MongoDB SNMP 配置文件从其安装位置复制到其目标目录:
- Navigate to the location where the SNMP files were installed. For example, if you installed the latest version of MongoDB via the
yum
package manager:
cd /usr/share/doc/mongodb-enterprise-server-3.6.19
- Copy the two MongoDB SNMP files to their target directories:
sudo cp MONGOD-MIB.txt /usr/share/snmp/mibs/
sudo cp mongod.conf.subagent /etc/snmp/mongod.conf
- Navigate to the location where the SNMP files were installed. For example, if you installed MongoDB via the
apt
package manager:
cd /usr/share/doc/mongodb-enterprise-server
- Copy the
MONGOD-MIB.txt.gz
file to its target directory, and unzip it:
sudo cp MONGOD-MIB.txt.gz /usr/share/snmp/mibs/
sudo gunzip /usr/share/snmp/mibs/MONGOD-MIB.txt.gz
- Copy the
mongod.conf.subagent
file to its target directory:
sudo cp mongod.conf.subagent /etc/snmp/mongod.conf
- Navigate to the location where the SNMP files were installed. For example, if you installed the latest version of MongoDB via the
zypper
package manager:
cd /usr/share/doc/packages/mongodb-enterprise-server
- Copy the two MongoDB SNMP files to their target directories:
sudo cp MONGOD-MIB.txt /usr/share/snmp/mibs/
sudo cp mongod.conf.subagent /etc/snmp/mongod.conf
Configure SNMP.
Edit the /etc/snmp/snmpd.conf
file, and add the following:
# sec.name source community
com2sec local localhost mongodb
# group.name sec.model sec.name
group MyRWGroup any local
# incl/excl subtree mask
view all included .1 80
# context sec.model sec.level prefix read write notif
access MyRWGroup "" any noauth 0 all all all
master agentx
AgentXSocket /tmp/agentx/master
AgentXPerms 0777 0777 mongod mongod
- Install
snmpd
if it is not already installed:
sudo apt-get install snmpd
- Edit the
/etc/snmp/snmpd.conf
file, and add the following:
# sec.name source community
com2sec local localhost mongodb
# group.name sec.model sec.name
group MyRWGroup any local
# incl/excl subtree mask
view all included .1 80
# context sec.model sec.level prefix read write notif
access MyRWGroup "" any noauth 0 all all all
AgentXSocket /tmp/agentx/master
AgentXPerms 0777 0777 mongodb mongodb
Edit the /etc/snmp/snmpd.conf
file, and add the following:
# sec.name source community
com2sec local localhost mongodb
# group.name sec.model sec.name
group MyRWGroup any local
# incl/excl subtree mask
view all included .1 80
# context sec.model sec.level prefix read write notif
access MyRWGroup "" any noauth 0 all all all
master agentx
AgentXSocket /tmp/agentx/master
AgentXPerms 0777 0777 mongod mongod
此配置定义了一个 UNIX 域套接字,用于在* master (snmpd
)和 sub-agent *(MongoDB)之间进行通信,并定义了访问相关 MongoDB SNMP 字段的基本 SNMP 权限。
Note
要将您的主服务器绑定到 nonlocalIP 地址,请将该 IP 地址添加到/etc/snmp/snmpd.conf
文件中的agentaddress
字段,然后更新适当的网络安全 ACL 以允许有效的地址范围。 mongod.conf.master
配置文件中提供了一个安全名称为“ mynetwork”的地址范围 10.0.0.0/8 作为示例。
以上配置仅作为示例提供;您可能希望根据您的站点安全要求自定义权限。虽然 MongoDB 支持可以提供有关为 SNMP 配置 MongoDB 的指导,但是在 os 上配置 SNMP 不在范围之内。
Start SNMP.
使用适合您的 Linux 版本的初始化系统在系统上启动 SNMP:
- 对于使用 systemd (
systemctl
命令)的 Linux 系统:
sudo systemctl start mongod
- 对于使用 System V init (
service
命令)的 Linux 系统:
sudo service mongod start
Start MongoDB.
以snmp-subagent
开头mongod以将数据发送到 SNMP 主服务器。
mongod --snmp-subagent
确认 SNMP 数据检索。
使用snmpwalk
testing 命令验证 MongoDB 是否可用于 SNMP 查询。
- Install
snmpwalk
on your system:
sudo yum install net-snmp-utils
- Run
snmpwalk
with the following parameters to verify the ability to collect data from mongod:
snmpwalk -m /usr/share/snmp/mibs/MONGOD-MIB.txt -v 2c -c mongodb 127.0.0.1:161 1.3.6.1.4.1.34601
- DEBIAN ONLY : If necessary, add the
non-free
repository to your/etc/apt/sources.list
file to access thesnmp-mibs-downloader
package. For example, on Debian 9 "Stretch", the primary repo entries might look like this:
deb http://deb.debian.org/debian stretch main non-free
deb-src http://deb.debian.org/debian stretch main non-free
- DEBIAN / UBUNTU : Install the
snmp-mibs-downloader
package to supply necessary MIB files, then restart thesnmpd
service to reload the new MIB files:
sudo apt-get update
sudo apt-get -y install snmp-mibs-downloader
sudo service snmpd restart
- DEBIAN / UBUNTU : Run
snmpwalk
with the following parameters to verify the ability to collect data from mongod:
snmpwalk -m /usr/share/snmp/mibs/MONGOD-MIB.txt -v 2c -c mongodb 127.0.0.1:161 1.3.6.1.4.1.34601
snmpwalk -m /usr/share/snmp/mibs/MONGOD-MIB.txt -v 2c -c mongodb 127.0.0.1:161 1.3.6.1.4.1.34601
snmpwalk
命令应显示 SNMP 字段的当前值,例如sysUpTime
和memoryResident
等。
可选:将 MongoDB 作为 SNMP Master 运行
您可以使用snmp-master
选项运行mongod进行测试。为此,请使用 SNMP 主配置文件而不是子代理配置文件。从包含解压缩的 MongoDB 安装文件的目录中:
cp mongod.conf.master /etc/snmp/mongod.conf
Note
要将您的主服务器绑定到 nonlocalIP 地址,请将该 IP 地址添加到/etc/snmp/mongod.conf
文件中的agentaddress
字段,然后更新适当的网络安全 ACL 以允许有效的地址范围。作为示例,在主配置文件中提供了安全名称为“ mynetwork”的地址范围 10.0.0.0/8.
然后,使用snmp-master
选项启动mongod:
mongod --snmp-master