Quantcast
Channel: LinOxide
Viewing all articles
Browse latest Browse all 1287

How to Install and Use MongoDB on FreeBSD 9.3 / 10.1

$
0
0

In this howto tutorial we will explore towards the setup of MongoDB on FreeBSD Operating system. MongoDB is a high-performance and scalable open source database application preferably designed for handling document-oriented storage with high availability. Moreover MongoDB is an ease of use to install, configure and maintain as compared to other database servers. It’s a server process that supports cross platforms and runs efficiently on Linux, Windows and OS X. We are going to setup its installation and configuration on FreeBSD 10.1 which is a UNIX like Operating System used for variety of platform because of its main features that is speed and its stability.

Pre-Installation Setup

Before starting with the installation of MongoDB, make sure that you have considerable privileges on server to perform each step. there are different ways to install MongoDB on freeBSD and other distributions but in this tutorial we will go with two different methods to install MondoDB on freeBSD.
System Update
Login to root user and exceute the following commands to update your FreeBSD.

root@FreeBSD-10:~ # portsnap fetch
root@FreeBSD-10:~ # portsnap extract

Installing MongoDB with PKG on FreeBSD

This is the simplest and easy way to install mongodb with package management tool on FreeBSD as it already provide us its package libraries and default configurations. Now start with the following steps to install mongodb.
STEP 1: Update PKG Repository
In order to update FreeBSD binary packages repository use the following command.

root@FreeBSD-10:~ # pkg update –f

STEP 2: Install MongoDB
Run the PKG command to install the package from the updated FreeBSD repository catalog as.

root@FreeBSD-10:~ # pkg install mongodb

This will install mongodb with addition of following new mandatory packages. Press "Y" to proceed.

New packages to be INSTALLED:
mongodb: 2.6.7
v8: 3.18.5
python27: 2.7.9_1
libffi: 3.2.1
python2: 2_3
pcre: 8.37_1
snappy: 1.1.1_1

The process will require 268 MiB more space.

Proceed with this action? [y/N]: y

STEP 3: Enable Boot Startup
Once the packages are installed, configure rc.conf file to enable mongodb service start up at boot as.

root@FreeBSD-10:~ # vi /etc/rc.conf
mongod_enable="YES"

STEP 4: Start MongoDB Service
Now start the mongod service and confirms its active status.

root@FreeBSD-10:/usr/ports/databases/mongodb # service mongod start
Starting mongod.
root@FreeBSD-10:/usr/ports/databases/mongodb # service mongod status
mongod is running as pid 92616.

STEP 5: Start Using Mongo Shell
MongoDB is ready to use on the shell, we can connect to the databases using mongo shell as.

root@FreeBSD-10:~ # mongo
MongoDB shell version: 2.6.7
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
>

Installing MongoDB from Ports on FreeBSD

Installation of MongoDB from ports way is also a simple method but its a long process and mainly depends on connection speed. During its installation process it might ask about different dependent packages that we can choose and configure as per required.

STEP 1: Starting Installation
Our first step would be to change the directory to ports databases into monogodb and run the make install command.

root@FreeBSD-10:~ # cd /usr/ports/databases/mongodb/
root@FreeBSD-10:/usr/ports/databases/mongodb # ls
Makefile distinfo files pkg-descr pkg-plist
root@FreeBSD-10:/usr/ports/databases/mongodb # make install clean

It will open a command prompt to choose from the option and press OK to proceed.

install mongodb

Similarly the installation process prompts for other packages to be configured as default or we can make changes to it like here it shows about the configuration settings of Python.

Python Installation

STEP 2: Configure Start-up Settings

Once the installation process completes we will configure its start up settings with its db and configurations path into rc.conf file.

root@FreeBSD-10:/usr/ports/databases/mongodb # vi /etc/rc.conf
mongod_enable="YES"
mongod_config="/usr/local/etc/mongodb.conf"
mongod_dbpath="/var/db/mongodb"

STEP 3: Configure MongoDB Conf

We can configure monogodb configurations file according to our environment as a single server node we will configure it to master with no http interface.

root@FreeBSD-10:/usr/ports/databases/mongodb # vi /usr/local/etc/mongodb.conf
master = true
nohttpinterface = true

Now restart mongod service and start using mongo.

root@FreeBSD-10:/usr/ports/databases/mongodb # service mongod start
Starting mongod

Using MongoDB Shell

We can perform almost every function from the mongo shell.Let's take a review by using few simple commands on mongo shell.

To check all databases on the server run the follwoing command in mongo shell.

> show dbs

Now we create a simple test collection and insert some variables in it and then save that variables to the test database. We will use .save() command for saving the data into the new collection as shown.

Mongo shell

Installing MongoDB PHP Interface

If you want to use mongoDB with php, then we can install pecl mongo extension for the administration of mongodb over the web. There are many other php extensions are available that we can install and use for mongo web interface. So, lets start with installing pecl-mongo installation on freeBSD from its ports.

Installing pecl-mongo

Move to the ports directory for pecl-mongo and run make install command.

root@FreeBSD-10:/usr/ports/databases/mongodb # cd /usr/ports/databases/pecl-mongo
root@FreeBSD-10:/usr/ports/databases/pecl-mongo # make install clean

During the installation process it prompts for the options to choose as per required configurations of php, perl and libxml libraries. We can configure it with appropriate options.

php version

Before the installation completes, pecl-mongo extension indiacated the default configurations of php that we can change through if required.

php conf

Now we access the web interface of pecl-mongo with port 27017 on localhost as below.

http://localhost:27017/
http://127.0.0.1:27017/

Conclusion

We learned to install mongodb on FreeBSD with PKG and Ports method with its basic configurations and using it on mongo shell and to access it over the web. I hope you get good idea with Mongo to build your own MongoDB environment on FreeBSD.

The post How to Install and Use MongoDB on FreeBSD 9.3 / 10.1 appeared first on LinOxide.


Viewing all articles
Browse latest Browse all 1287

Trending Articles