LoginSignup
120

More than 5 years have passed since last update.

CentOS6.5にMongoDBをインストールする

Last updated at Posted at 2014-09-07

はじめに

CentOS 6.5に、MongoDBの最新版をインストールする方法です。
現在の最新版は2.6.4です。

公式のCentOSへのインストール手順にそってインストールしていきます。

環境

  • CentOS 6.5 64bit

手順

MongoDBレポジトリ追加

今回はMongoDBのレポジトリからyumでインストールします。
まずはレポジトリを追加します。

/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

インストール

mongodb-orgというパッケージをインストールします。

$ sudo yum install -y mongodb-org

このパッケージは、次の4種類のパッケージをインストールしてくれます。

============================================================================
 Package                  Arch         Version          Repository     Size
============================================================================
Installing:
 mongodb-org              x86_64       2.6.4-1          mongodb       4.6 k
Installing for dependencies:
 mongodb-org-mongos       x86_64       2.6.4-1          mongodb       6.8 M
 mongodb-org-server       x86_64       2.6.4-1          mongodb       9.0 M
 mongodb-org-shell        x86_64       2.6.4-1          mongodb       4.3 M
 mongodb-org-tools        x86_64       2.6.4-1          mongodb        89 M

Transaction Summary
============================================================================
Install       5 Package(s)

それぞれ、

  • mongodb-org-server: MongoDBサーバのmongodやinitスクリプト
  • mongodb-org-mongos: シャーディングを管理するmongosサーバ
  • mongodb-org-shell: クライアントシェル
  • mongodb-org-tools: mongodumpやmongotopなどの周辺ツール群

起動

起動します。
これも、一般的なコマンドで一発です。

$ sudo service mongod start
Starting mongod:  [  OK  ]

確認

動作確認のため、ちょろっとmongoシェルを使ってみます。

$ mongo
MongoDB shell version: 2.6.4
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
> use test
switched to db test
> db.fish.insert({name: "マグロ"})
WriteResult({ "nInserted" : 1 })
> db.fish.find()
{ "_id" : ObjectId("540bd2d7a3754bda459c21ad"), "name" : "マグロ" }
> db.dropDatabase()
{ "dropped" : "test", "ok" : 1 }
> show dbs
admin  (empty)
local  0.078GB
> exit
bye

よさそうです。

おわりに

非常に簡単でした。
実際の用途では設定ファイルの/etc/mongod.confを編集したり、ReplicaSetやShardingを組むことになると思います。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
120