カテゴリーアーカイブ: MongoDB

【やった】dotcloud/MongoDBを試す。そしてクライアント(php)から接続する。

dotcloudでMongoDBも使えるみたいなので、試してみます。
そのメモ。
内容は、
1.dotcloud上でMongoDBを試す。
2.クライアント(php)から接続する。
の2本です。

 

 

 

この投稿の続きを読む

>[いってきた]Mongo Tokyo

>昨日、某社でおこなわれていた

Mongo Tokyo を参加しました!

ので、自分用のまとめや今後活かせることまとめておきます。

お昼と業務後しか、行けなかったけど為になりました。

(アプリ寄りのセッションを全部聞けたのは、幸運。)

▼概要

http://www.10gen.com/conferences/mongotokyo2011

▼聴講したセッション

  • Welcome to Mongo Tokyo and Introduction to MongoDB
  • Kiosk: The Schema Layer for MongoDB and PHP – Schema is Not Your Enemy
  • Node.js and MongoDB

▼スライド

▼今後活かせること

  • node.js とMongoDBの相性は抜群にいい。
  • ↑は、テストが最も大事。エラーハンドリングも、やり方大事。
  • nodeunite
  • 汎用dataの格納できる。

▼その他

  • ソーシャルゲームは、仕様変更が多い。イベントもたくさんある。
  • 運用ツールに、最新技術を利用する。

[Mickey]

>[入れてみた]MongoDBのGUIツール – rock_mongo

>

MongoDBのGUIツール、rock_mongoを入れてみたので、そのメモ。

▼rock_mongoのインストール

http://code.google.com/p/rock-php/wiki/rock_mongo

wget http://rock-php.googlecode.com/files/rockmongo-v1.0.11.zip
unzip rockmongo-v1.0.11.zip

▼IP/Host/Portの設定

diff config.php config.php.ORG
19c19
<               “host” => “[XXXXXXX]”, // Replace your MongoDB host ip or domain name here

>               “host” => “127.0.0.1”, // Replace your MongoDB host ip or domain name here

The MongoDB PHP driverをインストール。

#インストール

sudo pecl install mongo

#php.iniの設定

diff /etc/php.ini /etc/php.ini.20110215

1219,1221d1218
< [mongo]
< extension=mongo.so

▼apache再起動
/etc/rc.d/init.d/httpd restart

▼MongoDB起動

これは、いつもどおり。

▼つかう。

http://localhost/rockmongo/index.php

※日本語も選択できる。ちょっと訳がおかしいけど。

これで、画面から操作できるわー

[Mickey]

>[Memo]MongoDB 64bit Win7-OS

>昨日の問題点1.  2Gを超えるデータは、32bit Machineでは扱えない、ことの対策。

32bit Machineでは、サイズの大きなDBを扱うことが出来ないことなので、、

32-bit MongoDB processes are limited to about 2.5 gb of data.

Right now there aren’t too many people for whom 64-bit is a problem, and in the long term, we think this will be a non-issue.

http://blog.mongodb.org/post/137788967/32-bit-limitations

