Skip to content

Server Administration βš™οΈ

Lyes S edited this page Jun 19, 2022 · 6 revisions

Table Of Contents

Default MongoDB config file

lyes-s ( β—₯β—£_β—’β—€ ) ~/Documents/learning-mongo $ docker exec -it mongodb sh

> cat /etc/mongod.conf.orig

# mongod.conf

# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
#  engine:
#  wiredTiger:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1


# how the process runs
processManagement:
  timeZoneInfo: /usr/share/zoneinfo

#security:

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options:

#auditLog:

#snmp:

Directory Per DB

When true, MongoDB uses a separate directory to store data for each database. The directories are under the storage.dbPath directory, and each subdirectory name corresponds to the database name.

The storage.directoryPerDB setting is available only for mongod.

# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
  directoryPerDB: true

Max Incoming Connections

The maximum number of simultaneous connections that mongos or mongod will accept. This setting has no effect if it is higher than your operating system's configured maximum connection tracking threshold. Default : 65536

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1
  maxIncomingConnections: 65536

Process Management

Fork

Enable a daemon mode that runs the mongos or mongod process in the background. By default mongos or mongod does not run as a daemon: typically you will run mongos or mongod as a daemon, either by using processManagement.fork or by using a controlling process that handles the daemonization process (e.g. as with upstart and systemd). Default : false

# how the process runs
processManagement:
  fork: true
  timeZoneInfo: /usr/share/zoneinfo

Replication

Replica Sets

A replica set is a group of MongoDB servers, called nodes, containing an identical copy of the data. If one of the servers fails, the other two will pick up the load while the crashed one restarts. [1]

More Information : [2]

# Replica
replication:
  replSetName: cookerSet

Sharding

Sharding is a method for distributing data across multiple machines. MongoDB uses sharding to support deployments with very large data sets and high throughput operations. MongoDB supports horizontal scaling through sharding. [3]

More Information [4]

sharding:
  clusterRole: configsvr

Backups

fsyncLock

Forces the mongod to flush all pending write operations to disk and locks the entire mongod instance to prevent additional writes until the user releases the lock with a corresponding db.fsyncUnlock() command.

lyes-s ( β—₯β—£_β—’β—€ ) ~/Documents/learning-mongo $ docker exec -i mongodb sh -c 'mongosh --authenticationDatabase admin -u root --eval "printjson(db.fsyncLock())" '
Enter password: example
*******
Current Mongosh Log ID: 62af612421f98828d8ab85e8
Connecting to:          mongodb://<credentials>@127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&authSource=admin&appName=mongosh+1.5.0
Using MongoDB:          5.0.9
Using Mongosh:          1.5.0

For mongosh info see: https://docs.mongodb.com/mongodb-shell/

------
   The server generated these startup warnings when booting
   2022-06-19T15:57:19.878+00:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem
   2022-06-19T15:57:20.189+00:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
------

------
   Enable MongoDB's free cloud-based monitoring service, which will then receive and display
   metrics about your deployment (disk utilization, CPU, operation statistics, etc).

   The monitoring data will be available on a MongoDB website with a unique URL accessible to you
   and anyone you share the URL with. MongoDB may use this information to make product
   improvements and to suggest MongoDB products and deployment options to you.

   To enable free monitoring, run the following command: db.enableFreeMonitoring()
   To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
------

{
  info: 'now locked against writes, use db.fsyncUnlock() to unlock',
  lockCount: Long("2"),
  seeAlso: 'http://dochub.mongodb.org/core/fsynccommand',
  ok: 1
}

Mongo Dump

// Dump 
lyes-s ( β—₯β—£_β—’β—€ ) ~/Documents/learning-mongo/backup $ docker exec -i mongodb sh -c 'mongodump --authenticationDatabase admin -u root --db cooker --out /backup'
2022-06-19T17:20:55.635+0000    reading password from standard input
Enter password:******

