Skip to content

倪之帅 Victor 个人主页

  • Home
  • Tech
    • Linux
    • LNMP
    • Mac
    • Mobile
    • Products
    • SMS
  • 英语学习
April 26, 2014 / Linux

Install MongoDB on Amazon Linux

Install MongoDB

  • Use a 64-bit EC2 Amazon Linux instance to install MongoDB
  • Add a MongoDB yum repository for a 64-bit RPM

    sudo vi /etc/yum.repos.d/10gen.repo

    [10gen]
    name=10gen Repository
    baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
    gpgcheck=0

  • Install MongoDB

    sudo yum install mongo-10gen and mongo-10gen-server

  • Setup the data directory

    sudo mkdir -p /data/db/

     If a new EBS storage is mounted for the data directory, mount with the noatime and nodiratime atributes

  • Start MongoDB

    sudo mongod

     For production environment, change the owner of mongo to a local user instead of root and start with mongod

MongoDB Installation Smoke test

  • Start MongoDB client

    mongo

  • Insert and retrieve data

    db.things.save( { 'stage' : 'test' } )
    db.things.find()
    { "_id" : ObjectId("4db76912b5c36fabd0006041"), "stage" : "test" }
    exit

For PHP support on MongoDB

  • Install PHP if not done

    sudo yum install gcc
    sudo yum install make
    
    sudo yum install httpd mod_ssl
    sudo yum install php
    sudo yum install php-devel php-pear
    sudo yum install pcre-devel

  • Install MongoDB driver for Amazon Linux

    sudo pecl install mongo

  • Enable the driver

    sudo vi /etc/php.d/mongo.ini

    extension=mongo.so

Sample PHP code in using MongoDB

<?php

$db = new Mongo();

// Select the store DB
$db = $db->store;

// Select a collection
$collection = $db->users;

// Insert
$person = array( "name" => "David Jones", "age" => 30 );
$collection->insert($person);

// find data
$cursor = $collection->find();

// iterate through the results
foreach ($cursor as $data) {
    echo $data["name"] . "\n";
}

?>
 

Post navigation

Previous Post:

Formatting and Mounting Amazon EC2 Instance Ephemeral Storage

Next Post:

Debian SMS system

7 Commments

  1. Pingback: Clifton
  2. Pingback: claude
  3. JamesFgyhcgt says:
    March 21, 2016 at 7:37 pm

    I see, that your page needs unique and fresh content. I know it is hard to write posts manually everyday, but there is solution for this.

    Just search in google for; servitu’s tricks

    Log in to Reply
  4. clash royale cheats android 2016 says:
    August 7, 2016 at 2:17 am

    Please Like, Share, Tweet or Google+ in order to gain access
    to the latest working form of Clash Royale Hack and offer the developers.

    Log in to Reply
  5. buy hut coins says:
    August 25, 2016 at 7:46 pm

    I have read so many content concerning the blogger lovers but this article is truly a
    pleasant paragraph, keep it up.

    Log in to Reply
  6. clash royale hack android says:
    September 4, 2016 at 5:52 pm

    While in the Clash Royale Hack that’s online, the user must down load it very first and follow several steps
    thereon, the web one allows the user to utilize it in no time.
    Furthermore, downloading perhaps hindered by specific circumstances such as internet
    rate and others. Not forgetting, additionally requires
    installation, that might be really technical
    for some.

    Log in to Reply
  7. clash royale hack|clash royale trucos says:
    September 10, 2016 at 8:46 pm

    Hi there, I desire to subscribe forr this website to get newest updates, so
    wherte can i doo it please help.

    Log in to Reply

Leave a Reply Cancel reply

You must be logged in to post a comment.

Categories

  • Linux
  • LNMP
  • Mac
  • Mobile
  • PHP
  • Products
  • SMS
  • Uncategorized
  • VPS
  • 原创
  • 技术

Recent Posts

  • composer切换源_composer全局更换镜像源的教程
  • 宝塔终端切换root用户为www
  • linux 宝塔 nginx php8.0 或者 php7 安装swoole
  • 宝塔面板修改composer默认PHP版本
  • PHP代码http跳转到https

Archives

  • October 2022
  • August 2022
  • June 2020
  • June 2019
  • October 2018
  • May 2018
  • April 2018
  • March 2018
  • July 2016
  • June 2016
  • April 2016
  • November 2015
  • October 2015
  • May 2015
  • April 2015
  • February 2015
  • January 2015
  • December 2014
  • October 2014
  • August 2014
  • April 2014
  • June 2011
  • June 2010
  • May 2010
  • April 2010
  • December 2004
  • October 2002
  • January 2001
  • March 2000
© 2000-2025 倪之帅 Victor 个人主页