mongo服务器管理

如果未提供服务器配置文件,mongodb使用默认的数据库路径/data/db启动,并使用默认端口27017(mongodb)和28017(管理界面)连接到所有的网络IP

重新配置服务器

mongoDB提供3中方式用于配置服务

  1. 结合mongod守护进程,使用命令行选项。
  2. 使用setParameter修改设置
  3. 加载一个配置文件
    一般打包的安装包都是用加载一个配置文件,Unix/Linux该配置文件通常位于/etc/mongod.conf
systemLog:
  destination: file
  logAppend: true 
  #设置为false,mongodb每次启动都会清空日志,设置为true,所有日志都追加到现有日志后面。
  path: /var/log/mongodb/mongod.log

storage:
  dbPath: /var/lib/mongo#数据存储路径,
  journal:
    enabled: true

processManagement:
  fork: true  # fork and run in background
  pidFilePath: /var/run/mongodb/mongod.pid  # location of pidfile

net:
  port: 27017
  bindIp: 127.0.0.1  # Listen to local interface only, comment to listen on all interfaces.

security:
   authorization: enabled#开启安全认证

#replication:
   #replSetName: set0

Or, if using the older .ini configuration file format:

fork = true
bind_ip = 127.0.0.1
port = 27017
quiet = true
dbpath = /srv/mongodb
logpath = /var/log/mongodb/mongod.log
logappend = true
journal = true
#replSet = set0

使用配置文件启动mongodb

mongod --config /etc/mongod.conf

or

mongod -f /etc/mongod.conf

服务器版本

> use admin
switched to db admin
> db.version()
3.4.1

服务器状态

db.serverStatus()

