Subscribe to Posts by Email

Subscriber Count

    699

Disclaimer

All information is offered in good faith and in the hope that it may be of use for educational purpose and for Database community purpose, but is not guaranteed to be correct, up to date or suitable for any particular purpose. db.geeksinsight.com accepts no liability in respect of this information or its use. This site is independent of and does not represent Oracle Corporation in any way. Oracle does not officially sponsor, approve, or endorse this site or its content and if notify any such I am happy to remove. Product and company names mentioned in this website may be the trademarks of their respective owners and published here for informational purpose only. This is my personal blog. The views expressed on these pages are mine and learnt from other blogs and bloggers and to enhance and support the DBA community and this web blog does not represent the thoughts, intentions, plans or strategies of my current employer nor the Oracle and its affiliates or any other companies. And this website does not offer or take profit for providing these content and this is purely non-profit and for educational purpose only. If you see any issues with Content and copy write issues, I am happy to remove if you notify me. Contact Geek DBA Team, via geeksinsights@gmail.com

Pages

MongoDB for Oracle DBA’s Part 4 : Creating Standalone MongoDB Database

In this post, we will see how to create a standalone MongoDB Instance.

Installation is pretty straight forward just download and modify few configuration options and start the instance. This is just to prepare and know ourself, whilst the next posts will be continuation of this post , to convert the single instance to a replica set in standalone server (for practice) and then converting to a shard, which all will be hosted on single host for practice purpose.

To do the installation the following steps are necessary, 

  • Complete some pre-requisities
  • Create Mongo user
  • Create Data Directories and Log Directories (specific to our setup)
  • Download and Install the MongoDB Software
  • Modify the Options
  • Start the mongodb instance
  • Diagram of the Instance

### Complete the pre-requisties ###

  • /sys/kernel/mm/transparent_hugepage/defrag should be 'never'
  • soft rlimits too low. rlimits set to 1024 processes, 64000 files. Number of processes should be at least 32000 : 0.5 times number of files
  • Ports from 27017 to 65556 should be open (we use some range for all our nodes in future posts)
  • 32Bit version can hold only 2gb of data, hence use 64bit operating system

### Create mongo User ###

useradd -g mongo mongo

passwd mongo

### Create Directories ###

mkdir -p /backups/data/cluster/shard1/rs0/0/logs

mkdir -p /backups/data/cluster/shard1/rs0/0/data

Note: /backups/data/cluster is my base directory and shard1 is to identify the shard and rs0 belongs to replicaset and 0 is node sequence, this is just to for directory nomenclature to host all in one standalone server for practice purpose.

### Download and Install MongoDB Software ###

### Create Repo File

vi /etc/yum.repos.d/mongodb.repo

[mongodb]

name=mongodb Repository

baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64

gpgcheck=0

enabled=1

:wq

### Install Mongo using yum, this will install all pre-requisities RPM for MongoDB ###

yum install mongo-*

A typical output will be like this

Installed:

 mongodb-enterprise.x86_64 0:3.2.1-1.el6  mongodb-enterprise-server.x86_64 0:3.2.1-1.el6 mongodb-enterprise-shell.x86_64 0:3.2.1-1.el6

 mongodb-enterprise-tools.x86_64 0:3.2.1-1.el6

Dependency Installed:

 cyrus-sasl-gssapi.x86_64 0:2.1.23-15.el6_6.2 cyrus-sasl-plain.x86_64 0:2.1.23-15.el6_6.2 net-snmp.x86_64 1:5.5-57.0.1.el6_8.1

Dependency Updated:

 net-snmp-libs.x86_64 1:5.5-57.0.1.el6_8.1         net-snmp-utils.x86_64 1:5.5-57.0.1.el6_8.1

### Alternatively you can directly download using wget

 

### Configure the Conf file ###

vi /backups/data/cluster/shard1/rs0.conf

systemLog:

  destination: file

  path: "/backups/data/cluster/shard1/rs0/0/logs/rs0.log"

  logAppend: true

processManagement:

  pidFilePath: "/backups/data/cluster/shard1/rs0/0/shard1.pid"

  fork: true

net:

  bindIp: 127.0.0.1

  port: 47018

storage:

  engine: "mmapv1"

  dbPath: "/backups/data/cluster/shard1/rs0/0/data"

  directoryPerDB: true

operationProfiling:

  mode: all

:wq

### Start the mongod instance ###

mongod -f  /backups/data/cluster/shard1/rs0.conf

### Verify the process running ###

root@wash-i-03aaefdf-restore /backups/data/cluster/shard1/rs0/1/data/foo $ ps -eaf | grep mongo

root     21615     1  6 11:42 ?        00:02:28 mongod -f /backups/data/cluster/shard1/rs0.conf

### Stop the mongod Instance ###

mongod -f /backups/data/cluster/shard1/rs0.conf --shutdown

### login into the mongodb instance ###

mongo localhost:47018

### Creating a Sample Database & Collection ###

mongo localhost:47018

use foo

### Insert Records

for (var i = 1; i <= 500000; i++) db.testData.insert( { x : i } )

Output: WriteResult({ "nInserted" : 1 })

### Querying the Database ###

mongo localhost:47018

use foo

db.testData.find()

### The single instance looks like as this diagram ###

Next Post: Converting the Single MongoDB Instance to Replicaset in Standalone Server

Comments are closed.