2022-06-19T17:21:01.552+0000    writing cooker.users to /backup/cooker/users.bson
2022-06-19T17:21:01.553+0000    done dumping cooker.users (2 documents)
2022-06-19T17:21:01.554+0000    writing cooker.recipes to /backup/cooker/recipes.bson
2022-06-19T17:21:01.555+0000    done dumping cooker.recipes (7 documents)

Copy Backup

// Copy to Local
lyes-s ( β—₯β—£_β—’β—€ ) ~/Documents/learning-mongo $ docker cp mongodb:/backup .

// Verify
lyes-s ( β—₯β—£_β—’β—€ ) ~/Documents/learning-mongo $ ll -la backup/cooker/
total 15
drwxr-xr-x 1 lyess 197609    0 Jun 19 13:08 ./
drwxr-xr-x 1 lyess 197609    0 Jun 19 13:08 ../
-rw-r--r-- 1 lyess 197609 7526 Jun 19 13:08 recipes.bson
-rw-r--r-- 1 lyess 197609  174 Jun 19 13:08 recipes.metadata.json
-rw-r--r-- 1 lyess 197609  322 Jun 19 13:08 users.bson
-rw-r--r-- 1 lyess 197609  172 Jun 19 13:08 users.metadata.json

fsyncUnlock

Reduces the lock taken by db.fsyncLock() on a mongod instance by 1.

lyes-s ( β—₯β—£_β—’β—€ ) ~/Documents/learning-mongo $ docker exec -i mongodb sh -c 'mongosh --authenticationDatabase admin -u root --eval "printjson(db.fsyncUnlock())" '
Enter password: *******

Current Mongosh Log ID: 62af6f481544a9cf01e25103
Connecting to:          mongodb://<credentials>@127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&authSource=admin&appName=mongosh+1.5.0
Using MongoDB:          5.0.9
Using Mongosh:          1.5.0

For mongosh info see: https://docs.mongodb.com/mongodb-shell/

------
   The server generated these startup warnings when booting
   2022-06-19T18:35:44.597+00:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem
   2022-06-19T18:35:44.901+00:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
------

------
   Enable MongoDB's free cloud-based monitoring service, which will then receive and display
   metrics about your deployment (disk utilization, CPU, operation statistics, etc).

   The monitoring data will be available on a MongoDB website with a unique URL accessible to you
   and anyone you share the URL with. MongoDB may use this information to make product
   improvements and to suggest MongoDB products and deployment options to you.

   To enable free monitoring, run the following command: db.enableFreeMonitoring()
   To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
------

{ info: 'fsyncUnlock completed', lockCount: Long("0"), ok: 1 }

Mongo Restore

lyes-s ( β—₯β—£_β—’β—€ ) ~/Documents/learning-mongo $ docker exec -i mongodb sh -c 'mongorestore --authenticationDatabase admin -u root --drop --nsInclude cooker.* /dump'
2022-06-19T18:42:07.278+0000    reading password from standard input
Enter password:*****

2022-06-19T18:42:10.120+0000    preparing collections to restore from
2022-06-19T18:42:10.121+0000    reading metadata for cooker.recipes from /dump/cooker/recipes.metadata.json
2022-06-19T18:42:10.121+0000    reading metadata for cooker.users from /dump/cooker/users.metadata.json
2022-06-19T18:42:10.121+0000    dropping collection cooker.recipes before restoring
2022-06-19T18:42:10.121+0000    dropping collection cooker.users before restoring
2022-06-19T18:42:10.140+0000    restoring cooker.recipes from /dump/cooker/recipes.bson
2022-06-19T18:42:10.146+0000    restoring cooker.users from /dump/cooker/users.bson
2022-06-19T18:42:10.152+0000    finished restoring cooker.recipes (7 documents, 0 failures)
2022-06-19T18:42:10.158+0000    finished restoring cooker.users (2 documents, 0 failures)
2022-06-19T18:42:10.158+0000    no indexes to restore for collection cooker.recipes
2022-06-19T18:42:10.158+0000    no indexes to restore for collection cooker.users
2022-06-19T18:42:10.158+0000    9 document(s) restored successfully. 0 document(s) failed to restore.
Clone this wiki locally