MongoDB startup options, REST and HTTP admin interface

MongoDB has a built-in HTTP based admin interface and a REST based light weight operations interface which can be started with the MongoDB server start up.

When starting MongoDB, just specify the flags

The MongoDB server will start with a web server listening on 28017 (1000 greater than the native init port on which the MongoDB starts by default i.e. 27017)

mongodb –httpinterface –rest

D:\MongoDB3\bin>mongod –httpinterface –rest
2015-08-25T15:28:18.015+0530 I CONTROL  Hotfix KB2731284 or later update is installed, no need to zero-out data files
2015-08-25T15:28:18.033+0530 I JOURNAL  [initandlisten] journal dir=D:\data\db\journal
2015-08-25T15:28:18.034+0530 I JOURNAL  [initandlisten] recover : no journal files present, no recovery needed
2015-08-25T15:28:18.132+0530 I JOURNAL  [durability] Durability thread started
2015-08-25T15:28:18.134+0530 I JOURNAL  [journal writer] Journal writer thread started
2015-08-25T15:28:18.308+0530 I CONTROL  [initandlisten] MongoDB starting : pid=7380 port=27017 dbpath=D:\data\db\ 64-bit host=MYHOST
2015-08-25T15:28:18.309+0530 I CONTROL  [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2015-08-25T15:28:18.310+0530 I CONTROL  [initandlisten] db version v3.0.4
2015-08-25T15:28:18.312+0530 I CONTROL  [initandlisten] git version: 0481c958daeb2969800511e7475dc66986fa9ed5
2015-08-25T15:28:18.314+0530 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1m-fips 19 Mar 2015
2015-08-25T15:28:18.316+0530 I CONTROL  [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack=’Service Pack 1′) BOOST_LIB_VERSION=1
_49
2015-08-25T15:28:18.318+0530 I CONTROL  [initandlisten] allocator: tcmalloc
2015-08-25T15:28:18.320+0530 I CONTROL  [initandlisten] options: { net: { http: { RESTInterfaceEnabled: true, enabled: true } } }
2015-08-25T15:28:18.332+0530 I NETWORK  [websvr] admin web console waiting for connections on port 28017
2015-08-25T15:28:18.335+0530 I NETWORK  [initandlisten] waiting for connections on port 27017

Just point your browser to http://localhost:28017/ to see the admin console in action

Capture

#mongodb, #nosql

Installing MongoDB on Linux

MongoDB installation on Linux (Ubuntu 14.04 LTS here) consists of running the following commands:

  • sudo apt-key adv –keyserver hkp://keyserver.ubuntu.com:80 –recv 7F0CEB10   (Installing GPG Key)

Executing: gpg –ignore-time-conflict –no-options –no-default-keyring –homedir /tmp/tmp.KLub4f6ZtK –no-auto-check-trustdb –trust-model always –keyring /etc/apt/trusted.gpg –primary-keyring /etc/apt/trusted.gpg –keyserver hkp://keyserver.ubuntu.com:80 –recv 7F0CEB10
gpg: requesting key 7F0CEB10 from hkp server keyserver.ubuntu.com
gpg: key 7F0CEB10: “Richard Kreuter <richard@10gen.com>” not changed
gpg: Total number processed: 1
gpg:              unchanged: 1

  • echo ‘deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen’ | sudo tee /etc/apt/sources.list.d/mongodb.list

rahulsaini@rahulsaini-UBUNTU:~$ echo ‘deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen’ | sudo tee /etc/apt/sources.list.d/mongodb.list
deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen
rahulsaini@rahulsaini-UBUNTU:~$

  • sudo apt-get update

This sudo apt-get update command will update the package lists

To install a particular MongoDB version (here it is 2.6.1) run the command below

  • sudo apt-get install -y mongodb-org=2.6.1 mongodb-org-server=2.6.1 mongodb-org-shell=2.6.1 mongodb-org-mongos=2.6.1 mongodb-org-tools=2.6.1

Output will be something like this:

rahulsaini@rahulsaini-UBUNTU:~$ sudo apt-get install -y mongodb-org=2.6.1 mongodb-org-server=2.6.1 mongodb-org-shell=2.6.1 mongodb-org-mongos=2.6.1 mongodb-org-tools=2.6.1
Reading package lists… Done
Building dependency tree
Reading state information… Done

The following NEW packages will be installed:
mongodb-org mongodb-org-mongos mongodb-org-server mongodb-org-shell
mongodb-org-tools
0 upgraded, 5 newly installed, 0 to remove and 9 not upgraded.
Need to get 113 MB of archives.
After this operation, 284 MB of additional disk space will be used.
Get:1 http://downloads-distro.mongodb.org/repo/ubuntu-upstart/ dist/10gen mongodb-org-shell i386 2.6.1 [4,389 kB]
Get:2 http://downloads-distro.mongodb.org/repo/ubuntu-upstart/ dist/10gen mongodb-org-server i386 2.6.1 [9,308 kB]
Get:3 http://downloads-distro.mongodb.org/repo/ubuntu-upstart/ dist/10gen mongodb-org-mongos i386 2.6.1 [7,045 kB]
Get:4 http://downloads-distro.mongodb.org/repo/ubuntu-upstart/ dist/10gen mongodb-org-tools i386 2.6.1 [92.3 MB]
Get:5 http://downloads-distro.mongodb.org/repo/ubuntu-upstart/ dist/10gen mongodb-org i386 2.6.1 [3,652 B]
Fetched 113 MB in 4min 52s (386 kB/s)
Selecting previously unselected package mongodb-org-shell.
(Reading database … 243751 files and directories currently installed.)
Preparing to unpack …/mongodb-org-shell_2.6.1_i386.deb …
Unpacking mongodb-org-shell (2.6.1) …
Selecting previously unselected package mongodb-org-server.
Preparing to unpack …/mongodb-org-server_2.6.1_i386.deb …
Unpacking mongodb-org-server (2.6.1) …
Selecting previously unselected package mongodb-org-mongos.
Preparing to unpack …/mongodb-org-mongos_2.6.1_i386.deb …
Unpacking mongodb-org-mongos (2.6.1) …
Selecting previously unselected package mongodb-org-tools.
Preparing to unpack …/mongodb-org-tools_2.6.1_i386.deb …
Unpacking mongodb-org-tools (2.6.1) …
Selecting previously unselected package mongodb-org.
Preparing to unpack …/mongodb-org_2.6.1_i386.deb …
Unpacking mongodb-org (2.6.1) …
Processing triggers for man-db (2.6.7.1-1ubuntu1) …
Processing triggers for ureadahead (0.100.0-16) …
Setting up mongodb-org-shell (2.6.1) …
Setting up mongodb-org-server (2.6.1) …
mongod start/running, process 12163
Setting up mongodb-org-mongos (2.6.1) …
Setting up mongodb-org-tools (2.6.1) …
Processing triggers for ureadahead (0.100.0-16) …
Setting up mongodb-org (2.6.1) …

Once MongoDB has been installed via Ubuntu APT, it will be updated frequently whenever newer versions arrive. In order to stop this, the following commands need to be run

  • echo “mongodb-org hold” | sudo dpkg –set-selections
    echo “mongodb-org-server hold” | sudo dpkg –set-selections
    echo “mongodb-org-shell hold” | sudo dpkg –set-selections
    echo “mongodb-org-mongos hold” | sudo dpkg –set-selections
    echo “mongodb-org-tools hold” | sudo dpkg –set-selections
  • Running MongoDB on Ubuntu (Linux)
    ======================================================

    The MongoDB instance stores its data files in /var/lib/mongodb and its log files in /var/log/mongodb by default, and runs using the mongodb user account. You can specify alternate log and data file directories in /etc/mongod.conf. See systemLog.path and storage.dbPath for additional information.

    If you change the user that runs the MongoDB process, you must modify the access control rights to the /var/lib/mongodb and /var/log/mongodb directories to give this user access to these directories.

    sudo service mongod start

    Verify that the mongod process has started successfully by checking the contents of the log file at /var/log/mongodb/mongod.log for a line reading

    [initandlisten] waiting for connections on port <port>

    where <port> is the port configured in /etc/mongod.conf, 27017 by default.

    grep “waiting for connections on port” /var/log/mongodb/mongod.log

    rahulsaini@rahulsaini-UBUNTU:~$ grep “waiting for connections on port” /var/log/mongodb/mongod.log
    2015-04-01T22:27:45.674+0530 [initandlisten] waiting for connections on port 27017
    rahulsaini@rahulsaini-UBUNTU:~$

    sudo service mongod stop

    Later, to stop MongoDB, press Control+C in the terminal where the mongod instance is running.

Enjoy !

#linux, #mongodb, #ubuntu