首页 > 解决方案 > Mongodb 导出器即 Linux 中的服务

问题描述

我正在尝试使用此 github 链接安装 mongodb 导出器:https ://github.com/percona/mongodb_exporter

我按照此链接获取说明 https://www.percona.com/blog/2020/04/17/how-to-configure-mongodb-exporter-with-ssl-tls/

到目前为止没有问题,我可以单独使用“mongodb_exporter”二进制文件执行并通过执行成功连接到mongo

mongodb_exporter --mongodb.uri=mongodb://user:password@localhost:27017?ssl=true&sslclientcertificatekeyfile=/etc/ssl/mongo.pem&sslinsecure=true&sslcertificateauthorityfile=/etc/ssl/mongo.pem

但是要将这个二进制文件作为服务运行,我在 /etc/systemd/system 文件夹中创建了一个 mongodb_exporter.service。

这是服务文件的内容:

[Unit]
Description=Mongodb Exporter
After=network-online.target

[Service]
User=mongodb_exporter
Group=mongodb_exporter
Type=simple
EnvironmentFile=/etc/.mongodb_exporterconf
ExecStart=/usr/local/bin/mongodb_exporter $ARG1

[Install]
WantedBy=multi-user.target

如您所见,我之前创建了 .mongodb_exporterconf 文件,然后为 ARG1 变量分配了上面的标志“--mongodb.uri”

当我检查此服务的状态时,它会引发此错误error msg="Can't create mongo session to mongodb://****:password@localhost:27017?&sslclientcertificatekeyfile=/etc/ssl/mongo.pem&sslinsecure=true&sslcertificateauthorityfile=/etc/ssl/mongo.pem" source="mongodb_collector.go:188"

目前我不知道我错过了什么,但我发现只有 1 个线索,但我不太确定,是错误消息没有显示或跳过“ssl = true”选项。或者我只是错过了一些配置。任何想法或帮助表示赞赏!

标签: linuxmongodbsslexporter

解决方案


原来我只需要--mongodb.uri=mongodb://user:password@localhost:27017?ssl=true,其他选项是可选的。


推荐阅读