🎶 Sym - 一款用 Java 实现的现代化社区(论坛/BBS/社交网络/博客)平台

📕 思源笔记 - 一款桌面端笔记应用,支持 Windows、Mac 和 Linux

🎸 Solo - B3log 分布式社区的博客端节点,欢迎加入下一代社区网络

♏ Vditor - 一款浏览器端的 Markdown 编辑器

不同 PaaS 平台上对 Node.js 支持的比较

下文转自:比较不同的 PaaS 平台上的 Node.js 支持  

 

Node.js的相对 其他的语言来说可能仍然是年轻的,但是它的虚拟主机却有很多的选择。在这篇文章中,我们就来看看几个“平台即服务(PaaS)”提供商。

这里不涵盖某些“基础设施即服务(IaaS)”的选择,比如  AWS  和  Joyent,尽管这些选择之中的某些PaaS和IaaS之间的界限有一点点模糊。

在这一轮中,我主要考察两个方面:部署和环境变量的配置。我还把一些有关起步,仪表板的截图和对其它的杂项操作的观察囊括了进来。在以后的文章中,我们将会运行一些基础的性能测试,然后来看看架构伸缩难易程度。

The Players

Provider Deployment method Environment variables Performance
Nodejitsu CLI CLI or web interface coming soon
Heroku git CLI
Modulus CLI or web upload CLI or web interface
App Fog CLI CLI or web interface
Azure CLI or git CLI or web interface
dotCloud CLI CLI or .yml file
Engine Yard git ey_config npm module
OpenShift git SSH and create file
CloudFoundry coming soon coming soon

设置

我开始于一个非常简单的 Express app,使用 nconf可以提供多种不同的方式,让我们可以给app指定端口,监听我们的应用程序(必要时)以及一个dummy变量,我称之为SECRET。它会先寻找节点命令传递的参数,环境变量,然后从根目录的上一级到我们制定的默认位置,尝试加载的config.json文件。当加载app时,我们能知道变量从外部源加载是否正确。如果错误,加载app时将回滚到默认的SECRET。如果我可以访问app的启动日志,也就可以看到app监听在NODE_ENV上的哪个端口。

