Joyent no.de 试用和配置笔记
配置
1) 提交一个 ssh pub key。
2) windows 中可能没有 ssh config 文件,先要在 %home%.ssh 下新建 config 文件,内容写入:
Host ambar.no.de
Port 18360
User node
ForwardAgent yes
3) 命令行 ssh 登入,这里用的是我喜欢的 powershell :
PS C:\Users\lj> ssh ambar.no.de
Last login: Sat Dec 17 03:41:31 2011 from 10.2.136.43
__ __ __
__ / /___ __ _____ ____ / /_ ____ ____ ____/ /__
__/ /___ / / __ \/ / / / _ \/ __ \/ __/ / __ \/ __ \ / __ / _ \
/_ __/ /_/ / /_/ / /_/ / __/ / / / /_ / / / / /_/ // /_/ / __/
/_/ \____/\____/\__, /\___/_/ /_/\__/ /_/ /_/\____(_)__,_/\___/
/____/ Welcome to ambar.no.de
Useful Commands:
pkgin -h
node-service-info
node-service-log
node-service-restart
node-service-disable
node-service-enable
node-service-howto
Useful URLs:
http://wiki.joyent.com/display/node/Node+SmartMachine+FAQ
https://no.de/
http://nodejs.org/docs/latest/api/
https://api.no.de/
no.de 的 SmartMachine 比 heroku 好用就在这里,让你感觉你有一个真正的机器,不用麻烦地去记忆 heroku 的命令。
先看看运行的 nodejs 版本:
[node@ambar ~]$ node
process.versions
{ node: '0.4.11',
v8: '3.1.8.26',
ares: '1.7.4',
ev: '4.4',
openssl: '0.9.8k' }
从 node-service-info 命令可以看到默认运行服务器位置和参数:
> /opt/nodejs/v0.4/bin/node /opt/nodejs/default_server/server.js
通过 pkgin 可以很方便地安装软件:
> http://wiki.joyent.com/display/smart/Installing+Software+on+a+SmartMachine
4) 新建本地 repo , 新建 app.js,push 测试代码:
git push ambar.no.de master
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 353 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: Deploying node-service.
remote: revision: 51027adfaeb07b11b7b84f938fe729002fcefafd
remote: timestamp: 2011-12-17T04-33-02.424359254
remote: error: Cannot deploy without either a 'package.json' or 'server.js'.
remote: See <http://wiki.joyent.com/display/node/Node+Home> for more info.
remote:
remote: Rolling back to default server.
remote: Starting node-service.
remote: Rollback succeeded.
To ambar.no.de:repo
* [new branch] master -> master
出错了! 默认服务器引导的文件必须名叫 server.js ,否则用 package.json 文件进行配置:
> http://wiki.joyent.com/display/node/Getting+Started+with+a+Node.js+SmartMachine
要紧的是 package.json 必须符合标准格式:
要动手写一个的,参考 express 的最直接:
https://github.com/visionmedia/express/blob/master/package.json
package.json 样例:
{
"name" : "ambar.no.de",
"version" : "0.0.1",
"description": "have fun with no.de",
"scripts" : { "start": "node ./app" }
}
或者更酷一点,可以在 ssh 中用 npm 安装 CoffeeScript:
// npm install -g coffee-script
// 用 coffee 引导应用:
{ "start": "coffee ./app" }
http = require 'http'
port = process.env.PORT || 80
http.createServer (req,res) ->
res.writeHead 200, {'Content-Type': 'text/plain'}
res.end 'Hello World\n'
.listen port
console.log "Listening on port " + port
再 push 一遍,应用就成功运行了。
附
如何设置 node 版本:
> http://wiki.joyent.com/display/node/Setting+the+Node.js+Version
简易的方式是新建一个 config.json 文件,内容如下:
{ "version": "latest" }
查看所有可用的 nodejs 版本:
cat /opt/nodejs/NODE-BUILDS