Openshift初探

##前言
在找免费/低价的vps之类的产品,找了半天发现Openshift里有提供试用的。
挂上代理,尝试了一下,使用过程记录如下。

##Openshift介绍

OpenShift是红帽公司推出的一个云计算服务平台,开发人员可以用它来构建和发布web应用。Openshift广泛支持多种编程语言和框架,如Java,Ruby和PHP等。另外它还提供了多种集成开发工具如Eclipse integration,JBoss Developer Studio和 Jenkins等。OpenShift 基于一个开源生态系统为移动应用,数据库服务等,提供支持。

Openshift online 是一个面向开源开发人员开放的平台即服务(Pass).
Openshift 提供一年的免费服务,这也是本文的前提之一,创建应用后,我们可以通过多种途径(其实只有三种)方便地管理应用。

##搭建简单php应用
Tip: 本机环境:Linux (openSuSE 13.1), 目标:搭建并管理dokuwiki(php)应用

首先,你得能够科学上网。

  1. 申请帐号,验证邮箱。(下面使用web方式创建应用)
  2. 第一步,添加应用,选择平台,这里在Instant App —— see all中选择DokuWiki.
  3. 第二步,配置,其中填上rhcloud.com的二级域名(如 php-test.rhcloud.com)。
  4. 第三步,填写密钥,暂不填写,继续下一步。
  5. 创建完成,键入域名 php-test.rhcloud.com 即可访问。

如果接下来需要做修改文件等操作的话,就需要对源码管理(git)。
下面将使用Openshift的客户端工具进行本地管理。

##本地管理

安装 Ruby 并检测

1
2
3
$ sudo zypper install ruby
$ ruby -e 'puts "Welcome to Ruby"'
Welcome to Ruby

安装 RubyGem

1
$ sudo zypper install rubygem

安装 git 并检测

1
2
$ sudo zypper install git
$ git --version

安装客户端工具

1
$ gem install rhc

接下来进行安装后的第一次设定

1
2
3
$ rhc setup
Login to openshift.redhat.com: user@example.com
Password: password

然后提示生成授权token。回答yes. token用于后续的请求。到期时,系统提示您再次输入密码。

1
2
3
OpenShift can create and store a token on disk which allows to you to access the server without using your password. The key is stored in your home directory and should be kept secret. You can delete the key at any time by running 'rhc logout'.
Generate a token now? (yes|no) yes
Generating an authorization token for this client ... lasts about 1 day

如果本机没有过sshkey,程序会自动生成

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
No SSH keys were found. We will generate a pair of keys for you.
Created: /home/cathon/.ssh/id_rsa.pub
Your public SSH key must be uploaded to the OpenShift server to access code. Upload now? (yes|no) yes
default (type: ssh-rsa)
-----------------------
Fingerprint: 18:e0:61:e2:32:d4:bd:d4:7f:be:d9:ca:df:be:1e:2d
You can enter a name for your key, or leave it blank to use the default name. Using the same name
as an existing key will overwrite the old key.
Provide a name for this key: xxx //给key起个名字
Uploading key 'xxx' ... done
Checking for git ... found git version 1.8.4.5
Checking common problems .. done
Checking for a domain ... xxx
Checking for applications ... found 1
php http://test.rhcloud.com/
You are using 1 of 3 total gears
The following gear sizes are available to you: small
Your client tools are now configured.

如果本机之前有其他的sshkey,就需要自己生成一个新的,避免冲突,涉及到ssh多密钥管理。可以参考
现在客户端程序安装完毕,并且生成了私钥,上传了公钥。

下载应用到本地,使用 git 管理

1
$ git clone ssh://......./~/git/xxx.git     //此 git 链接可以在OPENSHIFT ONLINE中应用管理中找到)

用 ssh 登录远程服务器管理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
$ rhc ssh xxx    //xxx为应用的名称
Connecting to 54ead6dc5973ca85eb0001a1@xxx.rhcloud.com ...

*********************************************************************

You are accessing a service that is for use only by authorized users.
If you do not have authorization, discontinue use at once.
Any use of the services is subject to the applicable terms of the
agreement which can be found at:
https://www.openshift.com/legal

*********************************************************************

Welcome to OpenShift shell

This shell will assist you in managing OpenShift applications.

!!! IMPORTANT !!! IMPORTANT !!! IMPORTANT !!!
Shell access is quite powerful and it is possible for you to
accidentally damage your application. Proceed with care!
If worse comes to worst, destroy your application with "rhc app delete"
and recreate it
!!! IMPORTANT !!! IMPORTANT !!! IMPORTANT !!!

Type "help" for more info.


[xxx.rhcloud.com 54ead6dc5973ca85eb0001a1]\> //exit退出

##其他

备份

1
$ rhc snapshot save -a xxx  //xxx为应用名称

##后记

Openshift提供的平台除了php还有别的各种,其他应用管理也可以使用eclipse插件等等。
未完待续。。。

参考链接:
手把手教你在openshift上搭建wordpress博客(一)
升级、备份红帽PaaS openshift 上的 wordpress