在GCE中使用StackDriver监控MongoDB 3

有没有人成功地设法监视在GCE的StackDriver的MongoDB 3群集(或独立的数据库)?

我已经在GCE中设置了一个MongoDB 3.0.6集群(具有2个副本和1个仲裁器的副本集)

我试图通过Google提供的StackDriver来监视它。

我已按照所有说明安装了监视代理程序和mongodb插件,可在此处find: https : //cloud.google.com/monitoring/agent/plugins/mongodb

当我在configuration的副本上启动代理时:

sudo /etc/init.d/stackdriver-agent restart 

我在/ var / log / syslog中得到以下错误:

 collectd[6013]: tcpconns plugin: Reading from netlink succeeded. Will use the netlink method from now on. collectd[6013]: mongo plugin: Authenticating to localhost:27017 failed: collectd[6013]: mongo plugin: Connecting to localhost:27017 failed: collectd[6013]: read-function of plugin `mongodb' failed. Will suspend it for 120.000 seconds. 

我怀疑StackDriver代理与MongoDB 3不兼容,因为:

  • 在过去,我使用了GCE的Click-to-deploy特性来创build一个集群,并且能够使用StackDriver监视它。 那时候是MongoDB 2.6.x.

  • 我已经快速安装了MongoDB 2.6.x的独立安装,以相同的方式configuration了StackDriver代理,并且它可以工作:-(

任何帮助将非常感激。

configuration细节:

Mongodb:

  • AUTH =真

  • 在数据库pipe理员中,具有以下angular色的用户:dbAdminAnyDatabase,clusterAdmin和readAnyDatabase

Stackdriver Mongodb插件:

  • 这个用户和密码在/opt/stackdriver/collectd/etc/collectd.d/mongodb.conf

附加信息 :

无validation :插件成功初始化

/etc/mongod.conf:

 # Turn on/off security. Off is currently the default #noauth = true #auth = true 

/opt/stackdriver/collectd/etc/collectd.d/mongodb.conf:

 LoadPlugin mongodb <Plugin "mongodb"> Host "localhost" Port "27017" # If you restricted access to the database, you can # set the username and password here # User "user_name" # Password "user_password" # For performance/eventually consistent trade-offs you may add this line # PreferSecondaryQuery true </Plugin> 

身份validation模式:重新启动代理时发生身份validation错误

/etc/mongod.conf:

 # Turn on/off security. Off is currently the default #noauth = true auth = true 

3个用户configuration

 use admin db.createUser( { user: "siteUserAdmin", pwd: "xxx", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] } ) db.auth("siteUserAdmin", "xxx"); db.createUser( { user: "siteRootAdmin", pwd: "xxx", roles: [ { role: "root", db: "admin" } ] }); db.createUser( { user: "monitoring", pwd: "xxx", roles: [ { role: "dbAdminAnyDatabase", db: "admin" }, { role: "clusterAdmin", db: "admin" }, { role: "readAnyDatabase", db: "admin" } ] } ) 

/opt/stackdriver/collectd/etc/collectd.d/mongodb.conf:

 LoadPlugin mongodb <Plugin "mongodb"> Host "localhost" Port "27017" # If you restricted access to the database, you can # set the username and password here User "monitoring" Password "xxx" # For performance/eventually consistent trade-offs you may add this line # PreferSecondaryQuery true </Plugin> 

在插件configuration中使用siteRootAdmin时出现同样的错误。

解释和解决scheme

罪魁祸首实际上是StackDriver代理使用的身份validation模式

我修改了Adam Cbuild议的解决scheme ,因为我已经有了使用SCRAM-SHA-1架构创build的用户。

实际上,我只需要监控用户使用MONGODB-CR。

要做到这一点:

使用auth禁用重新启动MongoDB 3.0

连接到实例

将身份validation模式临时更改为MONGODB-CR

 use admin var schema = db.system.version.findOne({"_id" : "authSchema"}); schema.currentVersion = 3; db.system.version.save(schema); 

为StackDriver插件创build用户

 db.createUser( { user: "monitoring", pwd: "xxx", roles: [ { role: "dbAdminAnyDatabase", db: "admin" }, { role: "clusterAdmin", db: "admin" }, { role: "readAnyDatabase", db: "admin" } ] } ) 

检查它是否有正确的身份validation模式:MONGODB-CR

 > db.system.users.find({"user":"monitoring"}) { "_id" : "admin.monitoring", "user" : "monitoring", "db" : "admin", "credentials" : { "MONGODB-CR" ... 

将auth架构退回到SCRAM-SHA-1

 var schema = db.system.version.findOne({"_id" : "authSchema"}); schema.currentVersion = 5; db.system.version.save(schema); 

使用auth启用重新启动MongoDB 3.0

重新启动StackDriver代理

当StackDriver将支持SCRAM-SHA-1时,为此用户升级auth模式将很有用

 db.adminCommand({authSchemaUpgrade: 1}); 

我怀疑堆栈驱动程序还没有支持新的SCRAM-SHA-1authentication机制。 这个新的机制在3.0中被添加来代替MONGODB-CR并且是3.0+中的默认,但是它要求驱动程序支持新的机制。

为了让MongoDB 3.0使用旧的机制,你可以从2.6开始,在那里创build你的用户,然后升级,或者你可以做以下的事情(基于这个评论 ):

  • 启用MongoDB 3.0 auth禁用(确保没有用户已被添加)
  • 连接到实例并运行以下命令:

    var schema = db.system.version.findOne({"_id" : "authSchema"}); schema.currentVersion = 3; db.system.version.save(schema);

  • 用auth启动MongoDB并创build你的用户

现在应该使用MONGODB-CR创build这些用途。 StackDriver使用libmongoc 1.1版本开始支持SCRAM-SHA-1的libmongoc ,但是基于某些Github浏览,它们的版本看起来更老了。 一旦他们更新了驱动程序,这个问题应该消失 – 现在你将不得不解决它。

我在Google上的Stackdriver代理工作。 亚当C的回答是正确的。 最近我一直在研究这个问题,现在我们有一个beta版本,在我们自己的testing中运行良好。 这个新版本不仅解决了SCRAM-SHA-1问题,而且还有一些性能上的改进。 在更广泛地发布之前,我们希望有机会在几个客户环境中进行testing。

如果有人愿意成为我们代理的新版本的testing版testing人员,我可以安排为您提供.deb或.rpm文件,以适合您的平台。 像往常一样,有一点小小的风险可能会出现问题,所以我认为这只有在您可以尝试使用非生产环境时才有意义。

编辑:截至2016年7月12日,这一变化现已投入生产!