Showing posts with label MongoDB. Show all posts
Showing posts with label MongoDB. Show all posts

Monday, 7 March 2016

Install MongoDB On CentOS AWS Server


Enable MongoDB Repo:


echo "[MongoDB]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
gpgcheck=0
enabled=1" | sudo tee -a /etc/yum.repos.d/mongodb.repo

sudo yum install -y mongodb-org-server mongodb-org-shell mongodb-org-tools
sudo nano /etc/security/limits.conf

# End of file:
* soft nofile 64000
* hard nofile 64000
* soft nproc 32000
* hard nproc 32000

:wq


sudo nano /etc/security/limits.d/90-nproc.conf
## End of file

* soft nproc 32000
* hard nproc 32000

:wq


To check disk name :
fdisk -l

## edit here disk name like sda sdb sdc etc

echo 'ACTION=="add", KERNEL=="xvda1", ATTR{bdi/read_ahead_kb}="16"' | sudo tee -a /etc/udev/rules.d/85-ebs.rules

sudo service mongod start
sudo service mongod status
mongo
vim /etc/init.d/disable-transparent-hugepages

####

#!/bin/sh
### BEGIN INIT INFO
# Provides:          disable-transparent-hugepages
# Required-Start:    $local_fs
# Required-Stop:
# X-Start-Before:    mongod mongodb-mms-automation-agent
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Disable Linux transparent huge pages
# Description:       Disable Linux transparent huge pages, to improve
#                    database performance.
### END INIT INFO


case $1 in
  start)
    if [ -d /sys/kernel/mm/transparent_hugepage ]; then
      thp_path=/sys/kernel/mm/transparent_hugepage
    elif [ -d /sys/kernel/mm/redhat_transparent_hugepage ]; then
      thp_path=/sys/kernel/mm/redhat_transparent_hugepage
    else
      return 0
    fi

    echo 'never' > ${thp_path}/enabled
    echo 'never' > ${thp_path}/defrag

    unset thp_path
    ;;
esac


:wq


sudo chmod 755 /etc/init.d/disable-transparent-hugepages
chkconfig --add disable-transparent-hugepages
/etc/init.d/mongod restart
/etc/init.d/mongod status
chkconfig mongod on
reboot
/etc/init.d/mongod status
mongo

> show dbs
> exit
/etc/init.d/mongod restart

==============================


https://docs.mongodb.org/ecosystem/platforms/amazon-ec2/
https://docs.mongodb.org/manual/tutorial/transparent-huge-pages/


echo 'ACTION=="add", KERNEL=="xvda1", ATTR{bdi/read_ahead_kb}="16"' | sudo tee -a /etc/udev/rules.d/85-ebs.rules

Create the init.d script.

Create the following file at /etc/init.d/disable-transparent-hugepages:

#!/bin/sh
### BEGIN INIT INFO
# Provides:          disable-transparent-hugepages
# Required-Start:    $local_fs
# Required-Stop:
# X-Start-Before:    mongod mongodb-mms-automation-agent
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Disable Linux transparent huge pages
# Description:       Disable Linux transparent huge pages, to improve
#                    database performance.
### END INIT INFO

case $1 in
  start)
    if [ -d /sys/kernel/mm/transparent_hugepage ]; then
      thp_path=/sys/kernel/mm/transparent_hugepage
    elif [ -d /sys/kernel/mm/redhat_transparent_hugepage ]; then
      thp_path=/sys/kernel/mm/redhat_transparent_hugepage
    else
      return 0
    fi

    echo 'never' > ${thp_path}/enabled
    echo 'never' > ${thp_path}/defrag

    unset thp_path
    ;;
esac

2
Make it executable.

Run the following command to ensure that the init script can be used:

sudo chmod 755 /etc/init.d/disable-transparent-hugepages

3
Configure your operating system to run it on boot.

Use the appropriate command to configure the new init script on your Linux distribution.
Distribution     Command
Ubuntu and Debian    

sudo update-rc.d disable-transparent-hugepages defaults

SUSE    

sudo insserv /etc/init.d/disable-transparent-hugepages

Red Hat, CentOS, Amazon Linux, and derivatives    

sudo chkconfig --add disable-transparent-hugepages




How to Install MongoDB 3.0 on CentOS


Step 1: Add MongoDB Yum Repository


Add following content in yum repository configuration file,  as per your required MongoDB version and system architecture. For this article we are using MongoDB 3.0 repository.


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


For MongoDB 3.0.X


For 64bit Systems:


[mongodb-org-3.0]

name=MongoDB 3.0 Repository

baseurl=http://repo.mongodb.org/yum/redhat/6/mongodb-org/stable/x86_64/

gpgcheck=0

enabled=1


For MongoDB 2.6.X


For 64bit Systems:


[MongoDB]

name=MongoDB Repository

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

gpgcheck=0

enabled=1


For 32bit Systems:


[MongoDB]

name=MongoDB Repository

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

gpgcheck=0

enabled=1


:wq


Step 2: Install MongoDB


yum install mongodb-org


Step 3: Start MongoDB


Package mongodb-org-server provided MongoDB init script, Use that script to start service.


# /etc/init.d/mongod restart


Configure MongoDB to auto start on system boot.


# chkconfig mongod on



Step 4: Check MongoDB Version and Test Setup


Use following command to check installed mongodb version


[root@tecadmin ~]#  mongo --version


MongoDB shell version: 3.0.0



Connect MongoDB using command line and execute some test commands for checking proper working.


[root@tecadmin ~]#  mongo


> use mydb;

> db.test.save( { a: 1 } )

> db.test.find()


  { "_id" : ObjectId("54fc2a4c71b56443ced99ba2"), "a" : 1 }


Congratulation’s You have successfully installed mongodb server on your system



Configure MongoDB For connection:


vim  /etc/mongod.conf


Uncomment this line : we can set optional port here:


port=27017


Below line looks like this: add bind ip: 0.0.0.0

#bind_ip=127.0.0.1

bind_ip=0.0.0.0


:wq



service mongod restart



telnet localhost 27017



For Web Base UI: install robomongo  package


Ref :


http://docs.mongodb.org/v3.0/release-notes/3.0/

http://tecadmin.net/install-mongodb-on-centos-rhel-and-fedora/


Install MongoDB On Ubuntu 15.04


### Import the public key used by the package management system.¶


sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10



###  Create a list file for MongoDB.


Create the /etc/apt/sources.list.d/mongodb-org-3.0.list list file using the command appropriate for your version of Ubuntu:



echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list



###  Reload local package database.



sudo apt-get update



##  Install the MongoDB packages.


Install the latest stable version of MongoDB.¶



sudo apt-get install -y mongodb-org



###  Install a specific release of MongoDB.¶



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





Install the MongoDB packages.


You can install either the latest stable version of MongoDB or a specific version of MongoDB.

Install the latest stable version of MongoDB.


Issue the following command:


sudo apt-get install -y mongodb-org


Install a specific release of MongoDB.


To install a specific release, you must specify each component package individually along with the version number, as in the following example:


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


If you only install mongodb-org=3.0.6 and do not include the component packages, the latest version of each MongoDB package will be installed regardless of what version you specified.


Start MongoDB.



Ref :


http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/

http://tecadmin.net/install-mongodb-on-ubuntu/#