Contents


皆様こんにちは。
大好評(ウソ)の『試してみた』シリーズ第3弾は『OpenShift』を試してみました。

OpenShift とは

OpenShift』は皆様にとっておなじみの Red Hat が運営するクラウドサービスです。
PHP, Python, Ruby という人気言語および、それらのフレームワークが使えます。

プランは以下の3種類。

・EXPRESS
誰でも簡単に登録・利用できる軽量プラン。
PHP, Python, Ruby が使えます。
オートスケールやモニタリングもなく、単にアプリケーションを動かすだけ・と言った感じ。

・FLEX
EXPRESS から一つ上に上がったプラン。
PHP, Java EE が使え、MySQL, MongoDB などのデータベース使用できます。
さらには Memcache, DFS も用意されています。
オートスケーリングやモニタリングまでついてこのお値段!(無料)

ただ、FLEXプランを利用するには Amazon EC2 アカウントが必要…
私は持ってません…
使ってみたいな〜

・POWER
最上位プラン。
6/9現在はまだ準備中です。
案内を見る限り、root でアクセスできるみたい。
コントロールモニターも付いてるっぽいし。
有料になりそうな予感。

今回はこの中でお手軽な『EXPRESS』プランを試してみます。

ユーザー登録

サイトの右上にある『TRY IT NOW!』ボタンをクリック。

ユーザー登録フォームの画面に移動します。

メールアドレスと希望のパスワードを入力。
CAPTCHA を入力して Register Now!
メール送ったよ。見てね!・と表示されます。

以下のような登録確認メールが届くので、記載されているリンクをクリックします。

表示されたログインフォームに先ほど登録したメールアドレスとパスワードを入力してログイン。

使用許諾を読んで同意してね!・と表示されるので、

しっかり読んでから同意【I Accept】をクリックします。

これで登録は完了です。
以下のようなメールが届きます。

クライアントツールのインストール

登録が完了するとログインのたびに『Get Started』のページが表示されます。

ここに書かれている通り進めば良いだけなんですけどね。
一応手順をば。

クライアントツールのインストール

OpenShift はコマンドラインからクライアントツールを使って操作します。
rhc- で始まるコマンド。
まずはそのコマンドをインストール。
必要なもの(Mac の場合)
・XCode
・Ruby
Mac には標準で Ruby が入ってるので XCode だけ用意すればOK。
さてインストール。
クライアントツールは Ruby 製です。
このために Ruby がいる。
gem で簡単インストール!

$ sudo gem install rhc
Password:
Successfully installed rhc-0.71.2
1 gem installed
Installing ri documentation for rhc-0.71.2...
Installing RDoc documentation for rhc-0.71.2...

ほんとに簡単。

ドメインを決める

いよいよデビュー。
ドメイン名を決めましょ。
同時に SSH Key が作られます。

Ex.【rnsk】というドメイン名を作る

$ rhc-create-domain -n rnsk -l dmain@example.com

Created local config file: /Users/xxxx/.openshift/express.conf
express.conf contains user configuration and can be transferred across clients.

Password:
Generating Openshift Express ssh key to /Users/xxxx/.ssh/libra_id_rsa
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/xxxx/.ssh/libra_id_rsa.
Your public key has been saved in /Users/xxxx/.ssh/libra_id_rsa.pub.
The key fingerprint is:
・・・
・・・
・・・
Creation successful

You may now create an application.  Please make note of your local config file
in /Users/xxxx/.openshift/express.conf which has been created and populated for you.

/Users/xxxx/.openshift/express.conf も同時に作られ、ログイン情報が保存されます。
なにもしなくていい…

アプリケーションスペースの作成

勢いに任せてアプリケーションのスペースを作りましょ。
rhc-create-app で作成します。
以下必須。

【-a】がアプリケーション名です。
半角英数字で16文字までの名前を付けられます。
アプリケーション名はサブドメインみたいになります。
(実際にはドメイン名にハイフンで繋がる)
↓こんなURLになる
<your app name>-<your domain name>.rhcloud.com

【-t】が利用できるサービスになります。
PHP を利用する場合:php-5.3.2
Python を利用する場合:wsgi-3.2.1
Ruby を利用する場合:rack-1.1.0

アプリケーション作成の際に選択することでそれぞれが利用できるようになります。

Ex.【www】という名前のPHPアプリケーションスペースを作る

$ rhc-create-app -a www -t php-5.3.2
Password:

Found a bug? Post to the forum and we'll get right on it.
IRC: #openshift on freenode
Forums: https://www.redhat.com/openshift/forums

Creating remote application space: www
Contacting https://openshift.redhat.com

RESULT:
Successfully created application: www

Checking ~/.ssh/config
Contacting https://openshift.redhat.com
Could not find /Users/xxxx/.ssh/config.  This is ok, continuing
Adding rhcloud.com to ~/.ssh/config
Now your new domain name is being populated worldwide (this might take a minute)...
Pulling new repo down
Warning: Permanently added '
www-rnsk.rhcloud.com,xx.xx.xxx.xx' (RSA) to the list of known hosts.
Confirming application www is available
Attempt # 1

Success!  Your application is now published here:

http://www-rnsk.rhcloud.com/

The remote repository is located here:

ssh://~

To make changes to your application, commit to www/.
Then run '
git push' to update your Openshift Express space

ブラウザでアクセス!
なんかかっこいいページが表示された。

あとはアプリ作って push!

お決まりの『こんにちは、世界』

アプリケーションスペースを作成した際に表示された ssh://~ が Git リポジトリのアドレスです。
clone してみましょ。

$ mkdir OpenShift
$ cd OpenShift
$ git clone ssh://~
Cloning into www...
remote: Counting objects: 8, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 8 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (8/8), 12.27 KiB, done.

アプリケーション名と同じ名前のディレクトリができてます。
中身はこんな感じ

この中の『PHP』ディレクトリの中が公開されます。
ホームディレクトリってやつかな。

せっかくかっこいいページですが、お決まりに沿って変えちゃいましょ。

$ vi php/index.php
修正・・・
$ git commit -a -m "hello world"
[master b913336] hello world
 1 files changed, 1 insertions(+), 298 deletions(-)
 rewrite php/index.php (100%)

迷わず push だ!

$ git push
Counting objects: 7, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 367 bytes, done.
Total 4 (delta 1), reused 0 (delta 0)
To ssh://~
   0d537cd..b913336  master -> master

そして確認。

できた。
味気ない…

おわりに

相変わらず PaaS はあっさりさっくり使えるようになります。
ただ EXPRESS プランはデータベース使えないから作るアプリケーションが限られますね。
外部で用意するとかかな〜?

ではまた。

Comments are closed.