64bit Machineにて、再度環境構築をします(^^ゞ

環境は以下のとおりです。

  • OS:window7 64bit
  • CPU:inter core i7 860
  • Memory:6GB

Winでの構築方法は以下のとおり。(何でもすぐに調べられる時代だ。)

Installing MongoDB as a Service on Windows 7

  1. Download and extract the MongoDB archive appropriate for your system. http://www.mongodb.org/display/DOCS/Downloads
  2. Copy the extracted folder to C: and rename it mongo.
  3. Create a directory called ‘data’ inside C:mongo
  4. Click on the Start Menu and enter “cmd” in the search box. Right-click on cmd.exe and select “Run as administrator.” This is VERY important because you won’t be able to register MongoDB as a service if you run cmd.exe with normal privileges.
  5. Type “C:mongobinmongod –install” to register MongoDB as a Windows service. This will probably output what may look like an error message, but don’t worry … as long as you really did run cmd.exe with administrator privileges, everything is fine.
  6. Click on the start menu and enter “regedit” in the search box. Click on regedit.exe, and then browse to HKEY_LOCAL_MACHINESYSTEMCurrentControlSetservices. There should be child folder there named MongoDB that has several keys inside it. If not, go back to step 4 and try again.
  7. The ImagePath key should read “c:mongobinmongod –service” right now; change it to  “c:mongobinmongod –service –dbpath c:mongodata”. This will allow MongoDB to find its data files.
  8. Click on the Start Menu and enter “services” in the search box. Click on the “Component Services” option.
  9. In the pane on the far left, double-click on “Services (Local).” Locate MongoDB in the list in the center pane, and double click on it to bring up the properties inspector window.
  10. Make sure “Startup type” is set to automatic. Then click on the “Start” button.
  11. Browse to http://localhost:28017/ to verify that MongoDB is really running.

ここまで、相変わらずめっちゃ簡単。

次にデータの用意。ここからが、本題やからね。

[やってみる]twitter日本語ユーザのソーシャルダンプ

前回のを参考に再度データ入れる。debianとの違いは、文字コードぐらいかな。

サーバーとしていたmachineから、取得しておいたdumpを持ってくる。

FTPをいれてなかったので、こちら参考にinstall & ftpd起動。dumpをコピーする。

そして、データ投入。

【procedure for Win7】
▼インスタンス起動
mongod.exe –dbpath C:mongodata
▼dump投入
mongorestore -d twitter C:mongodumptwitter –dbpath C:mongodata

profiles/friends共に、stats確認したところ、すべて作成できている。

ようやく分析環境構築完了。

あと、文字コードの設定をcmdにて行っておく。

>chcp 65001
UTF-8に変更

profilesで@utadahikaru を検索してみる。

> db.profiles.find({‘screen_name’:/utadahikaru/i},{‘name’: 1})
{ “_id” : ObjectId(“4d3c99ddb69fff50abeb565d”), “name” : “宇多田ヒカル” }
Failed to write to logfile: errno:0 ���������������������������������������������: 000000013F20B980
{ “_id” : ObjectId(“4c725f051d41c85ccb004aac”), “name” : “宇多田ヒカルbot” }
Failed to write to logfile: errno:0 ���������������������������������������������: 000000013F20B980

log書き込めてない。

friends で@utadahikaruを検索してみる。

> db.friends.find({‘internal_id’:174511656},{‘ids’: 1})
{ “_id” : ObjectId(“4d44ca312d2d5402709ec5d0”), “ids” : [ 185509698, 174544032 ] }

よーし今日は、ここまで。

やっと、いろいろ試せる環境できたよ。

bye

[Mickey]

>[Memo]MongoDB の使い方と問題点2つ

>

自分用に操作メモ。インスタンスといっていいのかわからんけど。

あ、カンケーいないけど、

↓あとでみよう。

▼インスタンス起動

./mongod &

debian:/usr/local/mongodb/bin# ps -ef | grep mongo
root     24743 10934  0 21:16 pts/3    00:00:00 ./mongod

▼起動確認

http://localhost:28017/
→モニタリングツール。

When you start mongod (the MongoDB daemon), it starts listening on two ports by default.

27017: the default port accessed by the various MongoDB drivers.
28017: a port that handles HTTP requests and provides some general monitoring.

▼DB接続(cli)

debian:~# cd /usr/local/mongodb/bin/
debian:/usr/local/mongodb/bin# ./mongo
MongoDB shell version: 1.6.5
connecting to: test
> use twitter
switched to db twitter
> db.profiles.find().limit(1);
error: {
“$err” : “can’t map file memory – mongo requires 64 bit build for larger datasets”,
“code” : 10084

}

XXX@debian:~$ du -h /data/db/
3.0G    /data/db/

※問題1

。。別マシンで動かすか、、

▼インスタンスを強制終了してしまった場合。

./mongod –dbpath=/data/db/ –repair

※lockファイルが出来上がっていたので、その場合はrepairコマンドで削除できるみたい。

▼DB切断(cli)

> exit
bye

▼インスタンス終了(debian)

kill -2 <pid>

こちら側は大丈夫。

▼インスタンス終了(cli)

debian:/usr/local/mongodb/bin# ./mongo
MongoDB shell version: 1.6.5
connecting to: test
> use admin
switched to db admin
> db.shutdownServer()
Tue Feb  8 21:26:18 query failed : admin.$cmd { shutdown: 1.0 } to: 127.0.0.1
server should be down…
Tue Feb  8 21:26:18 trying reconnect to 127.0.0.1
Tue Feb  8 21:26:18 reconnect 127.0.0.1 failed couldn’t connect to server 127.0.0.1
Tue Feb  8 21:26:18 MessagingPort say send() errno:9 Bad file descriptor 127.0.0.1:27017
Tue Feb  8 21:26:18 Error: error doing query: unknown (anon):1526

※問題2

こちら側は大丈夫でない。調べましょう。

——–

うーむ、問題1のほうは、

dumpファイルを別のDBに展開すればできるかな。

問題2の方は、あとでぐぐーる。

[Mickey]

>[いれたよ]WP Social Bookmarking Light

>各POSTに、social serviceへの投稿ボタンをつけれるプラグイン。

WP Social Bookmarking Light

やりかたは、以下のとおり。Very Easy !

  1. Upload this directory to the ‘wp-content/plugins/’ directory
  2. Activate the plugin through the ‘Plugins’ menu in WordPress
  3. Open ‘WP Social Bookmarking Light Options’ control panel through the ‘Settings’ menu and change configurations (This step is not required, the plugin has default settings)

[Mickey]

>[やってみる]twitter日本語ユーザのソーシャルダンプ

>こちらでtwitterの日本語ユーザのfollowinとプロフィールのダンプを提供していたので、使ってみることに。

下記概要。

プロフィール:

108万人分のスクリーンネームや自己紹介文

フォローイング:

103万人分のフォローイング先ID一覧です。

展開すると300万ノード 2.8億エッジになります。

▼MongoDBをインストール

ダンプのストレージにMongoDBを使うので、インストール。

手順(インストール〜終了まで)はこちらを参照にさせていただいた。
※MongoDBのサイトはこちら。twitterやFacebook,google groupがあるので、参加しよー。

▼ダンプを入れる。

ダンプの読み込みから操作までこちらにまとめられている。

▼使ってみる。

プロフィールの位置情報で、tokyo(大文字小文字とわず)なのは108万件の中で5万ちょいぐらい。

> db.profiles.find({‘location’: /tokyo/i}).count()
53888

nara(同じく)なのは108万件の中で800件。。。

> db.profiles.find({‘location’: /nara/i}).count()
792

ちょっと検索条件が悪いか。。要調査ですな。

まあいいや。なるほどーこれはおもろい!

いろいろできるでー

とりあえず、使い方は大体分かったので、以下引き続き調べたい。

  • followinの方が、dump読み込み時にエラーで読み込めてないので調査
  • mongodbの書き方がまだ不慣れ。もっと試す。
  • rubyやpythonから使えるようにする

[Mickey]