Mongodb 简明教程

MongoDB - Deployment

在准备 MongoDB 部署时,您应尝试了解您的应用程序将在生产环境中的表现。最好开发一个一致、可重复的方法来管理您的部署环境,以最大限度地减少在生产过程中出现的意外事件。

When you are preparing a MongoDB deployment, you should try to understand how your application is going to hold up in production. It’s a good idea to develop a consistent, repeatable approach to managing your deployment environment so that you can minimize any surprises once you’re in production.

最佳方法是构建原型设置、执行负载测试、监控关键指标并使用这些信息扩展您的设置。该方法的关键部分是主动监控您的整个系统——它将帮助您了解您的生产系统将如何在部署前表现,并确定您需要提升容量的位置。例如,了解您内存使用率中的潜在高峰,可以帮助在锁定之前解决写锁定错误。

The best approach incorporates prototyping your set up, conducting load testing, monitoring key metrics, and using that information to scale your set up. The key part of the approach is to proactively monitor your entire system - this will help you understand how your production system will hold up before deploying, and determine where you will need to add capacity. Having insight into potential spikes in your memory usage, for example, could help put out a write-lock fire before it starts.

要监视您的部署,MongoDB 提供以下部分指令:

To monitor your deployment, MongoDB provides some of the following commands −

mongostat

此指令检查所有正在运行的 mongod 实例的状态,并返回数据库操作计数器。这些计数器包括插入、查询、更新、删除和游标。此指令还显示您何时遇到页面错误,以及您的锁定百分比。这意味着您的内存不足、达到写容量,或遇到某些性能问题。

This command checks the status of all running mongod instances and return counters of database operations. These counters include inserts, queries, updates, deletes, and cursors. Command also shows when you’re hitting page faults, and showcase your lock percentage. This means that you’re running low on memory, hitting write capacity or have some performance issue.

要运行此指令,请启动您的 mongod 实例。在另一个命令提示符中,转到 mongodb 安装的 bin 目录并键入 mongostat

To run the command, start your mongod instance. In another command prompt, go to bin directory of your mongodb installation and type mongostat.

D:\set up\mongodb\bin>mongostat

以下为指令输出:

Following is the output of the command −

mongostat
mongostat2

mongotop

此指令在集合的基础上跟踪并报告 MongoDB 实例的读写活动。默认情况下, mongotop 每秒返回一次信息,您可以根据需要更改信息。您应检查此读写活动是否符合您的应用程序预期,并且您不会一次向数据库写入太多信息、不会从磁盘读取过于频繁或超过您的工作集大小。

This command tracks and reports the read and write activity of MongoDB instance on a collection basis. By default, mongotop returns information in each second, which you can change it accordingly. You should check that this read and write activity matches your application intention, and you’re not firing too many writes to the database at a time, reading too frequently from a disk, or are exceeding your working set size.

要运行此指令,请启动您的 mongod 实例。在另一个命令提示符中,转到 mongodb 安装的 bin 目录并键入 mongotop

To run the command, start your mongod instance. In another command prompt, go to bin directory of your mongodb installation and type mongotop.

D:\set up\mongodb\bin>mongotop

以下为指令输出:

Following is the output of the command −

mongotop
mongotop2

要更改 mongotop 指令以减少返回信息的频率,请在 mongotop 指令后指定一个特定的数字。

To change mongotop command to return information less frequently, specify a specific number after the mongotop command.

D:\set up\mongodb\bin>mongotop 30

上述示例会每隔 30 秒返回一次值。

The above example will return values every 30 seconds.

除了 MongoDB 工具之外,10gen 还提供了一项免费托管式监控服务,即 MongoDB 管理服务 (MMS),它提供了一个仪表盘,让你可以查看整个群集的指标。

Apart from the MongoDB tools, 10gen provides a free, hosted monitoring service, MongoDB Management Service (MMS), that provides a dashboard and gives you a view of the metrics from your entire cluster.