情報源
■公式サイト
https://openshift.redhat.com/app/
■公式ドキュメント
https://openshift.redhat.com/community/documentation
・Release Notes
・Getting Started Guide
・User Guide
・OpenShift API Guide
■クライアントツール類
https://openshift.redhat.com/app/getting_started
■GitHub - OpenShift Origin
https://github.com/openshift
■Wiki
https://openshift.redhat.com/community/open-source
■Live CD
https://openshift.redhat.com/community/wiki/getting-started-with-openshift-origin-livecd
Live CD メディアをDLするには https://openshift.redhat.com/app/account/new からアカウント登録をしておく必要がある。
(このアカウントを作ると、RedHatが提供しているβ版のOpenShiftのPaaS環境を利用できるようにもなる)
Live CDでの確認
Live CDを使うと、仮想マシン上で、かつインストール作業を行わずOpenShiftを動かすことができます。
以下、KVM上で試しています。
起動画面
起動完了。Fedora16ベースのようです。
DHCPが使える環境であれば、ネットワークも使えます。KVMのコンソールで直接操作するのは不便なので外からSSHできるようにしておきます(Live CDなので再起動すれば消えます)
sshのポートが閉じられているので開けておきます。
liveuser@live$ su -
root@live# iptables -I INPUT 1 -p tcp --dport 22 -j ACCEPT
最初から存在するユーザが全てパスワードが設定されておらずSSHログインできないので、新しいユーザを作っておきます。
root@live# useradd user01
root@live# passwd user01
これでLive CD上で操作するのと同じように操作できます。
host# ssh user01@livehost
user01@live$ su - liveuser
liveuser@live$
環境を作ってみる(simple php)
admin/adminというユーザが最初に存在するので、これを作って最初のドメインを作成する。
この時に、SSHキーの作成が行われるが、これを「空」にすると失敗するようだ(原因は面倒なので未調査
$ rhc domain create -n mydomain -l admin
Password: admin Generating OpenShift ssh key to /home/liveuser/.ssh/libra_id_rsa Generating public/private rsa key pair. Created directory '/home/liveuser/.ssh'. Enter passphrase (empty for no passphrase): password Enter same passphrase again: password Your identification has been saved in /home/liveuser/.ssh/libra_id_rsa. Your public key has been saved in /home/liveuser/.ssh/libra_id_rsa.pub. The key fingerprint is: 9f:22:fd:4d:1a:f2:52:ce:1b:90:48:bf:7e:6a:f3:d6 liveuser@localhost The key's randomart image is: +--[ RSA 2048]----+ | | | | | . | | . o . | | . S | | . +.. | | . =+=.. | | o+==*E | | .oB*.. | +-----------------+ Checking ~/.ssh/config Could not find /home/liveuser/.ssh/config. This is ok, continuing Adding example.com to ~/.ssh/config Creation successful You may now create an application.
$ rhc domain show -l admin
Password: admin User Info ========= Namespace: mydomain RHLogin: admin Application Info ================ No applications found. You can use 'rhc app create' to create new applications.
実行環境を作成する。作成する環境は -t で指定する。
-t|--type type Type of app to create (jenkins-1.4, ruby-1.8, jbossas-7, nodejs-0.6, perl-5.10, php-5.3, diy-0.1, python-2.6) (required for creating an application)
実行環境を作成。
$ rhc app create -a myapp -t php-5.3
Password: admin Creating application: myapp in mydomain Now your new domain name is being propagated worldwide (this might take a minute)... Warning: Permanently added 'myapp-mydomain.example.com' (RSA) to the list of known hosts. Enter passphrase for key '/home/liveuser/.ssh/libra_id_rsa': password Confirming application 'myapp' is available: Success! myapp published: http://myapp-mydomain.example.com/ git url: ssh://[email protected]/~/git/myapp.git/ Successfully created application: myapp
作成された実行環境の情報は以下
$ rhc app show -a myapp
Password: admin Application Info ================ myapp Framework: php-5.3 Creation: 2012-05-27T06:55:54-04:00 UUID: 0d7533f49ca349db98312c519a6ecf0d Git URL: ssh://[email protected]/~/git/myapp.git/ Public URL: http://myapp-mydomain.example.com/ Embedded: None
上記のURLへアクセスすると以下の画面が表示される。
GitのURLが表示されているように、この実行環境はGitを経由してソースを管理できる。
$ cd
$ mkdir project
$ cd project
$ git clone ssh://[email protected]/~/git/myapp.git/
Cloning into 'myapp'... Enter passphrase for key '/home/liveuser/.ssh/libra_id_rsa': password remote: Counting objects: 25, done. remote: Compressing objects: 100% (19/19), done. remote: Total 25 (delta 1), reused 25 (delta 1) Receiving objects: 100% (25/25), 6.98 KiB, done. Resolving deltas: 100% (1/1), done.
$ cd myapp/
$ ll
total 16 -rw-rw-r--. 1 liveuser liveuser 0 May 27 07:06 deplist.txt drwxrwxr-x. 2 liveuser liveuser 4096 May 27 07:06 libs drwxrwxr-x. 2 liveuser liveuser 4096 May 27 07:06 misc drwxrwxr-x. 2 liveuser liveuser 4096 May 27 07:06 php -rw-rw-r--. 1 liveuser liveuser 2272 May 27 07:06 README
トップ画面のデカデカと表示されている「OpenShift」の部分を変更してみる。
$ vim php/index.php
<div class="brand-text"><strong>Open</strong>Shift</div> ↓ <div class="brand-text"><strong>MyAPP</strong>MyDomain</d
Welcome to OpenShift ↓ Welcome to MyApp-MyDomain
$ git add -u
$ git commit
$ git log
commit 9869b40b2995710d31f10c329e0535e6efe1c532 Author: Live System User <[email protected]> Date: Sun May 27 07:17:46 2012 -0400 change title commit 745fcd719255ea4e6c9b84972a7298c37090e33e Author: Template builder <[email protected]> Date: Sat Apr 28 20:44:49 2012 -0400 Creating template
$ git push
Enter passphrase for key '/home/liveuser/.ssh/libra_id_rsa': password Counting objects: 7, done. Compressing objects: 100% (4/4), done. Writing objects: 100% (4/4), 412 bytes, done. Total 4 (delta 2), reused 0 (delta 0) remote: Stopping application... remote: Waiting for stop to finish remote: Done remote: ~/git/myapp.git ~/git/myapp.git remote: ~/git/myapp.git remote: Running .openshift/action_hooks/pre_build remote: Running .openshift/action_hooks/build remote: Running .openshift/action_hooks/deploy remote: Starting application... remote: Done remote: Running .openshift/action_hooks/post_deploy To ssh://[email protected]/~/git/myapp.git/ 745fcd7..9869b40 master -> master
pushした内容が実行環境上で反映される。
複合実行環境を作成する(python/wsgi + mongodb + cron)
まずPython環境を作成する。
$ rhc app create -a mypyapp -t python-2.6
Password: admin Creating application: mypyapp in mydomain Now your new domain name is being propagated worldwide (this might take a minute)... Warning: Permanently added 'mypyapp-mydomain.example.com' (RSA) to the list of known hosts. Enter passphrase for key '/home/liveuser/.ssh/libra_id_rsa': password Confirming application 'mypyapp' is available: Success! mypyapp published: http://mypyapp-mydomain.example.com/ git url: ssh://[email protected]/~/git/mypyapp.git/ Successfully created application: mypyapp
$ rhc app show -a mypyapp
Password: admin Application Info ================ mypyapp Framework: python-2.6 Creation: 2012-05-27T07:44:45-04:00 UUID: f30eac9f479e4f05b951f6d0ec3e00db Git URL: ssh://[email protected]/~/git/mypyapp.git/ Public URL: http://mypyapp-mydomain.example.com/ Embedded: None
追加できるリソース(カードリッジ)を確認する。
$ rhc app cartridge list
List of supported embedded cartridges: Obtaining list of cartridges (please excuse the delay)... mysql-5.1, cron-1.4, 10gen-mms-agent-0.1, mongodb-2.0, jenkins-client-1.4, phpmyadmin-3.4
mongodbを追加。成功するとパスワード等が生成されるのでメモっておく。
$ rhc app cartridge add -c mongodb-2.0 -a mypyapp
Password: admin RESULT: MongoDB 2.0 database added. Please make note of these credentials: Root User: admin Root Password: gbx11ELvgu8F Database Name: mypyapp Connection URL: mongodb://127.0.251.1:27017/ You can manage your new MongoDB by also embedding rockmongo-1.1
$ rhc app show -a mypyapp
Password: admin Application Info ================ mypyapp Framework: python-2.6 Creation: 2012-05-27T07:44:45-04:00 UUID: f30eac9f479e4f05b951f6d0ec3e00db Git URL: ssh://[email protected]/~/git/mypyapp.git/ Public URL: http://mypyapp-mydomain.example.com/ Embedded: mongodb-2.0 - Connection URL: mongodb://127.0.251.1:27017/
さらにcronを追加
$ rhc app cartridge add -c cron-1.4 -a mypyapp
Password: admin RESULT: cron-1.4 added to application mypyapp To schedule your scripts to run on a periodic basis, add the scripts to your application's .openshift/cron/{minutely,hourly,daily,weekly,monthly}/ directories (and commit and redeploy your application). Example: A script .openshift/cron/hourly/crony added to your application will be executed once every hour. Similarly, a script .openshift/cron/weekly/chronograph added to your application will be executed once every week.
$ rhc app show -a mypyapp
Password: admin Application Info ================ mypyapp Framework: python-2.6 Creation: 2012-05-27T07:44:45-04:00 UUID: f30eac9f479e4f05b951f6d0ec3e00db Git URL: ssh://[email protected]/~/git/mypyapp.git/ Public URL: http://mypyapp-mydomain.example.com/ Embedded: cron-1.4 mongodb-2.0 - Connection URL: mongodb://127.0.251.1:27017/
phpの時と同様に、gitでソースを管理できる。
$ cd ~/project/
$ git clone ssh://[email protected]/~/git/mypyapp.git/
Cloning into 'mypyapp'... Enter passphrase for key '/home/liveuser/.ssh/libra_id_rsa': password remote: Counting objects: 28, done. remote: Compressing objects: 100% (21/21), done. remote: Total 28 (delta 1), reused 28 (delta 1) Receiving objects: 100% (28/28), 8.20 KiB, done. Resolving deltas: 100% (1/1), done.
$ cd mypyapp/
$ find . |grep -v ".git"
. ./README ./.openshift ./.openshift/markers ./.openshift/markers/README ./.openshift/cron ./.openshift/cron/daily ./.openshift/cron/minutely ./.openshift/cron/hourly ./.openshift/cron/monthly ./.openshift/cron/README.cron ./.openshift/cron/weekly ./.openshift/cron/weekly/README ./.openshift/cron/weekly/chrono.dat ./.openshift/cron/weekly/jobs.deny ./.openshift/cron/weekly/chronograph ./.openshift/cron/weekly/jobs.allow ./.openshift/action_hooks ./.openshift/action_hooks/build ./.openshift/action_hooks/post_deploy ./.openshift/action_hooks/pre_build ./.openshift/action_hooks/deploy ./wsgi ./wsgi/application ./wsgi/static ./wsgi/static/README ./data ./setup.py ./libs
./wsgi/application を編集することでWSGIのアプリケーションを作成できる。
今回はここまで。今後、調査事項として以下を予定。
・OpenShiftの構造
・1からの構築
・github連携
・IaaS連携(オートスケール等)
・任意のフレームワークやカードリッジの追加
いつになるかわからないけど。。。
0 件のコメント:
コメントを投稿