第八章 管理
一启动和停止mongodb
Mongodb的启动项可以通过mongod --help命令查看
C:\Users\Administrator>mongod --help
Options:
General options:
-h[ --help ] showthis usage information
--version show version information 显示版本
-f[ --config ] arg configuration file specifying
additional options
指定配置文件
-v[ --verbose ] [=arg(=v)] bemore verbose (include multiple times
formore verbosity e.g. -vvvvv)
--quiet quieter output 安静输出
--port arg specify port number - 27017 by default
指定端口号,默认为27017
--bind_ip arg comma separated list of ip addresses to
listenon - all local ips by default
邦定ip
--ipv6 enable IPv6 support (disabled by
default)
启用ipv6
--maxConns arg max number of simultaneous connections
- 1000000by default
最大同时联接数
--logpath arg log file to send write to instead of
stdout- has to be a file, not
Directory
指定日志输出路径
--logappend append to logpath instead of
over-writing
以追加的方式写日志
--logRotate arg set the log rotation behavior
(rename|reopen)
--timeStampFormat arg Desired format for timestamps in log
messages. One of ctime, iso8601-utc or
iso8601-local
--pidfilepath arg full path to pidfile (if not set, no
pidfileis created)
Pid文件的完整路径
--keyFile arg private key for cluster authentication
集群的私钥的路径,replica set架构
--noauth run without security
不启用验证
--setParameter arg Set a configurable parameter
--httpinterface enable http interface
开启http服务接口
--clusterAuthMode arg Authentication mode used for cluster
authentication.Alternatives are
(keyFile|sendKeyFile|sendX509|x509)
--auth run with security
启用验证
--jsonp allow JSONP access via http (has
security implications)
允许jsonp通过http访问(有安全问题)
--rest turn on simple rest api
开启简单的rest API
--slowms arg (=100) value of slow for profile and console
Log
--profile arg 0=off 1=slow, 2=all
档案参数
--cpu periodically show cpu and iowait
Utilization
定期显示cpu的利用率
--sysinfo print some diagnostic system
Information
诊断系统信息
--noIndexBuildRetry don't retry any index builds that were
interrupted by shutdown
--noscripting disable scripting engine
禁用解本引警
--notablescan do not allow table scans
不允许表扫描
Windows Service Control Manager options:
--install install Windows service 创建windows系统服务
--remove remove Windows service 移除服务
--reinstall reinstall Windows service (equivalent
to --remove followed by--install)
--serviceName arg Windows service name 指定服务名称
--serviceDisplayName arg Windows service display name
--serviceDescription arg Windows service description
--serviceUser arg account for service execution
--servicePassword arg password used to authenticate
serviceUser
Replication options:
--oplogSize arg size to use (in MB) forreplication op
log.default is 5% of disk space (i.e.
largeis good)
设置oplog的大小,
Master/slave options (old; use replica setsinstead):
--master master mode 主库模式
--slave slave mode 从库模式
--source arg when slave: specify master as
<server:port> 从库端口号
--only arg when slave: specify a single database
toreplicate 指定单一的数据库复制
--slavedelay arg specify delay (in seconds) to be used
when applying master ops to slave
从库同步主库的延迟时间
--autoresync automatically resync if slave data is
Stale
如果主从库数据差太多,自动重同步
Replica set options:
--replSet arg arg is <setname>[/<optionalseedhostlist
>] 设置副本集名称
--replIndexPrefetch arg specify index prefetching behavior (if
secondary) [none|_id_only|all]
--enableMajorityReadConcern enables majority readConcern
Sharding options:
--configsvr declare this is a config db of a
cluster; default port 27019; default
dir /data/configdb
集群的config服务
--configsvrMode arg Controls what config server protocol is
in use.When set to "sccc" keeps server
inlegacy SyncClusterConnection mode
evenwhen the service is running as a
replSet
--shardsvr declare this is a shard db of a
cluster; default port 27018
集群的分片
SSL options:
--sslOnNormalPorts use ssl on configured ports
--sslMode arg set the SSL operation mode
(disabled|allowSSL|preferSSL|requireSSL
)
--sslPEMKeyFile arg PEM file for ssl
--sslPEMKeyPassword arg PEM file password
--sslClusterFile arg Key file for internal SSL
authentication
--sslClusterPassword arg Internal authentication key file
password
--sslCAFile arg Certificate Authority file for SSL
--sslCRLFile arg Certificate Revocation List file for
SSL
--sslDisabledProtocols arg Comma separated list of TLS protocols
todisable [TLS1_0,TLS1_1,TLS1_2]
--sslWeakCertificateValidation allow client to connect without
presenting a certificate
--sslAllowConnectionsWithoutCertificates
allowclient to connect without
presenting a certificate
--sslAllowInvalidHostnames Allow server certificates to provide
non-matching hostnames
--sslAllowInvalidCertificates allow connections to servers with
invalidcertificates
--sslFIPSMode activate FIPS 140-2 mode at startup
Storage options:
--storageEngine arg what storage engine to use - defaults
towiredTiger if no data files present
--dbpath arg directory for datafiles - defaults to
\data\db\ which is C:\data\db\ based on
thecurrent working drive
指定数据库目录
--directoryperdb each database will be stored in a
separatedirectory
设置每个数据库将保存在一个单独目录
--noprealloc disable data file preallocation - will
oftenhurt performance
禁用数据文件预分配(影响性能)
--nssize arg (=16) .ns file size (in MB) for new databases
设置信数据库.ns文件大小
--quota limits each database to a certain
numberof files (8 default)
限制每个数据库的文件数
--quotaFiles arg number of files allowed per db, implies
--quota
--smallfiles use a smaller default file size
使用较小的默认文件
--syncdelay arg (=60) seconds between disk syncs (0=never,
but notrecommended)
数据定入磁盘的时间秒数
--upgrade upgrade db if needed
如果需要升级数据库
--repair run repair on all dbs
修改所有数据库
--repairpath arg root directory for repair files -
defaults to dbpath
修复库生成的文件的目录
--journal enable journaling
启用日志,操作将写入journal文件夹文件中
--nojournal disable journaling (journaling is on by
defaultfor 64 bit)
--journalOptions arg journal diagnostic options
启用日志诊断选项
--journalCommitInterval arg how often to group/batch commit(ms)
WiredTiger options:
--wiredTigerCacheSizeGB arg maximum amount of memory to allocate
forcache; defaults to 1/2 of physical
RAM
--wiredTigerStatisticsLogDelaySecs arg (=0)
secondsto wait between each write to a
statistics file in the dbpath; 0 means
do not logstatistics
--wiredTigerJournalCompressor arg (=snappy)
use acompressor for log records
[none|snappy|zlib]
--wiredTigerDirectoryForIndexes Put indexes and data in different
directories
--wiredTigerCollectionBlockCompressor arg (=snappy)
blockcompression algorithm for
collection data [none|snappy|zlib]
--wiredTigerIndexPrefixCompression arg (=1)
useprefix compression on row-store
leafpages
配置文件
Mongod --config 配置文件全路径
停止mongodb
Control+c
Kill -2 进程号(不能使用kill -9)
二监控
1 使用管理端口
在启动mongodb的时候需要添加--httpinterface参数,需要开启rest支持
C:\Users\Administrator>mongod --dbpathh:\MongoDB\data --httpinterface --rest
可以通过浏览器查看管理接口http://localhost:28017/,如下图所示
查看运行时服务器的统计信息
>db.runCommand({"serverStatus":1})
也可以通过浏览器查看http://localhost:28017/_status
{ "host" : "retacn",
"advisoryHostFQDNs" : [],
"version" : "3.2.11",
"process" : "mongod",
"pid" : { "$numberLong" : "10312" },
"uptime" : 269,
"uptimeMillis" : { "$numberLong" : "268368" },
"uptimeEstimate" : 266,
"localTime" : { "$date" : "2017-01-12T15:18:44.007+0800" },
"asserts" : { "regular" : 0,
"warning" : 0,
"msg" : 0,
"user" : 0,
"rollovers" : 0 },
"connections" : { "current" : 1,
"available" : 999999,
"totalCreated" : { "$numberLong" : "7" } },
"extra_info" : { "note" : "fields vary by platform",
"page_faults" : 47571,
"usagePageFileMB" : 74,
"totalPageFileMB" : 7513,
"availPageFileMB" : 3820,
"ramMB" : 3757 },
"globalLock" : { "totalTime" : { "$numberLong" : "268366000" },
"currentQueue" : { "total" : 0,
"readers" : 0,
"writers" : 0 },
"activeClients" : { "total" : 9,
"readers" : 0,
"writers" : 0 } },
"locks" : { "Global" : { "acquireCount" : { "r" : { "$numberLong" : "1538" },
"w" : { "$numberLong" : "13" },
"R" : { "$numberLong" : "1" },
"W" : { "$numberLong" : "4" } } },
"Database" : { "acquireCount" : { "r" : { "$numberLong" : "756" },
"R" : { "$numberLong" : "4" },
"W" : { "$numberLong" : "13" } } },
"Collection" : { "acquireCount" : { "r" : { "$numberLong" : "788" } } },
"Metadata" : { "acquireCount" : { "w" : { "$numberLong" : "1" } } } },
"network" : { "bytesIn" : { "$numberLong" : "716" },
"bytesOut" : { "$numberLong" : "23618" },
"numRequests" : { "$numberLong" : "10" } },
"opcounters" : { "insert" : 0,
"query" : 1,
"update" : 0,
"delete" : 0,
"getmore" : 0,
"command" : 11 },
"opcountersRepl" : { "insert" : 0,
"query" : 0,
"update" : 0,
"delete" : 0,
"getmore" : 0,
"command" : 0 },
"storageEngine" : { "name" : "wiredTiger",
"supportsCommittedReads" : true,
"persistent" : true },
"tcmalloc" : { "generic" : { "current_allocated_bytes" : 54030984,
"heap_size" : 55508992 },
"tcmalloc" : { "pageheap_free_bytes" : 491520,
"pageheap_unmapped_bytes" : 0,
"max_total_thread_cache_bytes" : { "$numberLong" : "1073741824" },
"current_total_thread_cache_bytes" : 375008,
"total_free_bytes" : 986488,
"central_cache_free_bytes" : 611480,
"transfer_cache_free_bytes" : 0,
"thread_cache_free_bytes" : 375008,
"aggressive_memory_decommit" : 0,
"formattedString" : "------------------------------------------------\nMALLOC: 54030984 ( 51.5 MiB) Bytes in use by application\nMALLOC: + 491520 ( 0.5 MiB) Bytes in page heap freelist\nMALLOC: + 611480 ( 0.6 MiB) Bytes in central cache freelist\nMALLOC: + 0 ( 0.0 MiB) Bytes in transfer cache freelist\nMALLOC: + 375008 ( 0.4 MiB) Bytes in thread cache freelists\nMALLOC: + 4206752 ( 4.0 MiB) Bytes in malloc metadata\nMALLOC: ------------\nMALLOC: = 59715744 ( 56.9 MiB) Actual memory used (physical + swap)\nMALLOC: + 0 ( 0.0 MiB) Bytes released to OS (aka unmapped)\nMALLOC: ------------\nMALLOC: = 59715744 ( 56.9 MiB) Virtual address space used\nMALLOC:\nMALLOC: 257 Spans in use\nMALLOC: 7 Thread heaps in use\nMALLOC: 8192 Tcmalloc page size\n------------------------------------------------\nCall ReleaseFreeMemory() to release freelist memory to the OS (via madvise()).\nBytes released to the OS take up virtual address space but no physical memory.\n" } },
"wiredTiger" : { "uri" : "statistics:",
"LSM" : { "application work units currently queued" : 64,
"merge work units currently queued" : 0,
"rows merged in an LSM tree" : 0,
"sleep for LSM checkpoint throttle" : 0,
"sleep for LSM merge throttle" : 0,
"switch work units currently queued" : 0,
"tree maintenance operations discarded" : 0,
"tree maintenance operations executed" : 0,
"tree maintenance operations scheduled" : 0,
"tree queue hit maximum" : 0 },
"async" : { "current work queue length" : 0,
"maximum work queue length" : 0,
"number of allocation state races" : 0,
"number of flush calls" : 0,
"number of operation slots viewed for allocation" : 0,
"number of times operation allocation failed" : 0,
"number of times worker found no work" : 0,
"total allocations" : 0,
"total compact calls" : 0,
"total insert calls" : 0,
"total remove calls" : 0,
"total search calls" : 0,
"total update calls" : 0 },
"block-manager" : { "blocks pre-loaded" : 14,
"blocks read" : 46,
"blocks written" : 27,
"bytes read" : 217088,
"bytes written" : 147456,
"bytes written for checkpoint" : 147456,
"mapped blocks read" : 0,
"mapped bytes read" : 0 },
"cache" : { "application threads page read from disk to cache count" : 12,
"application threads page read from disk to cache time (usecs)" : 0,
"application threads page write from cache to disk count" : 0,
"application threads page write from cache to disk time (usecs)" : 0,
"bytes belonging to page images in the cache" : 79165,
"bytes currently in the cache" : 116058,
"bytes not belonging to page images in the cache" : 36893,
"bytes read into cache" : 73301,
"bytes written from cache" : 75214,
"checkpoint blocked page eviction" : 0,
"eviction calls to get a page" : 0,
"eviction calls to get a page found queue empty" : 0,
"eviction calls to get a page found queue empty after locking" : 0,
"eviction currently operating in aggressive mode" : 0,
"eviction empty score" : 0,
"eviction server candidate queue empty when topping up" : 0,
"eviction server candidate queue not empty when topping up" : 0,
"eviction server evicting pages" : 0,
"eviction server slept, because we did not make progress with eviction" : 0,
"eviction server unable to reach eviction goal" : 0,
"eviction state" : 16,
"eviction walks abandoned" : 0,
"eviction worker thread evicting pages" : 0,
"failed eviction of pages that exceeded the in-memory maximum" : 0,
"files with active eviction walks" : 0,
"files with new eviction walks started" : 0,
"hazard pointer blocked page eviction" : 0,
"hazard pointer check calls" : 0,
"hazard pointer check entries walked" : 0,
"hazard pointer maximum array length" : 0,
"in-memory page passed criteria to be split" : 0,
"in-memory page splits" : 0,
"internal pages evicted" : 0,
"internal pages split during eviction" : 0,
"leaf pages split during eviction" : 0,
"lookaside table insert calls" : 0,
"lookaside table remove calls" : 0,
"maximum bytes configured" : 1073741824,
"maximum page size at eviction" : 0,
"modified pages evicted" : 0,
"modified pages evicted by application threads" : 0,
"overflow pages read into cache" : 0,
"overflow values cached in memory" : 0,
"page split during eviction deepened the tree" : 0,
"page written requiring lookaside records" : 0,
"pages currently held in the cache" : 30,
"pages evicted because they exceeded the in-memory maximum" : 0,
"pages evicted because they had chains of deleted items" : 0,
"pages evicted by application threads" : 0,
"pages queued for eviction" : 0,
"pages queued for urgent eviction" : 0,
"pages queued for urgent eviction during walk" : 0,
"pages read into cache" : 27,
"pages read into cache requiring lookaside entries" : 0,
"pages requested from the cache" : 509,
"pages seen by eviction walk" : 0,
"pages selected for eviction unable to be evicted" : 0,
"pages walked for eviction" : 0,
"pages written from cache" : 13,
"pages written requiring in-memory restoration" : 0,
"percentage overhead" : 8,
"tracked bytes belonging to internal pages in the cache" : 15889,
"tracked bytes belonging to leaf pages in the cache" : 100169,
"tracked dirty bytes in the cache" : 0,
"tracked dirty pages in the cache" : 0,
"unmodified pages evicted" : 0 },
"connection" : { "auto adjusting condition resets" : 8,
"auto adjusting condition wait calls" : 844,
"files currently open" : 19,
"memory allocations" : 9689,
"memory frees" : 8630,
"memory re-allocations" : 719,
"pthread mutex condition wait calls" : 3553,
"pthread mutex shared lock read-lock calls" : 748,
"pthread mutex shared lock write-lock calls" : 400,
"total fsync I/Os" : 35,
"total read I/Os" : 495,
"total write I/Os" : 44 },
"cursor" : { "cursor create calls" : 50,
"cursor insert calls" : 19,
"cursor next calls" : 170,
"cursor prev calls" : 13,
"cursor remove calls" : 1,
"cursor reset calls" : 469,
"cursor restarted searches" : 0,
"cursor search calls" : 524,
"cursor search near calls" : 1,
"cursor update calls" : 0,
"truncate calls" : 0 },
"data-handle" : { "connection data handles currently active" : 16,
"connection sweep candidate became referenced" : 0,
"connection sweep dhandles closed" : 0,
"connection sweep dhandles removed from hash list" : 42,
"connection sweep time-of-death sets" : 42,
"connection sweeps" : 26,
"session dhandles swept" : 0,
"session sweep attempts" : 18 },
"lock" : { "checkpoint lock acquisitions" : 5,
"checkpoint lock application thread wait time (usecs)" : 0,
"checkpoint lock internal thread wait time (usecs)" : 0,
"handle-list lock acquisitions" : 95,
"handle-list lock application thread wait time (usecs)" : 0,
"handle-list lock internal thread wait time (usecs)" : 0,
"metadata lock acquisitions" : 4,
"metadata lock application thread wait time (usecs)" : 0,
"metadata lock internal thread wait time (usecs)" : 0,
"schema lock acquisitions" : 22,
"schema lock application thread wait time (usecs)" : 0,
"schema lock internal thread wait time (usecs)" : 0,
"table lock acquisitions" : 21,
"table lock application thread time waiting for the table lock (usecs)" : 0,
"table lock internal thread time waiting for the table lock (usecs)" : 0 },
"log" : { "busy returns attempting to switch slots" : 0,
"consolidated slot closures" : 9,
"consolidated slot join races" : 0,
"consolidated slot join transitions" : 9,
"consolidated slot joins" : 11,
"consolidated slot unbuffered writes" : 0,
"log bytes of payload data" : 3852,
"log bytes written" : 5120,
"log files manually zero-filled" : 0,
"log flush operations" : 2665,
"log force write operations" : 2951,
"log force write operations skipped" : 2947,
"log records compressed" : 5,
"log records not compressed" : 0,
"log records too small to compress" : 6,
"log release advances write LSN" : 5,
"log scan operations" : 3,
"log scan records requiring two reads" : 4,
"log server thread advances write LSN" : 4,
"log server thread write LSN walk skipped" : 1265,
"log sync operations" : 9,
"log sync time duration (usecs)" : 850044,
"log sync_dir operations" : 1,
"log sync_dir time duration (usecs)" : 0,
"log write operations" : 11,
"logging bytes consolidated" : 4736,
"maximum log file size" : 104857600,
"number of pre-allocated log files to create" : 2,
"pre-allocated log files not ready and missed" : 1,
"pre-allocated log files prepared" : 2,
"pre-allocated log files used" : 0,
"records processed by log scan" : 10,
"total in-memory size of compressed records" : 5917,
"total log buffer size" : 33554432,
"total size of compressed records" : 3705,
"written slots coalesced" : 0,
"yields waiting for previous log file close" : 0 },
"reconciliation" : { "fast-path pages deleted" : 0,
"page reconciliation calls" : 13,
"page reconciliation calls for eviction" : 0,
"pages deleted" : 0,
"split bytes currently awaiting free" : 0,
"split objects currently awaiting free" : 0 },
"session" : { "open cursor count" : 31,
"open session count" : 16,
"table compact failed calls" : 0,
"table compact successful calls" : 0,
"table create failed calls" : 0,
"table create successful calls" : 1,
"table drop failed calls" : 0,
"table drop successful calls" : 0,
"table rebalance failed calls" : 0,
"table rebalance successful calls" : 0,
"table rename failed calls" : 0,
"table rename successful calls" : 0,
"table salvage failed calls" : 0,
"table salvage successful calls" : 0,
"table truncate failed calls" : 0,
"table truncate successful calls" : 0,
"table verify failed calls" : 0,
"table verify successful calls" : 0 },
"thread-state" : { "active filesystem fsync calls" : 0,
"active filesystem read calls" : 0,
"active filesystem write calls" : 0 },
"thread-yield" : { "application thread time evicting (usecs)" : 0,
"application thread time waiting for cache (usecs)" : 0,
"page acquire busy blocked" : 0,
"page acquire eviction blocked" : 0,
"page acquire locked blocked" : 0,
"page acquire read blocked" : 0,
"page acquire time sleeping (usecs)" : 0 },
"transaction" : { "number of named snapshots created" : 0,
"number of named snapshots dropped" : 0,
"transaction begins" : 18,
"transaction checkpoint currently running" : 0,
"transaction checkpoint generation" : 4,
"transaction checkpoint max time (msecs)" : 960,
"transaction checkpoint min time (msecs)" : 178,
"transaction checkpoint most recent time (msecs)" : 178,
"transaction checkpoint scrub dirty target" : 0,
"transaction checkpoint scrub time (msecs)" : 0,
"transaction checkpoint total time (msecs)" : 1794,
"transaction checkpoints" : 4,
"transaction checkpoints skipped because database was clean" : 1,
"transaction failures due to cache overflow" : 0,
"transaction fsync calls for checkpoint after allocating the transaction ID" : 4,
"transaction fsync duration for checkpoint after allocating the transaction ID (usecs)" : 0,
"transaction range of IDs currently pinned" : 0,
"transaction range of IDs currently pinned by a checkpoint" : 0,
"transaction range of IDs currently pinned by named snapshots" : 0,
"transaction sync calls" : 0,
"transactions committed" : 4,
"transactions rolled back" : 14 },
"concurrentTransactions" : { "write" : { "out" : 0,
"available" : 128,
"totalTickets" : 128 },
"read" : { "out" : 0,
"available" : 128,
"totalTickets" : 128 } } },
"writeBacksQueued" : false,
"mem" : { "bits" : 64,
"resident" : 46,
"virtual" : 166,
"supported" : true,
"mapped" : 0,
"mappedWithJournal" : 0 },
"metrics" : { "commands" : { "<UNKNOWN>" : { "$numberLong" : "0" },
"_getUserCacheGeneration" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"_isSelf" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"_mergeAuthzCollections" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"_migrateClone" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"_recvChunkAbort" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"_recvChunkCommit" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"_recvChunkStart" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"_recvChunkStatus" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"_transferMods" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"aggregate" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"appendOplogNote" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"applyOps" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"authSchemaUpgrade" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"authenticate" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"availableQueryOptions" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"buildInfo" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "1" } },
"checkShardingIndex" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"cleanupOrphaned" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"clone" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"cloneCollection" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"cloneCollectionAsCapped" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"collMod" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"collStats" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"compact" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"connPoolStats" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"connPoolSync" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"connectionStatus" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"convertToCapped" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"copydb" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"copydbgetnonce" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"copydbsaslstart" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"count" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"create" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"createIndexes" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"createRole" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"createUser" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"currentOp" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"currentOpCtx" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"dataSize" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"dbHash" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"dbStats" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"delete" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"diagLogging" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"distinct" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"driverOIDTest" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"drop" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"dropAllRolesFromDatabase" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"dropAllUsersFromDatabase" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"dropDatabase" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"dropIndexes" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"dropRole" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"dropUser" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"eval" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"explain" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"features" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"filemd5" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"find" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"findAndModify" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"forceerror" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"fsync" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"fsyncUnlock" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"geoNear" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"geoSearch" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"getCmdLineOpts" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"getLastError" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"getLog" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "1" } },
"getMore" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"getParameter" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"getPrevError" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"getShardMap" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"getShardVersion" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"getnonce" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"grantPrivilegesToRole" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"grantRolesToRole" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"grantRolesToUser" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"group" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"handshake" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"hostInfo" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"insert" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"invalidateUserCache" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"isMaster" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "4" } },
"killCursors" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"killOp" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"listCollections" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "1" } },
"listCommands" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"listDatabases" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"listIndexes" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"logRotate" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"logout" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"mapReduce" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"mapreduce" : { "shardedfinish" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } } },
"mergeChunks" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"moveChunk" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"parallelCollectionScan" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"ping" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"planCacheClear" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"planCacheClearFilters" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"planCacheListFilters" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"planCacheListPlans" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"planCacheListQueryShapes" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"planCacheSetFilter" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"profile" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"reIndex" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"renameCollection" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"repairCursor" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"repairDatabase" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"replSetDeclareElectionWinner" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"replSetElect" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"replSetFreeze" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"replSetFresh" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"replSetGetConfig" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"replSetGetRBID" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"replSetGetStatus" : { "failed" : { "$numberLong" : "1" },
"total" : { "$numberLong" : "1" } },
"replSetHeartbeat" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"replSetInitiate" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"replSetMaintenance" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"replSetReconfig" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"replSetRequestVotes" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"replSetStepDown" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"replSetSyncFrom" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"replSetUpdatePosition" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"resetError" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"resync" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"revokePrivilegesFromRole" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"revokeRolesFromRole" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"revokeRolesFromUser" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"rolesInfo" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"saslContinue" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"saslStart" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"serverStatus" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "2" } },
"setParameter" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"setShardVersion" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"shardConnPoolStats" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"shardingState" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"shutdown" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"splitChunk" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"splitVector" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"top" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"touch" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"unsetSharding" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"update" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"updateRole" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"updateUser" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"usersInfo" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"validate" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } },
"whatsmyuri" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "1" } },
"writebacklisten" : { "failed" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } } },
"cursor" : { "timedOut" : { "$numberLong" : "0" },
"open" : { "noTimeout" : { "$numberLong" : "0" },
"pinned" : { "$numberLong" : "0" },
"total" : { "$numberLong" : "0" } } },
"document" : { "deleted" : { "$numberLong" : "0" },
"inserted" : { "$numberLong" : "0" },
"returned" : { "$numberLong" : "0" },
"updated" : { "$numberLong" : "0" } },
"getLastError" : { "wtime" : { "num" : 0,
"totalMillis" : 0 },
"wtimeouts" : { "$numberLong" : "0" } },
"operation" : { "fastmod" : { "$numberLong" : "0" },
"idhack" : { "$numberLong" : "0" },
"scanAndOrder" : { "$numberLong" : "0" },
"writeConflicts" : { "$numberLong" : "0" } },
"queryExecutor" : { "scanned" : { "$numberLong" : "0" },
"scannedObjects" : { "$numberLong" : "0" } },
"record" : { "moves" : { "$numberLong" : "0" } },
"repl" : { "executor" : { "counters" : { "eventCreated" : 0,
"eventWait" : 0,
"cancels" : 0,
"waits" : 0,
"scheduledNetCmd" : 0,
"scheduledDBWork" : 0,
"scheduledXclWork" : 0,
"scheduledWorkAt" : 0,
"scheduledWork" : 0,
"schedulingFailures" : 0 },
"queues" : { "networkInProgress" : 0,
"dbWorkInProgress" : 0,
"exclusiveInProgress" : 0,
"sleepers" : 0,
"ready" : 0,
"free" : 0 },
"unsignaledEvents" : 0,
"eventWaiters" : 0,
"shuttingDown" : false,
"networkInterface" : "NetworkInterfaceASIO inShutdown: 0" },
"apply" : { "attemptsToBecomeSecondary" : { "$numberLong" : "0" },
"batches" : { "num" : 0,
"totalMillis" : 0 },
"ops" : { "$numberLong" : "0" } },
"buffer" : { "count" : { "$numberLong" : "0" },
"maxSizeBytes" : 268435456,
"sizeBytes" : { "$numberLong" : "0" } },
"network" : { "bytes" : { "$numberLong" : "0" },
"getmores" : { "num" : 0,
"totalMillis" : 0 },
"ops" : { "$numberLong" : "0" },
"readersCreated" : { "$numberLong" : "0" } },
"preload" : { "docs" : { "num" : 0,
"totalMillis" : 0 },
"indexes" : { "num" : 0,
"totalMillis" : 0 } } },
"storage" : { "freelist" : { "search" : { "bucketExhausted" : { "$numberLong" : "0" },
"requests" : { "$numberLong" : "0" },
"scanned" : { "$numberLong" : "0" } } } },
"ttl" : { "deletedDocuments" : { "$numberLong" : "0" },
"passes" : { "$numberLong" : "4" } } },
"ok" : 1 }
#通过mongostat查看服务器重要信息
C:\Users\Administrator>mongostat
insert query update delete getmore command% dirty % used flushes vsize res qr|qwar|aw netIn netOut conn time
*0 *0 *0 *0 0 1|0 0.0 0.0 0 166M 46.0M 0|0 0|0 79b 21.1k 2 2017-01-12T15:20:58+08:00
*0 *0 *0 *0 0 1|0 0.0 0.0 0 166M 46.0M 0|0 0|0 79b 21.1k 2 2017-01-12T15:20:59+08:00
*0 *0 *0 *0 0 1|0 0.0 0.0 0 166M 46.0M 0|0 0|0 79b 21.1k 2 2017-01-12T15:21:00+08:00
*0 *0 *0 *0 0 1|0 0.0 0.0 0 166M 46.0M 0|0 0|0 79b 21.1k 2 2017-01-12T15:21:01+08:00
*0 *0 *0 *0 0 1|0 0.0 0.0 0 166M 46.0M 0|0 0|0 79b 21.1k 2 2017-01-12T15:21:02+08:00
*0 *0 *0 *0 0 1|0 0.0 0.0 0 166M 46.0M 0|0 0|0 79b 21.1k 2 2017-01-12T15:21:03+08:00
*0 *0 *0 *0 0 1|0 0.0 0.0 0 166M 46.0M 0|0 0|0 79b 21.1k 2 2017-01-12T15:21:04+08:00
*0 *0 *0 *0 0 2|0 0.0 0.0 0 166M 46.0M 0|0 0|0 133b 21.2k 2 2017-01-12T15:21:05+08:00
*0 *0 *0 *0 0 1|0 0.0 0.0 0 166M 46.0M 0|0 0|0 79b 21.1k 2 2017-01-12T15:21:06+08:00
也可以通过第三方插件监控跟踪服务器的运行情况
Nagios
Munin
Ganglia
Cacti
三安全和认证
Mongodb的用户和权限设置
1 首先在没有添加--auth权限参数时启动服务
C:\Users\Administrator>mongod --dbpathh:\MongoDB\data --logpath=h:\MongoDB\logs\mongodb.log
这时不用指定用户就可以连接数据库
#切换数据库
> use admin
switched to db admin
#查看当前数据库
> db
Admin
#创建用户
Successfully added user: {
"user" : "admin",
"customData" : {
"description" :"superuser"
},
"roles" : [
{
"role" :"userAdminAnyDatabase",
"db" :"admin"
}
]
}
#显示数据库列表
> show dbs
admin 0.000GB
local 0.000GB
test 0.001GB
updates 0.000GB
#显示用户
> show users
{
"_id" : "admin.admin",
"user" : "admin",
"db" : "admin",
"customData" : {
"description" :"superuser"
},
"roles" : [
{
"role" :"userAdminAnyDatabase",
"db" :"admin"
}
]
}
#同上
> db.system.users.find()
{ "_id" :"admin.admin", "user" : "admin", "db" :"admin", "credentials" : { "SCRAM-SHA-1" : {"iterationCount" : 10000, "salt" : "OI2v0YoaArYWok8S7N0
7rw==", "storedKey" :"u03emmw4yR6u20AadMeObnDdPJ8=", "serverKey" :"NWQUz7VBHsrnrOgVXVdNBKw/9ps=" } }, "customData" : {"description" : "superuser" }
, "roles" : [ { "role": "userAdminAnyDatabase", "db" : "admin" } ] }
>
重启数据库,开启用户验证
C:\Users\Administrator>mongod --dbpathh:\MongoDB\data --httpinterface --rest --auth
内建角色
数据库用户角色 read readwrite
数据库管理角色 dbAdmin dbOwner userAdmin
集群管理角色 clusterAdmin clusterManager clusterMonitor hostManager
备份恢复角色 backup restore
所有数据库角色 readAnyDatabase
readWriteAnyDatabase
userAdminAnyDatabase
dbAdminAnyDatabase
超级用户角色 root
内部角色 __system