幽谷奇峰 | 燕雀鸣幽谷,鸿鹄掠奇峰

命令行环境下为OpenShift PaaS平台部署Snova


客户端部署工具为rhc,它依赖Ruby,同时会用到Git,因此要先安装Ruby和Git。这两个工具的安装依据不同的操作系统而不同,这里就不赘述。

安装好Ruby后,运行:

1
gem install rhc

gem安装rhc可能被防火墙中断,可能需要设置代理(经验证,无法使用Goagent),例如:

1
gem install rhc --http-proxy http://127.0.0.1:8080

可运行:

1
rhc --version

来验证安装是否成功。

若要更新rhc到最新版本,可运行:

1
gem update rhc

如果还没有OpenShift帐号,可以利用安装的这段时间注册一个,注册链接:https://www.openshift.com/app/account/new

在创建和部署应用程序之前,要先对rhc进行一下配置,通过运行命令rhc setup来启动配置向导:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
$ rhc setup
DL is deprecated, please use Fiddle
OpenShift Client Tools (RHC) Setup Wizard

This wizard will help you upload your SSH keys, set your application namespace, and check that other programs like Git
are properly installed.

If you have your own OpenShift server, you can specify it now. Just hit enter to use the server for OpenShift Online:
openshift.redhat.com.
Enter the server hostname: |openshift.redhat.com| <Enter>

登陆信息

按下回车键后,会提示你输入OpenShift帐号信息:

1
2
3
4
You can add more servers later using 'rhc server'.

Login to openshift.redhat.com: user@mail.com
Password: ****************

认证Token

配置向导接下来会提示你生成一个认证token,回答yes:

1
2
3
4
5
6
7
8
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 month

Saving configuration to D:\DevPack\msys64\home\Administrator\.openshift\express.conf ... done

SSH keys

接下来,配置向导会生成一个SSH密钥对,以便将本地客户端认证到远端服务器。

1
2
3
4
5
No SSH keys were found. We will generate a pair of keys for you.

    Created: D:/DevPack/msys64/home/Administrator/.ssh/id_rsa.pub

Your public SSH key must be uploaded to the OpenShift server to access code.  Upload now? (yes|no) <yes>

提示安装Git

接着,配置向导会提示你安装Git:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
In order to fully interact with OpenShift you will need to install and configure a git client if you have not already
done so.

Documentation for installing other tools you will need for OpenShift can be found at
https://www.openshift.com/developers/install-the-client-tools

We recommend these free applications:

  * Git for Windows - a basic git command line and GUI client https://github.com/msysgit/msysgit/wiki/InstallMSysGit
  * TortoiseGit - git client that integrates into the file explorer http://code.google.com/p/tortoisegit/

Domain(namespace)

配置向导接着会检查你的OpenShift云端环境是否存在domain(namespace),这是创建应用程序必须的。以下示例是还没有domain的情况,若已经存在domain,这里会显示出来。

1
2
3
4
5
6
7
Checking for a domain ... none

Applications are grouped into domains - each domain has a unique name (called a namespace) that becomes part of your
public application URL. You may create your first domain here or leave it blank and use 'rhc create-domain' later. You
will not be able to create an application without completing this step.

Please enter a namespace (letters and numbers only) |<none>|:

在这里输入你的domain(namespace),只能包含字母和数字。

Applications

最后,配置向导会检查服务器上是否存在应用程序。以下示例是没有应用程序的情况:

 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
Checking for applications ... none

Run 'rhc create-app' to create your first application.

  Do-It-Yourself 0.1                      rhc create-app <app name> diy-0.1
  JBoss Application Server 7              rhc create-app <app name> jbossas-7
  JBoss Data Virtualization 6             rhc create-app <app name> jboss-dv-6.0.0
  JBoss Enterprise Application Platform 6 rhc create-app <app name> jbosseap-6
  Jenkins Server                          rhc create-app <app name> jenkins-1
  Node.js 0.10                            rhc create-app <app name> nodejs-0.10
  PHP 5.3                                 rhc create-app <app name> php-5.3
  PHP 5.4                                 rhc create-app <app name> php-5.4
  PHP 5.4 with Zend Server 6.1            rhc create-app <app name> zend-6.1
  Perl 5.10                               rhc create-app <app name> perl-5.10
  Python 2.6                              rhc create-app <app name> python-2.6
  Python 2.7                              rhc create-app <app name> python-2.7
  Python 3.3                              rhc create-app <app name> python-3.3
  Ruby 1.8                                rhc create-app <app name> ruby-1.8
  Ruby 1.9                                rhc create-app <app name> ruby-1.9
  Ruby 2.0                                rhc create-app <app name> ruby-2.0
  Tomcat 6 (JBoss EWS 1.0)                rhc create-app <app name> jbossews-1.0
  Tomcat 7 (JBoss EWS 2.0)                rhc create-app <app name> jbossews-2.0
  Vert.x 2.1                              rhc create-app <app name> jboss-vertx-2.1

  You are using 0 of 3 total gears
  The following gear sizes are available to you: small

