Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Server Administration

Starting up options
• --dbpath
• The db directory path
• Each mongod process requires its own dbpath
• When mongod starts up, it creates a mongod.lock file in its data directory,
which prevents any other mongod process from using that directory.
• --port
• Specify the port number for the server to listen on
• Default port number is 27017
• --fork
• On Unix-based systems, fork the server process, running MongoDB as a
daemon.
Starting up options
• --logpath
• The path for log
• On each restarts , mongodb renames the old log files and create a new one
• --logappend to append to the existing log file
• --directoryperdb
• Put each database in its own directory
• Helps in restoring only one database using file system backup and restore
• --config
• Use a configuration file for additional options not specified on the command line.
• This is typically used to make sure options are the same between restarts.
Starting up options
• MongoDB stores the startup log details in the collection ‘startup_log’ in the local database.
MongoDB Enterprise > db.startup_log.find().sort({startTime: -1}).limit(1).pretty()
{
"_id" : "mongoserver4-1617814227932",
"hostname" : "mongoserver4",
"startTime" : ISODate("2021-04-07T16:50:27Z"),
"startTimeLocal" : "Wed Apr 7 12:50:27.932",
"cmdLine" : {
"net" : {
"port" : 27017
},
"storage" : {
"dbPath" : "/u01/data",
"directoryPerDB" : true,
"journal" : {
"enabled" : true
}
},
"systemLog" : {
"destination" : "file",
"path" : "/u01/data/mongo.log"
}
},
"pid" : NumberLong(20106),
"buildinfo" : {
"version" : "4.4.4",
"gitVersion" : "8db30a63db1a9d84bdcad0c83369623f708e0397",
"modules" : [
"enterprise"
Starting up options
• MongoDB stores the startup log details in the collection ‘startup_log’ in the local database.
MongoDB Enterprise > db.startup_log.find().sort({startTime: -1}).limit(1).pretty()
{
"_id" : "mongoserver4-1617814227932",
"hostname" : "mongoserver4",
"startTime" : ISODate("2021-04-07T16:50:27Z"),
"startTimeLocal" : "Wed Apr 7 12:50:27.932",
"cmdLine" : {
"net" : {
"port" : 27017
},
"storage" : {
"dbPath" : "/u01/data",
"directoryPerDB" : true,
"journal" : {
"enabled" : true
}
},
"systemLog" : {
"destination" : "file",
"path" : "/u01/data/mongo.log"
}
},
"pid" : NumberLong(20106),
"buildinfo" : {
"version" : "4.4.4",
"gitVersion" : "8db30a63db1a9d84bdcad0c83369623f708e0397",
"modules" : [
"enterprise"
File Based Configuration
• MongoDB supports reading configuration information from a file.
• use the -f or --config flags.
• mongod --config /u01/data/mongod.conf
• The options in this file is specified in YAML format as in /etc/mongod.conf
• 4.2 supports another option --configExpand
• --configExpand , helps in providing addition information like passwords
Stopping MongoDB
• > db.shutdownServer()
• This command should be executed from the admin database.
• When run on a primary, the shutdown command steps down the primary and waits for
a secondary to catch up before shutting down the server.
• You can force the shutdown command to shut down a primary by using the force
option:
• > db.runCommad({shutdown:1})
Enable Logging
• By default, mongod sends its logs to stdout.
• --logpath can be used to send the output to a log file
• Possible log values range from 0 to 5
• 0 enabled minimal logging and that’s is the default
• 5 enabled extensive logging
• Log level should be set on admin database.
• Setting up log level
• > db.adminCommand({"setParameter" : 1, "logLevel" : 3})
• Getting the current log level
• > db.runCommand({getParameter: 1, logLevel: 1});
Setting profile level
• By default, MongoDB logs information about queries that take longer than
100 ms to run.
• We can change the threshold with setProfilingLevel
• > db.setProfilingLevel(1, 500)
• The above command set the slow query level to 500ms
• > db.setProfilingLevel(0)
• The above command disable the profiling
• Startup option --slowms also sets the threshold level for monitoring slow
queries.
Rotating Logs
• > db.adminCommand({"logRotate" : 1}).

You might also like