We looked at the very basics of starting and stopping MongoDB when we performed our Windows installation, but there are more details to be aware of when running MongoDB for real.
By default, MongoDB listens for client connections on port 27017, and stores data in the /data/db directory on Unix and on Windows \data\db on the drive from which you start MongoDB. To start MongoDB using all the defaults we simply run mongod from the command line.
To list the various options for use with the mongod process, we run
mongod --help
or
mongod -h
We can use the options listed to over-ride the defaults. Some common ones to use are:
--dbpath arg
Specifies an alternate location for the data directory
--bind_ip args
Specifies a comma-separated list of IP-addresses to listen for client connections
--port arg
Specifies an alternative port to listen for client connections
--logpath arg
Write all output from mongod to a file instead of the terminal. The directory path must exist but the file will be created by mongod.
--logappend
Keep previous log output instead of over-writing
--logRotate rename|reopen
Specifies the behavior to use when the logRotate command is issued. The default is rename, which archives the old log by appending a timestamp to it. If you want to take care of the archival yourself, for instance with the Linux/Unix logrotate utility, then use reopen and --logappend.
--syslog
Used on Unix systems to write the mongod output to the operating system log
--fork
Used on Unix systems to fork the mongod process and run it as a deamon. Must be run with a logpath
--journal
This will create a transaction log in a journal subdirectory in the data directory. All changes to MongoDB data will be recorded in the journal files here. Journaling is enabled by default on 64-bit installations. Journaling guarantees data integrity after a crash by replaying the writes from the journal files. The journal files are removed after a clean shutdown as they are no longer needed. Journaling is necessary for data persistency as changes are written in memory immediately but not to the datafiles on disk until the memory gets flushed.
--nojournal
Disables journaling on 64-bit systems
--journalCommitInterval arg
MongoDB commits changes in batches, writing to the journal every 100ms by default. This means you could lose 100ms of data in a crash. We can override this duration globally using journalCommitInterval as a startup option or a runtime configuration parameter. We can also use db.runCommand({"getLastError" : 1, "j" : true}) to wait 30ms for the previous write to be journaled.
--keyFile arg
Specifies a private key file for use in cluster authentication
--auth
Enforces secure logins
--noscripting
Disables the scripting engine on the server for improved security. Note that this can also break some shell helpers
--config arg
Specifes a configuration file containing additional startup options that were not specified on the command line. Format is described here
So we could start mongod to run as follows:
mongod --bind_ip 192.101.193.143 --port 27000 --dbpath "C:\mongodata\testdb" --logpath mongolog --journal
Or we could create config file (eg mongod.conf)containing
net:
bindIp: 192.101.193.143
port: 27000
storage:
dbPath: C:\mongodata\testdb
systemLog:
destination: file
path: C:\data\db\mongolog\mongod.log
logAppend: true
storage: journal:
enabled: true
and then run
mongod --config mongod.conf
to achieve the same thing
Nice blog and absolutely outstanding. You can do something much better but i still say this perfect.Keep trying for the best. Mongo Database Services
ReplyDelete
ReplyDeletethanks for your information visit us at MongoDB Training in Hyderabad
Thanks for sharing this blog post,Nice written skill core Java online training
ReplyDeleteThanks for sharing the useful bog about starting the MongoDB Server. Nicely explained.
ReplyDeleteCustom Web App Development Company in Coimbatore