2. openshift [mtchang's wiki] 頁 2 / 16
* 送出後系統會發出確認信件到你的信箱,確認後會引導到網站並要求你卻認同意此機器的使用規範。。
* 確認完成後你的信箱會收到一封信件,告訴你下一步該如何做?
* 同這網址的內容 https://openshift.redhat.com/app/getting_started/express
[https://openshift.redhat.com/app/getting_started/express] ,因為這系統仍然不斷的在開發中,你可以透過
IRC: #openshift on Freenode [http://webchat.freenode.net/] 直接反映問題。
Thank you for requesting access to OpenShift Express!
To get started, click on this link:
https://openshift.redhat.com/app/getting_started/express
We'd love to hear your feedback, please join us on IRC and our forums.
Thanks
The Red Hat OpenShift Team
IRC: #openshift on Freenode
使用Express
file:///D:/mydoc_sync/mtchang/LCCNET/other/投稿/20110530_lccnet_mtchang_ope... 2012/11/25
3. openshift [mtchang's wiki] 頁 3 / 16
* 要開始使用 Express account 必須要有些 Client 端應用程式才可以連接到該服務主機,目前只有提供
command 指令模式的方式。
* 目前 Client 端有支援的為 RHEL 6 or Fedora or MAC or Windows ,但Mac 需鑰匙用 gem ,Windows
需要 cygwin 。看起來都很麻煩。
* Linux 目前只提供 RHEL 6 以上的版本來安裝,所以最後我選擇了 Fedora 15 [http://fedoraproject.org/]
這個版本來完成下面的實做:
file:///D:/mydoc_sync/mtchang/LCCNET/other/投稿/20110530_lccnet_mtchang_ope... 2012/11/25
5. openshift [mtchang's wiki] 頁 5 / 16
Fedora安裝rhc
* 將底下的 repo 檔案 openshift.repo 放到 /etc/yum.repos.d/ 目錄內
# 改變目錄
[root@localhost mtchang]# cd /etc/yum.repos.d/
# 新增 openshift repo 檔案
[root@localhost yum.repos.d]# vim openshift.repo
[openshift-express]
name=Openshift-express
baseurl=https://openshift.redhat.com/app/repo/rpms/$releasever/$basearch/
failovermethod=priority
skip_if_unavailable=1
gpgkey=https://openshift.redhat.com/app/repo/RPM-GPG-KEY-redhat-beta
ggpkey=https://openshift.redhat.com/app/repo/RPM-GPG-KEY-redhat-release
enabled=1
gpgcheck=1
# 安裝 rhc 工具
[root@localhost mtchang]# yum install rhc
* 檢查應用程式,系統主要使以 rhc-* 開頭的程式負責這些工作
[root@localhost ~]# rpm -ql rhc-0.68.5-1.el6.noarch
/etc/openshift/express.conf <-- 設定檔
/usr/bin/rhc-create-app <-- 負責應用程式建立
/usr/bin/rhc-create-domain <-- 負責 Domain 名稱建立及申請
/usr/bin/rhc-ctl-app <-- 控制應用程式啟動、停止、刪除....
/usr/bin/rhc-snapshot <-- 把應用程式打包成 gzip
/usr/bin/rhc-user-info <-- 顯示使用者在 rhcloud.com 的資訊
... 略.....
建立Domain
* 建立 domain ,使用 /usr/bin/rhc-create-domain 程式在 rhcloud 註冊一個 domain
* 註冊名稱為 jangmt 在雲端的使用者帳號為 jangmt@gmail.com
[jangmt@localhost ~]$ rhc-create-domain -n jangmt -l jangmt@gmail.com
Password: rhcloud的密碼
Generating Openshift Express ssh key to /home/jangmt/.ssh/libra_id_rsa
Generating public/private rsa key pair.
Created directory '/home/jangmt/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/jangmt/.ssh/libra_id_rsa.
Your public key has been saved in /home/jangmt/.ssh/libra_id_rsa.pub.
The key fingerprint is:
18:25:39:79:b5:88:87:9c:56:ab:35:6e:da:3b:4e:8b jangmt@localhost.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
| .oo.. |
| .+B.o . |
| Bo* . |
| . B . |
| o S |
| + |
| . o |
| o.o |
| E.+. |
+-----------------+
Contacting https://openshift.redhat.com
Adding rhlogin to /home/jangmt/.openshift/express.conf
Creation successful
You may now create an application. Please make note of your local config file
in /home/jangmt/.openshift/express.conf which has been created and populated for you.
* 這動作會建立一組 ssh key 來提供程式開發上 git 的存取。
建立PHP應用程式
file:///D:/mydoc_sync/mtchang/LCCNET/other/投稿/20110530_lccnet_mtchang_ope... 2012/11/25
6. openshift [mtchang's wiki] 頁 6 / 16
* 建立應用程式 /usr/bin/rhc-create-app ,目前系統提供 php-5.3.2, wsgi-3.2.1, rack-1.1.0 三種選項的
應用程式可以選擇。
* 底下為建立一個應用程式 myphp 提供 php-5.3.2 的應用程式功能
[jangmt@localhost ~]$ rhc-create-app -a myphp -t php-5.3.2 -l jangmt@gmail.com
Password:
Please support the developer preview - let #openshift on freenode know of any
bugs you find
Creating remote application space: myphp
Contacting https://openshift.redhat.com
RESULT:
Successfully created application: myphp
Checking ~/.ssh/config
Contacting https://openshift.redhat.com
Found rhcloud.com in ~/.ssh/config... No need to adjust
Now your new domain name is being populated worldwide (this might take a minute)...
Pulling new repo down
Warning: Permanently added the RSA host key for IP address '50.17.172.80' to the list of known hosts.
remote: Counting objects: 23, done.
remote: Compressing objects: 100% (20/20), done.
remote: Total 23 (delta 6), reused 0 (delta 0)
Receiving objects: 100% (23/23), done.
Resolving deltas: 100% (6/6), done.
Confirming application myphp is available
Attempt # 1
Success! Your application is now published here:
http://myphp-jangmt.rhcloud.com/
The remote repository is located here:
ssh://a0aaf4b1ba3f4f3dbf7abd14c64fa89f@myphp-jangmt.rhcloud.com/~/git/myphp.git/
To make changes to your application, commit to myphp/.
Then run 'git push' to update your Openshift Express space
* 此程式會將剛剛的金鑰上傳到遠端機器,並且再本機建立一個目錄 ~/myphp 。此目錄可以透過 git 的SCM
管理方式管理程式碼。
* 並且建立一個應用程式名稱的對應網域 http://myphp-jangmt.rhcloud.com/ [http://myphp-
jangmt.rhcloud.com/] ,當修改完程式後只需使用 git push 程式到遠端主機即可完成上傳程式碼的工作。
* 第一次建立好,都沒有修改的畫面如下:http://myphp-jangmt.rhcloud.com/ [http://myphp-
jangmt.rhcloud.com/]
* 修改 index.php 加上 phpinfo(); 並git push 上 server
file:///D:/mydoc_sync/mtchang/LCCNET/other/投稿/20110530_lccnet_mtchang_ope... 2012/11/25
7. openshift [mtchang's wiki] 頁 7 / 16
# 本地端產生 ~/myphp 的目錄,程式統一放在 ~/myphp/php 目錄內
[jangmt@localhost php]$ cd /home/jangmt/myphp/php/
[jangmt@localhost php]$ pwd
/home/jangmt/myphp/php
# 修改程式碼,加入 <?php phpinfo(); ?> 這段做為測試
[jangmt@localhost php]$ vim index.php
<html><title>OpenShift!</title>
<body>
<h1>Welcome to OpenShift</h1>
<p>Place your application here</p>
<p>In order to commit to your new project, go to your projects git repo
(created with the create_http command). Make your changes, then run:</p>
<pre>git commit -a -m 'Some commit message'
git push</pre>
<p>Then reload this page</p>
<?php phpinfo(); ?>
</body>
</html>
* 加上 commit 資訊並 git push
# git commit -a 將所有修改過得檔案都 commit, 但是新增的檔案 還是得要先 add 才可以(git add -A 新增所有變更的檔案)
# -m 'message' 指的是在這個 commit 加上說明的內容
[jangmt@localhost php]$ git commit -a -m 'add phpinfo() in index.php'
[master a7aaf2b] add phpinfo() in index.php
1 files changed, 1 insertions(+), 0 deletions(-)
# git-push 更新遠端的檔案物件資訊
[jangmt@localhost php]$ git push
Counting objects: 7, done.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 399 bytes, done.
Total 4 (delta 2), reused 0 (delta 0)
remote: tar: README: time stamp 2011-05-31 07:51:47 is 28761.007922033 s in the future
remote: tar: libs/README: time stamp 2011-05-31 07:51:47 is 28761.00683967 s in the future
remote: tar: libs: time stamp 2011-05-31 07:51:47 is 28761.006520158 s in the future
remote: tar: misc/README: time stamp 2011-05-31 07:51:47 is 28761.006146669 s in the future
remote: tar: misc: time stamp 2011-05-31 07:51:47 is 28761.005907377 s in the future
remote: tar: php/health_check.php: time stamp 2011-05-31 07:51:47 is 28761.005505289 s in the future
remote: tar: php/index.php: time stamp 2011-05-31 07:51:47 is 28761.005190215 s in the future
remote: tar: php: time stamp 2011-05-31 07:51:47 is 28761.004967428 s in the future
To ssh://a0aaf4b1ba3f4f3dbf7abd14c64fa89f@myphp-jangmt.rhcloud.com/~/git/myphp.git/
ebb33fa..a7aaf2b master -> master
* 上傳更新完成,再看一次網頁內容
* Git 是分散式的版本控制系統,可以方便的用於程式碼的管理。Git目前為很多自由軟體專案的版本控制工具,
與常用的版本控制工具CVS,Subversion 不同,它採用了分散式版本庫的方式,不必伺服器端軟體也可以存取所
以使得原始碼的發布和交流更方便。
file:///D:/mydoc_sync/mtchang/LCCNET/other/投稿/20110530_lccnet_mtchang_ope... 2012/11/25
8. openshift [mtchang's wiki] 頁 8 / 16
安裝Drupal
* 既然可以使用 php 的功能在伺服器上,這裡以 Drupal 這個很受歡迎的的內容管理系統當作範例,安裝到
openshift 服務上。 * Drupal 是一個自由開源的內容管理系統,以PHP語言寫成。後端的資料庫為MySQL或
PostgreSQL,在7.0版本以後開始支援SQLite資料庫。 * 因為此服務沒有提供資料庫的功能,所以直接使用
SQLite 用檔案型態的資料庫當城後端資料庫。
* 將檔案放到跟目錄,並且修改設定檔。
# 抓最新的版本
[jangmt@localhost php]$ wget wget http://ftp.drupal.org/files/projects/drupal-7.2.tar.gz
# 解開
[jangmt@localhost php]$ tar zxf drupal-7.2.tar.gz
# 搬動
[jangmt@localhost php]$ mv drupal-7.2/.* .
mv: cannot move `drupal-7.2/.' to `./.': Device or resource busy
mv: cannot move `drupal-7.2/..' to `./..': Device or resource busy
[jangmt@localhost php]$ mv drupal-7.2/* .
# 刪除
[jangmt@localhost php]$ rm -rf drupal-7.2 drupal-7.2.tar.gz
# 修改設定檔
[jangmt@localhost php]$ vim sites/default/default.settings.php
$base_url = 'http://myphp-jangmt.rhcloud.com';
* 更新上傳修改的程式碼
# 增加有新增的檔案到索引內
[jangmt@localhost php]$ git add -A
# 新增修改的的訊息及變動的檔案
[jangmt@localhost php]$ git commit -a -m "drupal to http://myphp-jangmt.rhcloud.com/"
[master 36c5a3a] drupal to http://myphp-jangmt.rhcloud.com/
998 files changed, 290732 insertions(+), 11 deletions(-)
create mode 100644 php/.gitignore
create mode 100644 php/.htaccess
...skip...
# 上傳
[jangmt@localhost php]$ git push
...skip...
remote: tar: php: time stamp 2011-05-31 08:00:29 is 28702.719547983 s in the future
To ssh://a0aaf4b1ba3f4f3dbf7abd14c64fa89f@myphp-jangmt.rhcloud.com/~/git/myphp.git/
a7aaf2b..36c5a3a master -> master
* 完成後,可是在進入剛剛的網址觀看,他即會進入安裝畫面。
* 請選擇標準安裝 standard
file:///D:/mydoc_sync/mtchang/LCCNET/other/投稿/20110530_lccnet_mtchang_ope... 2012/11/25
14. openshift [mtchang's wiki] 頁 14 / 16
刪除應用程式
* 目前 Openshift express 只支援使用者同時擁有一個應用程式,所以如果需要測試另外一種應用程式服務,
只能將這個裝好的服務移除再行安裝。
* /usr/bin/rhc-ctl-app 指令提供應用程式 (start|stop|restart|reload|status|destroy) 這些功能,底下範
例為使用 destroy 刪除剛註冊的應用程式。
[jangmt@localhost ~]$ rhc-ctl-app -c destroy -a myphp -l jangmt@gmail.com
Password:
Contacting https://openshift.redhat.com
!!!! WARNING !!!! WARNING !!!! WARNING !!!!
You are about to destroy the myphp application.
This is NOT reversable, all remote data for this application will be removed.
Do you want to destroy this application (y/n): y
Contacting https://openshift.redhat.com
RESULT:
Successfully destroyed application: myphp
* 當你 destory 應用程式只會移除雲端的資料,本地端的目錄還是一樣存在不會有任何的異動。
建立wsgi應用程式
* Python網頁開發的標準: WSGI,(Python Web Server Gateway Interface,縮寫為WSGI)是為Python
語言定義的Web伺服器和Web應用程序或框架之間的一種簡單而通用的介面。
* 建立一個 wsgi 應用程式,這程式會在本機 ~/mywsgi/ 建立一個目錄和上面 php 的開發方式一樣需要透過
git 更新程式。
[jangmt@localhost ~]$ rhc-create-app -a mywsgi -t wsgi-3.2.1 -l jangmt@gmail.com
Password:
Please support the developer preview - let #openshift on freenode know of any
bugs you find
Creating remote application space: mywsgi
Contacting https://openshift.redhat.com
RESULT:
Successfully created application: mywsgi
Checking ~/.ssh/config
Contacting https://openshift.redhat.com
Found rhcloud.com in ~/.ssh/config... No need to adjust
Now your new domain name is being populated worldwide (this might take a minute)...
Pulling new repo down
Warning: Permanently added 'mywsgi-jangmt.rhcloud.com,50.17.156.80' (RSA) to the list of known hosts.
remote: Counting objects: 30, done.
remote: Compressing objects: 100% (25/25), done.
remote: Total 30 (delta 9), reused 0 (delta 0)
Receiving objects: 100% (30/30), done.
Resolving deltas: 100% (9/9), done.
Confirming application mywsgi is available
Attempt # 1
Success! Your application is now published here:
http://mywsgi-jangmt.rhcloud.com/
The remote repository is located here:
ssh://a0aaf4b1ba3f4f3dbf7abd14c64fa89f@mywsgi-jangmt.rhcloud.com/~/git/mywsgi.git/
To make changes to your application, commit to mywsgi/.
Then run 'git push' to update your Openshift Express space
* 建立好的 wsgi 應用程式網站 http://mywsgi-jangmt.rhcloud.com/ [http://mywsgi-
jangmt.rhcloud.com/]
file:///D:/mydoc_sync/mtchang/LCCNET/other/投稿/20110530_lccnet_mtchang_ope... 2012/11/25
15. openshift [mtchang's wiki] 頁 15 / 16
* 修改預設的 application 這只程式,成為最簡單的 hello world (透過 wsgi方式呈現)。
[jangmt@localhost mywsgi]$ pwd
/home/jangmt/mywsgi
# 修改程式內容
[jangmt@localhost mywsgi]$ vim wsgi/application
def simplestApp(environ, start_response):
start_response('200 OK',[('Content-type','text/plain')])
return ['Hello world!']
# 指定輸出app
application = simplestApp
# 更新修改
[jangmt@localhost mywsgi]$ git commit -a -m 'simplest APP test'
[master 95b7a2b] simplest APP test
1 files changed, 5 insertions(+), 36 deletions(-)
rewrite wsgi/application (99%)
# git上傳
[jangmt@localhost mywsgi]$ git push
Counting objects: 7, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 422 bytes, done.
Total 4 (delta 1), reused 0 (delta 0)
remote: tar: README: time stamp 2011-05-31 08:47:47 is 28763.774683407 s in the future
remote: tar: data/SAFETOREMOVE.txt: time stamp 2011-05-31 08:47:47 is 28763.773869298 s in the future
remote: tar: data: time stamp 2011-05-31 08:47:47 is 28763.773712804 s in the future
remote: tar: libs/SAFETOREMOVE.txt: time stamp 2011-05-31 08:47:47 is 28763.773307896 s in the future
remote: tar: libs: time stamp 2011-05-31 08:47:47 is 28763.773183541 s in the future
remote: tar: wsgi/application: time stamp 2011-05-31 08:47:47 is 28763.772759805 s in the future
remote: tar: wsgi: time stamp 2011-05-31 08:47:47 is 28763.772630393 s in the future
To ssh://a0aaf4b1ba3f4f3dbf7abd14c64fa89f@mywsgi-jangmt.rhcloud.com/~/git/mywsgi.git/
73ae5b9..95b7a2b master -> master
* hello world 的結果
file:///D:/mydoc_sync/mtchang/LCCNET/other/投稿/20110530_lccnet_mtchang_ope... 2012/11/25