Your client tools are now configured.

rhc create-app的用法如下:

 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
$ rhc create-app --help
Usage: rhc app-create <name> <cartridge> [... <cartridge>] [... VARIABLE=VALUE] [-n namespace]

Create an application. Every OpenShift application must have one web cartridge which serves web requests, and can have a
number of other cartridges which provide capabilities like databases, scheduled jobs, or continuous integration.

You can see a list of all valid cartridge types by running 'rhc cartridge list'. OpenShift also supports downloading
cartridges - pass a URL in place of the cartridge name and we'll download and install that cartridge into your app.
Keep in mind that these cartridges receive no security updates.  Note that not all OpenShift servers allow downloaded
cartridges.

When your application is created, a URL combining the name of your app and the name of your domain will be registered in
DNS. A copy of the code for your application will be checked out locally into a folder with the same name as your
application.  Note that different types of applications may require different folder structures - check the README
provided with the cartridge if you have questions.

OpenShift runs the components of your application on small virtual servers called "gears".  Each account or plan is
limited to a number of gears which you can use across multiple applications.  Some accounts or plans provide access to
gears with more memory or more CPU.  Run 'rhc account' to see the number and sizes of gears available to you.  When
creating an application the --gear-size parameter may be specified to change the gears used.


Options
  -n, --namespace NAME      Namespace for the application
  -g, --gear-size SIZE      Gear size controls how much memory and CPU your cartridges can use.
  -s, --[no-]scaling        Enable scaling for the web cartridge.
  -r, --repo DIR            Path to the Git repository (defaults to ./$app_name)
  -e, --env VARIABLE=VALUE  Environment variable(s) to be set on this app, or path to a file containing environment
                            variables
  --from-app NAME           Create based on another application. All content and configurations will be copied from the
                            original app.
  --from-code URL           URL to a Git repository that will become the initial contents of the application
  --region REGION           The region where the application gears will be located
  --[no-]git                Skip creating the local Git repository.
  --[no-]dns                Skip waiting for the application DNS name to resolve. Must be used in combination with
                            --no-git
  --enable-jenkins [NAME]   Enable Jenkins builds for this application (will create a Jenkins application if not already

                            available). The default name will be 'jenkins' if not specified.
  -a, --app NAME            Name for your application
  -t, --type CARTRIDGE      The web framework this application should use

Global Options
  -l, --rhlogin LOGIN       OpenShift login
  -p, --password PASSWORD   OpenShift password
  --token TOKEN             An authorization token for accessing your account.
  --server HOSTNAME         An OpenShift server hostname (default: openshift.redhat.com)
  --timeout SECONDS         The timeout for operations

  See 'rhc help options' for a full list of global options.

应用程序最后的域名格式为:<app name>-<namespace>.rhcloud.com

首先到这里下载Snova服务器端(nodejs版)源码(笔者下的是snova-c4-nodejs-server-0.22.0.zip)和本地客户端程序。

服务器端

运行以下命令(用你的应用程序名替代),创建一个应用程序:

1
$ rhc create-app <your app name> -t nodejs-0.10

该命令成功运行完后,给出了该应用程序的URL,SSH to 和 Git remote 的信息,并在当前路径下生成一个名为的目录,解压snova-c4-nodejs-server-0.22.0.zip并覆盖到这个目录,然后进入该目录,依次运行:

1
2
3
$ git add .
$ git commit -m "First deployment "
$ git push

若最后看到有如下信息:

1
2
3
remote: Git Post-Receive Result: success
remote: Activation status: success
remote: Deployment completed with status: success

则表示部署已经成功。

修改客户端设置

修改gsnova.conf中C4部分,填入之前创建的域名(必须用https),重启gsnova生效

1
2
3
4
5
6
[C4]
#Enable改为1,C4才能生效,默认为0关闭
Enable=1
#修改domain为前面创建的应用程序的域名, 可加多个域名
WorkerNode[0]=https://<appname1>-<namespace>.rhcloud.com
WorkerNode[1]=https://<appname2>-<namespace>.rhcloud.com

修改gsnova.conf中SPAC下默认的Proxy实现为C4

1
2
3
4
[SPAC]
Enable=1
#默认Proxy实现,初始为GAE
Default=C4

启动GSnova,默认在127.0.0.1:48102上接受无spac支持的代理请求,在127.0.0.1:48100上接受有spac支持的代理请求。


本作品由 Yysfire 创作,采用知识共享许可协议进行许可。转载时请在显著位置标明本文永久链接:
http://yysfire.github.io/tools/deploy-snova-on-Openshift-in-CLI.html


最后修改
2014-08-29 01:31
发表时间
2014-08-28 22:23
本文标签
CLI 1 JAP 1 OpenShift 1 PaaS 1 Snova 1
关注我