MongoDB Tutorial 3: Introduction

From The Uniform Server Wiki
Revision as of 13:17, 1 August 2010 by Ric (talk | contribs) (New page: {{Nav MongoDB Tutorial 3}} '''''MongoDB''''' == Introduction == This tutorial covers a production standalone version of MongoDB. As a starting point is uses the basic standalone version co...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

 

MongoDB Production Standalone
UniServer 6-Carbo.

MongoDB

Introduction

This tutorial covers a production standalone version of MongoDB. As a starting point is uses the basic standalone version covered in tutorial 1. Non-authentication components are replaced with their authentication counterparts as covered in the initial plugin design tutorial.

With this structure in place additional functionally is added making the server easier to administer.

Top

Downloads

We require a working MongoDB server to this we will add components from the tutorial plugin design.

Downloads and install

  • Create a new folder z_mongo
  1. Download standalone server mongo_standalone_v1_0.exe and save to this foldr.
  2. Extract by double clicking on file mongo_standalone_v1_0.exe
  • Create two new folders:
  1. z_mongo\temp
  2. z_mongo\zz_temp
  • # Download mongodb_plugin_design_v1_0.exe
  1. Save to z_mongo\zz_temp
  2. To extract Double click mongodb_plugin_design_v1_0.exe


  • Navigate to folder z_mongo\zz_temp\usr\local\mongo_tutorial\Cheat_folder
  1. Copy file mongo_db_inc.php to folder z_mongo\temp
  • Navigate to folder z_mongo\zz_temp\usr\local\mongo_tutorial\bin
  1. Copy files config_auth.ini and mongo_name_password
  2. Toc folder \z_mongo\mongodb_1\bin
  • Delete folder z_mongo\zz_temp

For download details see MongoDB Introduction (Main Start page)

Top

Update mongo_db_inc.php

Production server uses authentications hence we need to remove all functions that are related to no authentication.

Edit file z_mongo\temp\mongo_db_inc.php and remove the following functions:

  • set_mongo_port_no_auth($new_port)
  • get_mongo_port_no_auth()
  • start_mongo_no_auth()
  • stop_mongo_no_auth()
  • client_no_auth()
  • list_dbs_no_auth()
  • drop_db_no_auth($db_name)

Paths

The file has the following incrorrect paths:

$path_array      = explode("\\usr",getcwd());              // Split at folder usr
$mongo_base      = $path_array[0];                         // find drive letter and any sub-folders 
$mongo_base_f    = preg_replace('/\\\/','/', $mongo_base); // Replace \ with /

//=== FOLDERS ===
define("MONGO_BIN",   "$mongo_base_f/usr/local/mongo_tutorial/bin");  // Binaries for MongoDB

//=== FILES ===
define("CONFIG_NO_AUTH_F",   "$mongo_base_f/usr/local/mongo_tutorial/bin/config_no_auth.ini"); 
define("CONFIG_AUTH_F",      "$mongo_base_f/usr/local/mongo_tutorial/bin/config_auth.ini"); 
define("NAME_PWD_F",         "$mongo_base_f/usr/local/mongo_tutorial/bin/mongo_name_password"); 
define("UNISERV_EXE",        "$mongo_base_f/usr/local/mongo_tutorial/bin/uniserv.exe"); // Utility 
define("UNISERV_EXE_B",      $mongo_base.'\usr\local\mongo_tutorial\bin\uniserv.exe');  // Utility 
define("MON_PSKILL_EXE",     "$mongo_base_f/usr/local/mongo_tutorial/bin/pskill.exe");  // Utility 
define("CMD_DUMMY_TXT",      "$mongo_base_f/usr/local/mongo_tutorial/bin/cmd_dummy.txt"); // Temp command fie

Correct paths are contained in file z_mongo\mongodb_1\control\mongo_db_inc.php as shown:

$path_array      = explode("\\mongodb_1",getcwd());          // Split at folder usr
$mongo_base      = $path_array[0];                           // find drive letter and any sub-folders 
$mongo_base_f    = preg_replace('/\\\/','/', $mongo_base);   // Replace \ with /

//=== FOLDERS ===
define("MONGO_BIN",   "$mongo_base_f/mongodb_1/bin");        // Binaries for MongoDB

//=== FILES ===
define("INFO_TXT",           "$mongo_base_f/mongodb_1/control/read_me.txt"); // Information file
define("NO_NAG_TXT",         "$mongo_base_f/mongodb_1/control/no_nag.txt");  // Dummy file
define("CONFIG_NO_AUTH_F",   "$mongo_base_f/mongodb_1/bin/config_no_auth.ini"); 
define("UNISERV_EXE",        "$mongo_base_f/mongodb_1/bin/uniserv.exe"); // Utility 
define("UNISERV_EXE_B",      $mongo_base.'\mongodb_1\bin\uniserv.exe');  // Utility 
define("MON_PSKILL_EXE",     "$mongo_base_f/mongodb_1/bin/pskill.exe");  // Utility 

Top

Path Difference

The following are differences

define("CONFIG_AUTH_F",      "$mongo_base_f/usr/local/mongo_tutorial/bin/config_auth.ini"); 
define("NAME_PWD_F",         "$mongo_base_f/usr/local/mongo_tutorial/bin/mongo_name_password"); 
define("CMD_DUMMY_TXT",      "$mongo_base_f/usr/local/mongo_tutorial/bin/cmd_dummy.txt"); // Temp command fie

Convert these and add to the correct paths and replace the entire section in file z_mongo\temp\mongo_db_inc.php

Finally copy z_mongo\temp\mongo_db_inc.php to z_mongo\mongodb_1\control

Top

Update mongo_tutorial.phpw

Our application requires updating for authentication only.

This really is easy edit file z_mongo\mongodb_1\control\mongo_tutorial.phpw

With the exception of "no_nag" replace all names containing "no_" with nothing "" converts no authentication to authentication.

Top

Enable authentication

Our application will now access MongoDB server in authentication mode. At least one user must be assigned to the Admin database. Attempting to run server without this user will fail.

Using the batch files we start server in non-authentication mode and configure this root user as follows:

Start Server:

  • Navigate to folder z_mongo\mongodb_1\alt_control_2
  • Start server double click on Start_mongo.bat
  • Start mongo-client: Double click on monogo_client.bat

Enter the following:

  • use admin
  • db.addUser("root", "root")

Stop Server:

  • Stop Server Double clicks on Stop_mongo.bat
MongoDB shell version: 1.4.4
url: test
connecting to: test
type "exit" to exit
type "help" for help
> use admin
switched to db admin
> db.addUser("root", "root")
{
        "user" : "root",
        "readOnly" : false,
        "pwd" : "2a8025f0885adad5a8ce0044070032b3"
}
> exit
bye
Press any key to continue . . .

Top

Test

At this stage we have a working server requiring a user to authenticate.

  • Start the application by running z_mongo\mongodb_1\Run_MongoDB.exe
  • Start server
  • Check you can connect using client
  • Close server

Top

Rename

Currently scrip names refer to a tutorial for consistency we will name these as follow:

  • mongo_tutorial.bat to Run_mongo_db.bat
  • mongo_tutorial.phpw to mongo_db.php

Edit file Run_mongo_db.bat

Change this line:

php.exe -c mongo_tutorial_cli.ini ..\control\mongo_tutorial.phpw

To

php.exe -c mongo_tutorial_cli.ini ..\control\mongo_db.php

Top

Summary

We have a working server remainder of this tutorial covers adding additional functionality.

We will start with change Port and Password pop-up window

Top