最后,我设置"engines": { "node": "v0.10.x" ...到 package.json文件中,就可以看到每个提供者如何响应。

现在没有特定的顺序..




Nodejitsu

https://www.nodejitsu.com/

一个最初的参与者仍然完全地是Node.js的解决方案,当Joyent放弃他们的no.de服务之后Joyent的Nodejitsu成为了官方合作伙 伴(惭愧,那真是一个不错的域名).Nodejitsu不再是一个永久免费的中间层.但是个别的方案需要3$每月和有一个30天的免费试用期.

变量配置
根据文档你不需要设置监听端口,只要它是80或大于1024.

设置我们的SECRET来覆盖默认的是相当容易的.您可以使用CLI或web接口列表来设置变量,就像这个名单上其他几个供应商。

部署

发布你的代码到Nodejitsu云是通过一个自定义的命令行接口(CLI)应用程序,安装rpm,注册以后将自动转存到 github 指令版本库但整体安装过程是相当痛苦的,当提示选择一个二级域名,然后会自动添加到package.json文件,在我跑了几个测试中,部署是非常快的. 在每个部署的package.json文件的版本属性是自动递增与的,这不会麻烦我但可能会使另外一些人烦恼.

我遇到了三个小故障,第一是版本控制,在我部署时有信息输出,我展示下:
info: jitsu v0.12.10-2, node v0.10.4
然而,我被告知0.10.x不是支持价值,只有通过对比到0.8.x时我才能够获得成功.
第二,我尝试在package.json改变属性名称然后就告诉不能部署
第三.我把ENV变量给消除了,每次我都的重新部署,也许有一个方法可以避免.

Misc Notes 和 Dashboard

我喜欢Nodejitsu。任何处理自定义配置都会通过标准的package.json文件。你甚至可以定义定制的predeploy和postdeploy hooks。我对它的印象是,它能非常灵活地部署和查看日志。

Nodejitsu dashboard

Heroku

https://www.heroku.com/

PaaS世界的庞然大物, 使用无所不在的Ruby on Rails 构造出的极端流行的平台。

变量配置

同样是使用CLI设置我们的SECRET,用来覆盖默认值。

所有应用在端口5000上运行,所以你需要监听这个端口。

最后,需要创建一个Procfile来说明web应用:node server.js。这只是支持多语言的PaaS的平台的小小的副作用。

部署

Heroku的"toolbelt"CLI是用于管理您的帐户和应用,但部署是通过git,你只需要添加终端他们就会为您提供远程在你的git配置中,因 为他们不完全支持Node.js,我很惊喜地发现他们已经支持v 0.10.6,我的第一个部署似乎成功,但是我收到追踪错误引导我发现第一次需要指定有多少资源,我想致力于这个程序:

heroku ps:scale web=1

在那之后,它是一帆风顺的.

Misc Notes and Dashboard

I didn’t try Heroku for my own projects until about 3 months ago, partly because I have a modest level of comfort in setting up my own servers, and partly because I just figured they treated node.js as an afterthought. But if you can get over their lack of WebSocket support and some misleading marketing and stats, it’s a pretty smooth experience.

They’ve also got a very polished and functional dashboard, with some handy features you won’t find elsewhere like pointing to an S3-hosted file for 404 pages, and the ability to transfer ownership of a project to a different user.


Modulus

http://modulus.io

.io  后缀是一个相对较新的服务。 关于Node.js, 他们内嵌支持MongoDB 和本地文件存储。

配置变量

配置变量可以通过网页界面或者CLI。我试图在创建SECRET。在尝试并碰到错误后,我发现不能在变量中出现空格!所以奇怪是SECRET模块不能运作。

应用需要监听8080端口, “但我们推荐用端口环境变量 (process.env.PORT).”

部署

部署可以通过CLI来做,但你也可以压缩整个项目并把它通过他们很有趣的网络接口上传。我没有任何问题,部署,但每次要把你整个项目(除了 node_modules之外)都打包和上传,这会使它的处理过程比那些使用 git 的“diff”功能或 rsync 的工具慢得多。

至于写作,模块运行于0.8.15版本,并忽略你在 package.json 中指定的任何内容。

其它注意事项和仪表板

我为这些家伙欢呼,并希望他们能继续改善。有个内置MongoDB的选项会是不错的,我喜欢前期定价。

AppFog

http://appfog.com

AppFog先前因PHP Fog而出名,现在已被CenturyLink收购。你可以指定你想使用的云,如不同地区的AWS、HP以及Azure云。 

配置变量

变量可通过web控制台或者CLI(命令行工具)设置。设置私密变量毫无问题。

文档要求监听process.env.VCAP_APP_PORT端口,但我尝试使用默认配置也能正常工作。日志显示它在监听57277端口。

部署

也是借助CLI工具。写这篇文章的时候,AppFog使用v0.8.14版本,并且忽略package.json里的版本设置。

其他注意事项和仪表盘

它的免费计划看起来挺慷慨的。它提供多达8个实例,总共2GB RAM,并可随意分割使用。它也有内置MongoDB的选项。

AppFog dashboard

Windows Azure

http://windowsazure.com

Yep. Believe it.

Configuring variables

Variables can be set either via the web interface or the CLI. I experienced one weird bit behavior on the SECRET when I first set it up via the CLI; it was lowercased to secret. I had to use the web interface to correct it.

The app ran fine without making any changes to our configuration for ports, although the logs showed a pretty wacky value: \\.\pipe\bea0dffc-de5b-47f4-8575-4d17c2175fd5

Deploying

You might expect Microsoft to have all kinds of custom stuff here. While there are a few files that get dropped into you repo (name azure_error and iisnode.yml), the (optional) CLI is installed via npm and deployment is handled via git. Nice!

As of writing, Azure is running 0.8.2, and this value must be configured correctly in package.json.

Misc Notes and Dashboard

The account creation process was by far the most tedious of any listed here. It included SMS verification, a Windows Live account, and a separate git user account for deploying. But overall, the dashboard is pretty nice considering the huge scope of the Azure platform. They also support streaming log files. As far as I can tell, Heroku is the only other provider on this list to do so.


dotCloud

http://dotcloud.com

支持多国语言.就像Nodejitsu一样, 他们最近取消了他们的免费服务,所以在开始使用之前需要绑定一张信用卡.

参数配置

参数的设置通过CLI或者一个dotcloud.yml文件设置.

监听端口需要设置为8080.

部署

dotClouds CLI使用Python编写的, 同时使用rsync在每次部署的时候最小化你要上传的数据. 为了帛书,你需要配置supervisord.conf和dotcloud.yml文件。

目前, dotCloud的版本为 0.6.20. Ouch.

注意事项和控制面板

早期的时候我感到非常的愤怒,当他们进行一些重大修改却几乎没有警告的时候。我猜这就是生活在一个beta的世界,但是我一直没有急着跑回来。

dotCloud dashboard

Engine Yard

http://engineyard.com

Like Heroku, Engine Yard is known primary for it’s Ruby on Rails hosting. Unlike Heroku, you have more control over the setup and environment. It’s still a PaaS, but people with some direct server experience will appreciate being a little “closer to the metal.”

Configuring variables

Environment variable cas be set by using the ey_config npm module. Engine Yard also support SSH access to your machine, which means you could create a config.json and drop it in the right place.

The port should be process.env.PORT and nconf is already handling that for us.

Deploying

Handled via git.

It respects the node version value in package.json but only up to 0.8.11.

Misc Notes and Dashboard

When you create an application, you get to choose between nginx as front-end proxy (which the recommend) or going straight to Node.js, the latter of which gives you option of WebSockets.

When my first deploy failed, a chat window popped up with option for me to put in my phone number.


OpenShift.com

http://openshift.com

OpenShift 一个主要由Red Hat维护的开源项目, OpenShift.com是一个托管式服务的平台(像WordPress.org 和 WordPress.com).

配置变量

OpenShift.com 支持用SSH连接你的电脑,这意味着你可以新建 config.json 并把它放到合适的地方. 否则, 没有特殊的命令来预先定义配置文件.

端口是 process.env.OPENSHIFT_INTERNAL_PORT || 8080.

部署

用git操作,如果你不是基于网页的GUI的粉丝,尽管有 CLI 用来创建和管理项目. 你需要先将你的公共SSH key加到你的账户中,这是不包括在node.js快速进阶样例的一步。 

It ignores the node version value in package.json and runs a rusty ol’ v0.6.20 by default, but with some extra steps you can change that.

Misc Notes and Dashboard

I had some problems getting the sample app running at first, so I started over and let OpenShift populate the git repository for me with their sample files. There are a few extra things in there, many of which are tucked under the.openshift directory. These include deploy hooks and config files. The README they include does a good job of laying out the structure and explaining the purpose of each file.

But I still got stuck on the fact that I needed to listen on a specific IP address. That mean including this:

var ipaddr = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";

And then added ipaddr in the app.listen section of my server.js like this:

app.listen(app.get('port'), ipaddr, function(){...

I’ve had an exchange with the OpenShift folks and they’re going to update their getting started guide to make this more clear.

CloudFoundry

http://cloudfoundry.com

At first look, CloudFoundry has a clear and friendly process for getting started. However, a few screens into the process I was presented with this message:
*We are in a time of transition:*
You are reading V2 documentation... Cloudfoundry.com will be upgraded to V2 in June 2013.

So I’ll circle back to them in the next installment of this series.

Until Next Time

Needless to say things are changing quickly in this space. Don’t put too much weight on any specific detail here without first checking for updates. For example, in the couple of days that it took me to type this up, Modulus sent out an email about upgrading their version of Node.js.

In future posts I’ll be walking through how we can monitor and test the performance of these platforms, and then take a shot at scaling them. In the meantime, let me know if I’ve missed your favorite Node.js PaaS.


欢迎注册黑客派社区,开启你的博客之旅。让学习和分享成为一种习惯!

留下你的脚步