雲端服務是目前常見對於網路服務應用運作模式的稱謂,大多數的使用者很難清楚的定義何謂雲端?在
美國國家標準與技術研究院(NIST)對於雲端運算提出了一份明確的定義, 雲端運算是一種網路應用的運作模式,其需求能夠方便存取網路上所提供的電腦資源,其包含5種特徵、4種建置模式、3項服務,比較常見的有3種服務模式 (SaaS)軟體即服務、(PaaS)平台即服務、(IaaS)基礎設施即服務以及4種建置方式 Public cloud(公共雲), Private cloud(私有雲), Community cloud(社區雲), Hybrid cloud(混合雲),另外有五種特徵可以評估該服務是不是雲端服務的重要項目,分別是(1)On-demand self-service(需要時自助的取得)(2)Broad network access(可以透過標準網路取得)(3)Resource pooling(資源可以動態配置)(4)Rapid elasticity,(快速且有彈性)(5)Measured Service(用多少付多少)。
Red Hat(紅帽)提出新的平台即服務(PaaS)、及架構及服務(IaaS)的解決方案 OpenShift,讓使用者可以專心於軟體的應用而不是基礎設施的建設。OpenShift的基礎來源於Red Hat於2010年11月收購的科技公司Makara technology。目前OpenShift 提供三種不同的部屬應用程序,開發人員可以快速的透過此服務建立開發平台,而無須架設任何伺服器。OpenShift Express 提供用來開發 PHP、Ruby、Python 和 Java 等軟體的應用程式環境,另外有 OpenShift FLEX 和 OpenShit Power 等服務,OpenShift FLEX 預計供部署、監控、預備用和自動擴充與縮減的應用系統,而 OpenShift Power 是部署自己所建置的 Linux,目前 FLEX 和 Power 服務目前是還在開發中,只有 OpenShift FLEX 有開放免費使用,OpenShift Flex 提用試用,而 OpenShift Power 還在開發中。
本文目的則以OpenShift Express 的申請及如何使用,並且建立可以用的CMS系統的過程做說明。
* OpenShift Express 目前提供有 php-5.3.2, wsgi-3.2.1, rack-1.1.0 and jbossas-7.0.0 三種服務,底下已申請一個PHP 應用程式服務為範例。 * 目前系統提供 RHN account 登入,如果你已經有 RHN 帳號可以直接登入使用。沒有的使用者請先註冊 成為一個新的使用者。
* 送出後系統會發出確認信件到你的信箱,確認後會引導到網站並要求你卻認同意此機器的使用規範。。
* 確認完成後你的信箱會收到一封信件,告訴你下一步該如何做? * 同這網址的內容
https://openshift.redhat.com/app/getting_started/express ,因為這系統仍然不斷的在開發中,你可以透過
IRC: #openshift on Freenode 直接反映問題。
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
* 要開始使用 Openshift Express account 必須要有些 Client 端應用程式才可以連接到該服務主機,目前只有提供 command 指令模式的方式。
* 目前 Client 端有支援的為 RHEL 6 or Fedora or MAC or Windows ,但Mac 需鑰匙用 gem ,Windows 需要 cygwin 。看起來都很麻煩。
* Linux 目前只提供 RHEL 6 以上的版本來安裝,所以最後我選擇了
Fedora 15 這個版本來完成下面的實做:
* 將底下的 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 ,使用 /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 的存取。
* 建立應用程式 /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管理方式管理程式碼。
* 修改 index.php 加上 phpinfo(); 並git push 上 server
# 本地端產生 ~/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 不同,它採用了分散式版本庫的方式,不必伺服器端軟體也可以存取所以使得原始碼的發布和交流更方便。
* 既然可以使用 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
* 選擇安裝的語系,
請不要增加中文語系安裝,因為中文語系的翻譯檔有問題安裝到一半會卡住。 * 資料庫請選擇 SQLite
* 接下來進進入模組的安裝過程了
* 網站設定頁面
* 安裝完成
* dokuwiki 是一套只需要 php 語言支援的 wiki 程式,後端存放資料是以文字檔型態儲存並且可以具有可閱讀性,非常適合在這樣的環境中使用。 * 安裝過程
# 取得軟體,放到根目錄
[jangmt@localhost php]$ wget http://www.splitbrain.org/_media/projects/dokuwiki/dokuwiki-2011-05-25.tgz
# 解開
[jangmt@localhost php]$ tar zxf dokuwiki-2011-05-25.tgz
# 更名為 wiki
[jangmt@localhost php]$ mv dokuwiki-2011-05-25 wiki
# 刪除原本的檔案及目錄
[jangmt@localhost php]$ rm dokuwiki-2011-05-25.tgz
# git 新增檔案
[jangmt@localhost php]$ git add -A
# git 新增修改及註解
[jangmt@localhost php]$ git commit -a -m 'add dukewiki in /wiki/'
# git 上傳
[jangmt@localhost php]$ git push
* 還真是快呀!!!!!!
* 目前 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 應用程式只會移除雲端的資料,本地端的目錄還是一樣存在不會有任何的異動。
* 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
* 修改預設的 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 的結果
* 第二個例子
[jangmt@localhost mywsgi]$ vim wsgi/application
import cgi
def application(environ, start_response):
form = cgi.FieldStorage(fp=environ['wsgi.input'],
environ=environ,
keep_blank_values=1)
write = start_response('200 OK', [('Content-type', 'text/html')])
if form.getvalue('name'):
write('<html><head><title>Hello!</title></head>\n')
write('<body>\n')
write('<h1>Hello %s!</h1>\n' % form['name'].value)
else:
write('<html><head><title>Who is there?</title></head>\n')
write('<body>\n')
write('<h1>Who is there?</h1>\n')
write('<form action="%s" method="POST">\n' % environ['SCRIPT_NAME'])
write('What is your name?<br>\n')
write('<input type="text" name="name" value="%s"><br>\n'
% cgi.escape(form.getvalue('name', ''), 1))
write('<input type="submit" value="That is my name"></form>\n')
write('</body></html>\n')
return None
application = application
[jangmt@localhost mywsgi]$ git commit -a -m 'cgi post APP test'
[master 26854fd] cgi post APP test
1 files changed, 24 insertions(+), 5 deletions(-)
rewrite wsgi/application (99%)
[jangmt@localhost mywsgi]$ git push
Counting objects: 7, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 725 bytes, done.
Total 4 (delta 1), reused 0 (delta 0)
remote: tar: README: time stamp 2011-05-31 08:50:58 is 28761.427928209 s in the future
remote: tar: data/SAFETOREMOVE.txt: time stamp 2011-05-31 08:50:58 is 28761.427255996 s in the future
remote: tar: data: time stamp 2011-05-31 08:50:58 is 28761.427219172 s in the future
remote: tar: libs/SAFETOREMOVE.txt: time stamp 2011-05-31 08:50:58 is 28761.426901593 s in the future
remote: tar: libs: time stamp 2011-05-31 08:50:58 is 28761.426865693 s in the future
remote: tar: wsgi/application: time stamp 2011-05-31 08:50:58 is 28761.426519532 s in the future
remote: tar: wsgi: time stamp 2011-05-31 08:50:58 is 28761.426481248 s in the future
To ssh://a0aaf4b1ba3f4f3dbf7abd14c64fa89f@mywsgi-jangmt.rhcloud.com/~/git/mywsgi.git/
95b7a2b..26854fd master -> master
* 自Python提出了WSGI標準,它可重覆利用和有彈性的特性,使得網頁開發可以更專注於更重要的地方。當然 OpenShift 也就以此為標準讓使用這可以專注於程式上面的開發。
* 當系統問題變的簡單,所有的服務都可以在雲端上找到資源。針對MIS人員的存在價值應該也要跟著有所轉變,傳統上MIS人員是管看的見的硬體、設備,在雲 端服務下MIS人員只是從管看的見,轉成管虛擬的、Cloud上的資源,並且有更多的時間專於IT及組織的問題予以處理改善。雲端服務只是以前的技術應用 的創新,透過基礎課程的訓練,瞭解每個細節將來也大多事這些基礎的運作模式用不同的組合搭配出現。
底下是上面這些相關資訊的延伸參考: