mongodb的设计理念:尽可能简化系统操作。
8.1 启动和停止
管理严在生产环境中部署mongodb的要点
8.1.1 从命令行启动
D:\java\mongodb-win32-i386-2.2.3\bin>mongod --help Wed Mar 20 20:42:43 Wed Mar 20 20:42:43 ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data Wed Mar 20 20:42:43 ** see http://blog.mongodb.org/post/137788967/32-bit-l imitations Wed Mar 20 20:42:43 ** with --journal, the limit is lower Wed Mar 20 20:42:43 Allowed options: |
Windows Service Control Manager options: Replication options: Master/slave options: Replica set options: Sharding options: |
8.1.2 配置文件
mongodb支持从文件获取配置信息。
8.1.3 停止mongodb
8.2 监控
8.2.1 使用管理接口
默认情况,启动mongodb是会启动一个HTTP服务器,+1000端口
要想利用好管理接口,需要用--rest选项开启REST支持,也可以在启动mongod是使用--nohttpinterface关闭管理接口
http://localhost:28017/
mongod king-PCList all commands | Replica set status Commands: buildInfo cursorInfo features hostInfo isMaster listDatabases replSetGetStatus serverStatus topdb version v2.2.3, pdfile version 4.5 git hash: f570771a5d8a3846eb7586eaffcf4c2f4a96bf08 sys info: windows sys.getwindowsversion(major=6, minor=0, build=6002, platform=2, service_pack='Service Pack 2') BOOST_LIB_VERSION=1_49 uptime: 3734 secondsoverview (only reported if can acquire read lock quickly) time to get readlock: 0ms # databases: 2 # Cursors: 0 replication: master: 0 slave: 0clients
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
write locked now: false Log Wed Mar 20 20:43:19 [initandlisten] MongoDB starting : pid=7944 port=27017 dbpath=c:\data\db 32-bit host=king-PC 20:43:19 [initandlisten] 20:43:19 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data 20:43:19 [initandlisten] ** see http://blog.mongodb.org/post/137788967/32-bit-limitations 20:43:19 [initandlisten] ** with --journal, the limit is lower 20:43:19 [initandlisten] 20:43:19 [initandlisten] db version v2.2.3, pdfile version 4.5 20:43:19 [initandlisten] git version: f570771a5d8a3846eb7586eaffcf4c2f4a96bf08 20:43:19 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=0, build=6002, platform=2, service_pack='Service Pack 2') BOOST_LIB_VERSION=1_49 20:43:19 [initandlisten] options: { dbpath: "c:\data\db" } 20:43:19 [initandlisten] Unable to check for journal files due to: boost::filesystem::basic_directory_iterator constructor: ϵͳ�Ҳ���ָ����·����: "c:\data\db\journal" 20:43:19 [initandlisten] waiting for connections on port 27017 20:43:19 [websvr] admin web console waiting for connections on port 28017 20:43:38 [initandlisten] connection accepted from 127.0.0.1:50891 #1 (1 connection now open) 20:44:51 [conn1] build index test.foo { _id: 1 } 20:44:51 [conn1] build index done. scanned 0 total records. 0.003 secs |
****不要用驱动程序连接HTTP接口,也不要用HTTP连接本机驱动端口
驱动端口只能处理本机mongodb传输协议,不能处理HTTP请求
不能用本机mongodb传输协议去访问管理接口的端口
http://localhost:27017/
You are trying to access MongoDB on the native driver port. For http diagnostic access, add 1000 to the port number |
8.2.2 serverStatus
要获取运行中的mongodb服务器的统计信息,最基本的工具是serverStatus命令,(不同平台不同版本可能不同)
> db.runCommand({"serverStatus":1}) }, } |
原始的统计信息同样可以有HTTP接口一json的形式得到,还有其他一些有用命令的输出
http://localhost:28017/_status
{ "serverStatus" : { "host" : "king-PC", "version" : "2.2.3", "process" : "mongod", "pid" : 7944, "uptime" : 4586, "uptimeMillis" : 4586204, "uptimeEstimate" : 3261, "localTime" : { "$date" : 1363787985482 }, "locks" : { "." : { "timeLockedMicros" : { "R" : 43, "W" : 66111 }, "timeAcquiringMicros" : { "R" : 20, "W" : 16 } }, "admin" : { "timeLockedMicros" : {}, "timeAcquiringMicros" : {} }, "local" : { "timeLockedMicros" : { "r" : 14749, "w" : 0 }, "timeAcquiringMicros" : { "r" : 760, "w" : 0 } }, "test" : { "timeLockedMicros" : { "r" : 50981, "w" : 48442 }, "timeAcquiringMicros" : { "r" : 362, "w" : 8 } } }, "globalLock" : { "totalTime" : 4586204000, "lockTime" : 66111, "currentQueue" : { "total" : 0, "readers" : 0, "writers" : 0 }, "activeClients" : { "total" : 0, "readers" : 0, "writers" : 0 } }, "mem" : { "bits" : 32, "resident" : 18, "virtual" : 147, "supported" : true, "mapped" : 64 }, "connections" : { "current" : 1, "available" : 19999 }, "extra_info" : { "note" : "fields vary by platform", "page_faults" : 17872, "usagePageFileMB" : 33, "totalPageFileMB" : 4094, "availPageFileMB" : 1400, "ramMB" : 2047 }, "indexCounters" : { "note" : "not supported on this platform" }, "backgroundFlushing" : { "flushes" : 76, "total_ms" : 4744, "average_ms" : 62.42105263157895, "last_ms" : 108, "last_finished" : { "$date" : 1363787960012 } }, "cursors" : { "totalOpen" : 0, "clientCursors_size" : 0, "timedOut" : 0 }, "network" : { "bytesIn" : 860, "bytesOut" : 2610, "numRequests" : 11 }, "opcounters" : { "insert" : 1, "query" : 153, "update" : 0, "delete" : 0, "getmore" : 0, "command" : 10 }, "asserts" : { "regular" : 0, "warning" : 0, "msg" : 0, "user" : 0, "rollovers" : 0 }, "writeBacksQueued" : false, "recordStats" : { "accessesNotInMemory" : 4, "pageFaultExceptionsThrown" : 0, "local" : { "accessesNotInMemory" : 0, "pageFaultExceptionsThrown" : 0 }, "test" : { "accessesNotInMemory" : 4, "pageFaultExceptionsThrown" : 0 } } }, "buildinfo" : { "version" : "2.2.3", "gitVersion" : "f570771a5d8a3846eb7586eaffcf4c2f4a96bf08", "sysInfo" : "windows sys.getwindowsversion(major=6, minor=0, build=6002, platform=2, service_pack='Service Pack 2') BOOST_LIB_VERSION=1_49", "versionArray" : [ 2, 2, 3, 0 ], "bits" : 32, "debug" : false, "maxBsonObjectSize" : 16777216 } } |
关于serverStatus的一些参数说明:
8.2.3 mongostat
mongodb提供了mongostatus,可以动态便捷的查看serverStatus信息
8.2.4 第三方插件
8.3 安全和认证
mongodb支持对单个连接的认证,即便这个认证的权限模式很简陋。
8.3.1 认证的基础知识
8.4 备份和修复
8.4.1 数据文件备份
这个方式实际上就是在数据库关闭时备份数据库目录的文件。
8.4.2 mongodump和mongorestore
mongodump提供运行时备份的解决方案,使用普通的查询机制,对运行的mongodb做查询,然后将所有查询到的文档写入磁盘。
mongorestore恢复
8.4.3 fsync和锁
8.4.4 从属备份