> db.serverStatus()
{
    "host" : "mongo",
    "version" : "3.4.1",
    "process" : "mongod",
    "pid" : NumberLong(1215),
    "uptime" : 2114,
    "uptimeMillis" : NumberLong(2114105),
    "uptimeEstimate" : NumberLong(2114),
    "localTime" : ISODate("2016-12-27T02:16:39.389Z"),
    "asserts" : {
        "regular" : 0,
        "warning" : 0,
        "msg" : 0,
        "user" : 0,
        "rollovers" : 0
    },
    "connections" : {
        "current" : 1,
        "available" : 51199,
        "totalCreated" : 4
    },
    "extra_info" : {
        "note" : "fields vary by platform",
        "page_faults" : 22
    },
    "globalLock" : {
        "totalTime" : NumberLong(2114038000),
        "currentQueue" : {
            "total" : 0,
            "readers" : 0,
            "writers" : 0
        },
        "activeClients" : {
            "total" : 7,
            "readers" : 0,
            "writers" : 0
        }
    },
    "locks" : {
        "Global" : {
            "acquireCount" : {
                "r" : NumberLong(2145),
                "w" : NumberLong(4),
                "W" : NumberLong(5)
            }
        },
        "Database" : {
            "acquireCount" : {
                "r" : NumberLong(1065),
                "R" : NumberLong(2),
                "W" : NumberLong(4)
            }
        },
        "Collection" : {
            "acquireCount" : {
                "r" : NumberLong(1063)
            }
        },
        "Metadata" : {
            "acquireCount" : {
                "w" : NumberLong(1)
            }
        }
    },
    "network" : {
        "bytesIn" : NumberLong(8151),
        "bytesOut" : NumberLong(162359),
        "physicalBytesIn" : NumberLong(8151),
        "physicalBytesOut" : NumberLong(162359),
        "numRequests" : NumberLong(193)
    },
    "opLatencies" : {
        "reads" : {
            "latency" : NumberLong(0),
            "ops" : NumberLong(0)
        },
        "writes" : {
            "latency" : NumberLong(0),
            "ops" : NumberLong(0)
        },
        "commands" : {
            "latency" : NumberLong(5235),
            "ops" : NumberLong(96)
        }
    },
    "opcounters" : {
        "insert" : 0,
        "query" : 1,
        "update" : 0,
        "delete" : 0,
        "getmore" : 0,
        "command" : 97
    },
    "opcountersRepl" : {
        "insert" : 0,
        "query" : 0,
        "update" : 0,
        "delete" : 0,
        "getmore" : 0,
        "command" : 0
    },
    "storageEngine" : {
        "name" : "wiredTiger",
        "supportsCommittedReads" : true,
        "readOnly" : false,
        "persistent" : true
    },
    "tcmalloc" : {
        "generic" : {
            "current_allocated_bytes" : 60971512,
            "heap_size" : 64802816
        },
        "tcmalloc" : {
            "pageheap_free_bytes" : 2764800,
            "pageheap_unmapped_bytes" : 0,
            "max_total_thread_cache_bytes" : 127926272,
            "current_total_thread_cache_bytes" : 538352,
            "total_free_bytes" : 1066504,
            "central_cache_free_bytes" : 210840,
            "transfer_cache_free_bytes" : 317312,
            "thread_cache_free_bytes" : 538352,
            "aggressive_memory_decommit" : 0,
            "formattedString" : "------------------------------------------------\nMALLOC:       60971512 (   58.1 MiB) Bytes in use by application\nMALLOC: +      2764800 (    2.6 MiB) Bytes in page heap freelist\nMALLOC: +       210840 (    0.2 MiB) Bytes in central cache freelist\nMALLOC: +       317312 (    0.3 MiB) Bytes in transfer cache freelist\nMALLOC: +       538352 (    0.5 MiB) Bytes in thread cache freelists\nMALLOC: +      1302720 (    1.2 MiB) Bytes in malloc metadata\nMALLOC:   ------------\nMALLOC: =     66105536 (   63.0 MiB) Actual memory used (physical + swap)\nMALLOC: +            0 (    0.0 MiB) Bytes released to OS (aka unmapped)\nMALLOC:   ------------\nMALLOC: =     66105536 (   63.0 MiB) Virtual address space used\nMALLOC:\nMALLOC:            471              Spans in use\nMALLOC:             12              Thread heaps in use\nMALLOC:           4096              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" : 0,
            "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" : 7,
            "blocks read" : 24,
            "blocks written" : 24,
            "bytes read" : 106496,
            "bytes written" : 122880,
            "bytes written for checkpoint" : 122880,
            "mapped blocks read" : 0,
            "mapped bytes read" : 0
        },
        "cache" : {
            "application threads page read from disk to cache count" : 6,
            "application threads page read from disk to cache time (usecs)" : 3331,
            "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" : 16293,
            "bytes currently in the cache" : 62347,
            "bytes not belonging to page images in the cache" : 46053,
            "bytes read into cache" : 15087,
            "bytes written from cache" : 34783,
            "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" : 268435456,
            "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" : 15,
            "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" : 14,
            "pages read into cache requiring lookaside entries" : 0,
            "pages requested from the cache" : 145,
            "pages seen by eviction walk" : 0,
            "pages selected for eviction unable to be evicted" : 0,
            "pages walked for eviction" : 0,
            "pages written from cache" : 12,
            "pages written requiring in-memory restoration" : 0,
            "percentage overhead" : 8,
            "tracked bytes belonging to internal pages in the cache" : 18274,
            "tracked bytes belonging to leaf pages in the cache" : 44073,
            "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" : 6373,
            "files currently open" : 11,
            "memory allocations" : 33031,
            "memory frees" : 32354,
            "memory re-allocations" : 6445,
            "pthread mutex condition wait calls" : 27620,
            "pthread mutex shared lock read-lock calls" : 4315,
            "pthread mutex shared lock write-lock calls" : 2169,
            "total fsync I/Os" : 30,
            "total read I/Os" : 461,
            "total write I/Os" : 38
        },
        "cursor" : {
            "cursor create calls" : 34,
            "cursor insert calls" : 12,
            "cursor next calls" : 45,
            "cursor prev calls" : 4,
            "cursor remove calls" : 1,
            "cursor reset calls" : 133,
            "cursor restarted searches" : 0,
            "cursor search calls" : 140,
            "cursor search near calls" : 1,
            "cursor update calls" : 0,
            "truncate calls" : 0
        },
        "data-handle" : {
            "connection data handles currently active" : 8,
            "connection sweep candidate became referenced" : 0,
            "connection sweep dhandles closed" : 0,
            "connection sweep dhandles removed from hash list" : 12,
            "connection sweep time-of-death sets" : 12,
            "connection sweeps" : 211,
            "session dhandles swept" : 0,
            "session sweep attempts" : 16
        },
        "lock" : {
            "checkpoint lock acquisitions" : 4,
            "checkpoint lock application thread wait time (usecs)" : 0,
            "checkpoint lock internal thread wait time (usecs)" : 0,
            "handle-list lock acquisitions" : 47,
            "handle-list lock application thread wait time (usecs)" : 3332,
            "handle-list lock internal thread wait time (usecs)" : 0,
            "metadata lock acquisitions" : 3,
            "metadata lock application thread wait time (usecs)" : 0,
            "metadata lock internal thread wait time (usecs)" : 0,
            "schema lock acquisitions" : 12,
            "schema lock application thread wait time (usecs)" : 0,
            "schema lock internal thread wait time (usecs)" : 0,
            "table lock acquisitions" : 11,
            "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" : 7,
            "consolidated slot join races" : 0,
            "consolidated slot join transitions" : 7,
            "consolidated slot joins" : 10,
            "consolidated slot unbuffered writes" : 0,
            "log bytes of payload data" : 3324,
            "log bytes written" : 4608,
            "log files manually zero-filled" : 0,
            "log flush operations" : 20997,
            "log force write operations" : 23129,
            "log force write operations skipped" : 23127,
            "log records compressed" : 4,
            "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" : 3,
            "log server thread advances write LSN" : 2,
            "log server thread write LSN walk skipped" : 3110,
            "log sync operations" : 7,
            "log sync time duration (usecs)" : 4897,
            "log sync_dir operations" : 1,
            "log sync_dir time duration (usecs)" : 1,
            "log write operations" : 10,
            "logging bytes consolidated" : 4224,
            "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" : 9,
            "total in-memory size of compressed records" : 5532,
            "total log buffer size" : 33554432,
            "total size of compressed records" : 3180,
            "written slots coalesced" : 0,
            "yields waiting for previous log file close" : 0
        },
        "reconciliation" : {
            "fast-path pages deleted" : 0,
            "page reconciliation calls" : 12,
            "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" : 24,
            "open session count" : 16,
            "table compact failed calls" : 0,
            "table compact successful calls" : 0,
            "table create failed calls" : 0,
            "table create successful calls" : 0,
            "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" : 8,
            "transaction checkpoint currently running" : 0,
            "transaction checkpoint generation" : 3,
            "transaction checkpoint max time (msecs)" : 6,
            "transaction checkpoint min time (msecs)" : 1,
            "transaction checkpoint most recent time (msecs)" : 1,
            "transaction checkpoint scrub dirty target" : 0,
            "transaction checkpoint scrub time (msecs)" : 0,
            "transaction checkpoint total time (msecs)" : 10,
            "transaction checkpoints" : 3,
            "transaction checkpoints skipped because database was clean" : 33,
            "transaction failures due to cache overflow" : 0,
            "transaction fsync calls for checkpoint after allocating the transaction ID" : 3,
            "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" : 2,
            "transactions rolled back" : 6
        },
        "concurrentTransactions" : {
            "write" : {
                "out" : 0,
                "available" : 128,
                "totalTickets" : 128
            },
            "read" : {
                "out" : 0,
                "available" : 128,
                "totalTickets" : 128
            }
        }
    },
    "mem" : {
        "bits" : 64,
        "resident" : 43,
        "virtual" : 290,
        "supported" : true,
        "mapped" : 0,
        "mappedWithJournal" : 0
    },
    "metrics" : {
        "commands" : {
            "buildInfo" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(8)
            },
            "getLog" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(4)
            },
            "isMaster" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(69)
            },
            "listDatabases" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(1)
            },
            "replSetGetStatus" : {
                "failed" : NumberLong(4),
                "total" : NumberLong(4)
            },
            "serverStatus" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(7)
            },
            "whatsmyuri" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(4)
            }
        },
        "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" : {
            "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" : "\nNetworkInterfaceASIO Operations' Diagnostic:\nOperation:    Count:   \nConnecting    0        \nIn Progress   0        \nSucceeded     0        \nCanceled      0        \nFailed        0        \nTimed Out     0        \n\n"
            },
            "apply" : {
                "attemptsToBecomeSecondary" : NumberLong(0),
                "batches" : {
                    "num" : 0,
                    "totalMillis" : 0
                },
                "ops" : NumberLong(0)
            },
            "buffer" : {
                "count" : NumberLong(0),
                "maxSizeBytes" : NumberLong(0),
                "sizeBytes" : NumberLong(0)
            },
            "initialSync" : {
                "completed" : NumberLong(0),
                "failedAttempts" : NumberLong(0),
                "failures" : 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(35)
        }
    },
    "ok" : 1
}

在输出的信息中,可以找到两个最重要的部分:opcounters和asserts。

  1. opcounters:显示了服务器上已经执行的每种类型的操作数目。对于特定的服务器,计数器的正常值应该在一定范围。
  2. asserts:显示服务器与客户端抛出异常或警告的数目。如果异常数目迅速增加,应该查看服务器的日志文件以检查服务器是否异常。

关闭服务器

sudo service mongod stop

或者从mongo控制台关闭服务器

use admin
switched to db admin
> db.shutdownServer()
server should be down...
2016-12-27T10:27:58.305+0800 I NETWORK  [main] trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2016-12-27T10:27:58.308+0800 W NETWORK  [main] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2016-12-27T10:27:58.308+0800 I NETWORK  [main] reconnect 127.0.0.1:27017 (127.0.0.1) failed failed

猜你喜欢

转载自blog.csdn.net/uevol14/article/details/53887881