几个月前在heroku 注册了个账户, 那时候还是 beta测试, 也没当回事 , 2天前, heroku 给我发了个 Heroku Paid Services 的邮件, 也没怎么感兴趣, 我对任何 paid service 都不怎么感兴趣 , 不过 打开一看也是 有些我感兴趣的内容的
Now you can:
- add dynos for more performance
- scale your database
- add custom domains (free)
- add wildcard domains
- use SSL (free)
- make backups (free)
- use cron (free)
其实也没啥 , 就是那么几个free 的东西:
add custom domains (free ) , 这个可以把自己没用的域名扔上去
use SSL (free ) , 加了SSL 这样proxy 翻墙时候就不会被打扰了
use cron (free ), 有了cron , 能干的事情就多了(后来一看, free 的是 nightly cron )
今天是端午,吃完粽子以后也没心情缅怀伟大的自由战士屈原了, 打开电脑去heroku一趟,还不错,小有收获.
就纪录下流水帐吧.
去那的目的就是一个 , 把一个rails小程序从 dreamhost 上迁出去, 问啥叫小程序呢 ? 因为 heroku 给免费的应用 只有一个 blossom-1 , 呵呵, 只有5M 的database空间, 存储空间它也没说 , 估计也不会大吧
(更正, 不是不大,是根本就没有, 需要连 s3 等)
迁移的很顺利, 把code扔到 heroku的 git 上就成了 , 而且每次push的时候 , 你的应用会重新启动一下, 很方便 .
但是 add custom domains 的时候, 或者其他 addon services 的时候 , 你的billing 信息必须验证 ,即使是免费的
服务 , 这不就是为以后收钱做准备吗 , 结果扣了我信用卡里1美元 (我的一顿饭钱), 还不知道啥时候还给我 ,算了算
了, 不跟他计较了 , 虽说我穷的铃儿响叮当了.
回到正题, 表面探索开始喽......
heroku 的 构建 在此: architecture , 我来啰唆一下: 从上到下:
HTTP Reverse Proxy : Nginx
|
V
HTTP Cache :Varnish
|
V
Routing Mesh (Erlang 自己开发的)
|
V
Dyno Grid(Ruby 就跑在这里面)
| |
V V
DB : PostgreSQL Memory Cache : Memcached
从上面看 , 主要自己开发的就是 Routing Mesh 这一次, 其他都用 Open Source 的东西了
一切用数据说话, 我的 rails 小程序 跑在这么一个linux上:
vendor_id : GenuineIntel
cpu family : 6
model : 15
model name : Intel(R) Xeon(R) CPU E5345 @ 2.33GHz
stepping : 11
cpu MHz : 2327.500
cache size : 4096 KB
physical id : 1
siblings : 1
core id : 3
cpu cores : 1
fpu : yes
fpu_exception : yes
cpuid level : 10
wp : yes
flags : fpu tsc msr pae mce cx8 apic mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr lahf_lm
bogomips : 4657.65
clflush size : 64
cache_alignment : 64
address sizes : 38 bits physical, 48 bits virtual
power management:
MemFree: 3762200 kB
Buffers: 130992 kB
Cached: 370448 kB
SwapCached: 0 kB
Active: 2828944 kB
Inactive: 363188 kB
root 1 0.0 0.0 6124 688 ? Ss May27 0:00 init [4]
root 2 0.0 0.0 0 0 ? S May27 0:00 [migration/0]
root 3 0.0 0.0 0 0 ? SN May27 0:00 [ksoftirqd/0]
root 4 0.0 0.0 0 0 ? S May27 0:00 [watchdog/0]
root 5 0.0 0.0 0 0 ? S< May27 0:00 [events/0]
root 6 0.0 0.0 0 0 ? S< May27 0:00 [khelper]
root 7 0.0 0.0 0 0 ? S< May27 0:00 [kthread]
root 9 0.0 0.0 0 0 ? S< May27 0:00 [xenwatch]
root 10 0.0 0.0 0 0 ? S< May27 0:00 [xenbus]
root 18 0.0 0.0 0 0 ? S< May27 0:00 [migration/1]
root 19 0.0 0.0 0 0 ? SN May27 0:00 [ksoftirqd/1]
root 20 0.0 0.0 0 0 ? S< May27 0:00 [watchdog/1]
root 21 0.0 0.0 0 0 ? S< May27 0:00 [events/1]
root 22 0.0 0.0 0 0 ? S< May27 0:00 [migration/2]
root 23 0.0 0.0 0 0 ? SN May27 0:00 [ksoftirqd/2]
root 24 0.0 0.0 0 0 ? S< May27 0:00 [watchdog/2]
root 25 0.0 0.0 0 0 ? S< May27 0:00 [events/2]
root 26 0.0 0.0 0 0 ? S< May27 0:00 [migration/3]
root 27 0.0 0.0 0 0 ? SN May27 0:00 [ksoftirqd/3]
root 28 0.0 0.0 0 0 ? S< May27 0:00 [watchdog/3]
root 29 0.0 0.0 0 0 ? S< May27 0:00 [events/3]
root 30 0.0 0.0 0 0 ? S< May27 0:00 [migration/4]
root 31 0.0 0.0 0 0 ? SN May27 0:00 [ksoftirqd/4]
root 32 0.0 0.0 0 0 ? S< May27 0:00 [watchdog/4]
root 33 0.0 0.0 0 0 ? S< May27 0:00 [events/4]
root 34 0.0 0.0 0 0 ? S< May27 0:00 [migration/5]
root 35 0.0 0.0 0 0 ? SN May27 0:00 [ksoftirqd/5]
root 36 0.0 0.0 0 0 ? S< May27 0:00 [watchdog/5]
root 37 0.0 0.0 0 0 ? S< May27 0:00 [events/5]
root 38 0.0 0.0 0 0 ? S< May27 0:00 [migration/6]
root 39 0.0 0.0 0 0 ? SN May27 0:00 [ksoftirqd/6]
root 40 0.0 0.0 0 0 ? S< May27 0:00 [watchdog/6]
root 41 0.0 0.0 0 0 ? S< May27 0:00 [events/6]
root 42 0.0 0.0 0 0 ? S< May27 0:00 [migration/7]
root 43 0.0 0.0 0 0 ? SN May27 0:00 [ksoftirqd/7]
root 44 0.0 0.0 0 0 ? S< May27 0:00 [watchdog/7]
root 45 0.0 0.0 0 0 ? S< May27 0:00 [events/7]
root 54 0.0 0.0 0 0 ? S< May27 0:00 [kblockd/0]
root 55 0.0 0.0 0 0 ? S< May27 0:00 [kblockd/1]
root 56 0.0 0.0 0 0 ? S< May27 0:00 [kblockd/2]
root 57 0.0 0.0 0 0 ? S< May27 0:00 [kblockd/3]
root 58 0.0 0.0 0 0 ? S< May27 0:00 [kblockd/4]
root 59 0.0 0.0 0 0 ? S< May27 0:00 [kblockd/5]
root 60 0.0 0.0 0 0 ? S< May27 0:00 [kblockd/6]
root 61 0.0 0.0 0 0 ? S< May27 0:00 [kblockd/7]
root 63 0.0 0.0 0 0 ? S< May27 0:00 [kseriod]
root 130 0.0 0.0 0 0 ? S May27 0:00 [pdflush]
root 131 0.0 0.0 0 0 ? S May27 0:00 [pdflush]
root 132 0.0 0.0 0 0 ? S< May27 0:00 [kswapd0]
root 133 0.0 0.0 0 0 ? S< May27 0:00 [aio/0]
root 134 0.0 0.0 0 0 ? S< May27 0:00 [aio/1]
root 135 0.0 0.0 0 0 ? S< May27 0:00 [aio/2]
root 136 0.0 0.0 0 0 ? S< May27 0:00 [aio/3]
root 137 0.0 0.0 0 0 ? S< May27 0:00 [aio/4]
root 138 0.0 0.0 0 0 ? S< May27 0:00 [aio/5]
root 139 0.0 0.0 0 0 ? S< May27 0:00 [aio/6]
root 140 0.0 0.0 0 0 ? S< May27 0:00 [aio/7]
root 752 0.0 0.0 0 0 ? S< May27 0:00 [kjournald]
root 839 0.0 0.0 10656 944 ? S
root 1763 0.0 0.0 0 0 ? S< May27 0:00 [kmirrord]
root 1819 0.0 0.0 0 0 ? S< May27 0:00 [kjournald]
root 1821 0.0 0.0 0 0 ? S< May27 0:00 [kjournald]
root 1898 0.0 0.0 4568 940 ? Ss May27 0:00 dhclient3 -pf /var/run/dhclient.eth0.pid -lf /var/lib/dhcp3/dhclient.eth0.leases eth0
root 1988 0.0 0.0 10228 1644 ? Ss May27 0:00 /bin/sh /etc/init.d/rc 4
root 1997 0.0 0.0 3732 648 ? Ss May27 0:00 /sbin/syslogd
root 2003 0.0 0.0 2660 396 ? Ss May27 0:00 /sbin/klogd -x
root 2073 0.0 0.0 25840 1256 ? Ss May27 0:00 /usr/sbin/sshd
root 2106 0.0 0.0 8020 1972 ? S May27 0:00 /usr/bin/ruby /etc/rc4.d/S90heroku start
root 2204 0.0 0.0 10056 1384 ? S May27 0:00 sh -c /root/fabber/master_fab 2>&1 | tee -a /var/log/heroku_fab.log
root 2206 0.0 0.0 2640 452 ? S May27 0:00 tee -a /var/log/heroku_fab.log
root 2236 0.0 0.0 11496 944 ? Ss May27 0:00 /usr/sbin/cron
root 2296 0.0 0.0 10056 1400 ? S May27 0:00 bash
root 2297 0.0 0.3 66996 28772 ? S May27 0:02 ruby railgun_web.rb -p 1000
root 2320 1.4 0.3 63532 27360 ? Ss May27 12:15 /usr/bin/ruby /home/railgun/railgun.rb
root 2323 2.6 0.3 67600 29352 ? Ss May27 22:39 /usr/bin/ruby /home/railgun/uncle_jimbo.rb
root 3871 0.0 0.0 0 0 ? S< May27 0:00 [loop2]
root 4167 0.0 0.0 0 0 ? S< May27 0:00 [loop3]
root 5120 0.0 0.0 0 0 ? S< May27 0:00 [loop7]
root 5223 0.0 0.0 0 0 ? S< May27 0:00 [loop8]
root 6790 0.0 0.0 0 0 ? S< May27 0:00 [loop13]
1013 6803 0.0 0.0 6248 1492 ? S May27 0:00 /bin/bash /usr/local/bin/thin_launcher 47123 log/server_12599_43eedc9_8d52_47123.log 12599_43eedc9_8d52
1013 6805 0.0 0.5 95368 41480 ? S May27 0:08 /usr/local/bin/ruby /usr/local/bin/thin -p 47123 -e production -R /home/heroku_rack/heroku.ru start
root 8225 0.0 0.0 0 0 ? S< May27 0:00 [loop16]
root 18730 0.0 0.0 10056 1416 ? S May27 0:00 bash
root 19608 0.0 0.0 10052 1412 ? S May27 0:00 bash
root 28749 0.0 0.0 0 0 ? S< May27 0:00 [loop15]
1055 28762 0.0 0.0 6248 1492 ? S May27 0:00 /bin/bash /usr/local/bin/thin_launcher 58852 log/server_15841_c5d2715_8b13_58852.log 15841_c5d2715_8b13
1055 28764 0.0 0.7 108672 54948 ? S May27 0:01 /usr/local/bin/ruby /usr/local/bin/thin -p 58852 -e production -R /home/heroku_rack/heroku.ru start
root 3657 0.0 0.0 0 0 ? S< May27 0:00 [loop38]
slug3635 3670 0.0 0.0 6248 1492 ? S May27 0:00 /bin/bash /usr/local/bin/thin_launcher 59168 log/server_3635_20e3e3a_def5_59168.log 3635_20e3e3a_def5
slug3635 3672 0.0 0.8 118256 60484 ? S May27 0:02 /usr/local/bin/ruby /usr/local/bin/thin -p 59168 -e production -R /home/heroku_rack/heroku.ru start
root 17444 0.0 0.0 0 0 ? S< May27 0:00 [loop40]
1080 17457 0.0 0.0 6248 1496 ? S May27 0:00 /bin/bash /usr/local/bin/thin_launcher 42355 log/server_11148_6794cd5_a238_42355.log 11148_6794cd5_a238
1080 17459 0.0 0.8 117160 61436 ? S May27 0:02 /usr/local/bin/ruby /usr/local/bin/thin -p 42355 -e production -R /home/heroku_rack/heroku.ru start
root 20903 0.0 0.0 0 0 ? S< May27 0:00 [loop41]
slug2195 20944 0.0 0.0 6248 1492 ? S May27 0:00 /bin/bash /usr/local/bin/thin_launcher 37142 log/server_2195_6fda6fd_339c_37142.log 2195_6fda6fd_339c
slug2195 20947 0.0 0.8 116936 60032 ? S May27 0:02 /usr/local/bin/ruby /usr/local/bin/thin -p 37142 -e production -R /home/heroku_rack/heroku.ru start
root 9224 0.0 0.0 0 0 ? S< May27 0:00 [loop14]
slug9519 9264 0.0 0.0 6244 1492 ? S May27 0:00 /bin/bash /usr/local/bin/thin_launcher 17203 log/server_9519_da8d959_0a56_17203.log 9519_da8d959_0a56
slug9519 9267 0.1 0.8 123456 64928 ? S May27 0:29 /usr/local/bin/ruby /usr/local/bin/thin -p 17203 -e production -R /home/heroku_rack/heroku.ru start
root 12912 0.0 0.0 0 0 ? S< May27 0:00 [loop17]
1090 12928 0.0 0.0 6252 1500 ? S May27 0:00 /bin/bash /usr/local/bin/thin_launcher 20602 log/server_15138_c833c63_5c8e_20602.log 15138_c833c63_5c8e
1090 12930 0.0 0.8 116100 60612 ? S May27 0:01 /usr/local/bin/ruby /usr/local/bin/thin -p 20602 -e production -R /home/heroku_rack/heroku.ru start
root 26763 0.0 0.0 0 0 ? S< May27 0:00 [loop49]
slug1816 26776 0.0 0.0 6244 1492 ? S May27 0:00 /bin/bash /usr/local/bin/thin_launcher 51714 log/server_1816_33835df_a171_51714.log 1816_33835df_a171
slug1816 26778 0.0 0.5 88628 41516 ? S May27 0:01 /usr/local/bin/ruby /usr/local/bin/thin -p 51714 -e production -R /home/heroku_rack/heroku.ru start
root 13891 0.0 0.0 0 0 ? S< 01:13 0:00 [loop36]
root 18816 0.0 0.0 0 0 ? S< 01:20 0:00 [loop52]
系统信息就这些了, 我们的程序跑在 Dyno Grid 中 , heroku 说 Dyno 类似于 mongrel , 其实现在都是 thin了 , 谁叫
mongrel 停止开发了呢.
继续,部属程序的时候, 我的database.yml 是 Mysql 的, 但是在 Dyno 访问的是 PostgreSQL, 应该是 部属的时候,把
database.yml 替换了吧 ? 验证一下database.yml 叫它给重新生成了 .
::::::::::::::
config/database.yml
::::::::::::::
---
production:
encoding: unicode
adapter: postgresql
username: xxxxxxxxxx
port: 5432
host: 10.250.xxx.47
database: xxxxxxxxxx
password: xxxxxxxxxx
heroku还说 memcached 用来保存 page fragment cache , 估计对 production.rb 也改了 , 但是我看了下 , 没有变化, 没有自动使用 memcached? 还是因为我的是 free 的 ?
继续继续, 看着系统进程里面有几个 heroku 自己的服务 , 拿来欣赏一下 :)
::::::::::::::
/etc/rc4.d/S90heroku
::::::::::::::
#!/usr/bin/ruby
LOG="/var/log/heroku_fab.log"
action = ARGV[0]
def start
puts "===== Heroku Fab - begin ====="
puts "Updating Fabber"
output = `cd /root/fabber && git pull`
output = "\nUpdating Fabber\n\n#{output}"
File.open(LOG, 'w') { |f| f.write output }
puts "Calling Preload Fab"
output = `/root/fabber/preload_fab`
output = "\nPreload Fab\n\n#{output}\n"
File.open(LOG, 'a') { |f| f.write output }
puts "Calling Master Fab"
system "echo Calling Master Fab | tee -a #{LOG}"
system "/root/fabber/master_fab 2>&1 | tee -a #{LOG}"
puts "===== Heroku Fab - done ====="
end
if action == 'start'
start
else
puts "Usage: heroku start"
end
root 里面的东西 看不到 ,但是 , 这并不影响咱们看log呀:
Updating f8e4481..b0d5239
Fast forward
lib/support.rb | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
Preload Fab
Moving home, tmp, var, and tmp to disk1...----> Fetching fabber in /root/fabber/
Initialized empty Git repository in /root/fabber/.git/
----> Checking out branch origin/v50
Calling Master Fab
** Proclaiming boot **
true
Initialized empty Git repository in /disk1/tmp/git-sh/.git/
Initialized empty Git repository in /disk1/tmp/git-sh/.git/
cat git-sh.bash git-completion.bash git-sh-config.bash > git-sh
chmod 0755 git-sh
install -m 0755 git-sh /usr/local/bin
alias 'sh' added to ~/.gitconfig
Installing droid lib
----> Fetching droid in /usr/local/droid/ as fabber@
Initialized empty Git repository in /usr/local/droid/.git/
----> Checking out branch origin/v50
Branch v50 set up to track remote branch refs/remotes/origin/v50.
Fixing broken gem permissions...
/root/fabber/lib/railgun.rb:114: warning: parenthesize argument(s) for future version
---- Calling /root/fabber/lib/railgun.rb
Updating railgun
----> Fetching railgun in /home/railgun/ as
----> Checking out branch origin/v50
Branch v50 set up to track remote branch refs/remotes/origin/v50.
Starting railgun web
Installing heroku rack
----> Fetching heroku_rack in /home/heroku_rack/ as
----> Checking out branch origin/v50
Branch v50 set up to track remote branch refs/remotes/origin/v50.
installing /usr/local/bin/service_monitor
Starting Uncle Jimbo
---- verifying firewall
** Proclaiming online **
Sending instance.up
----- verifying connectivity with cloud
ok, done!
Stopping MTA: exim4_listener.
thin_launcher 比较简单
/usr/local/bin/thin_launcher
::::::::::::::
#!/bin/bash
rm -f log/crashlog.log
thin -p $1 -e $RACK_ENV -R /home/heroku_rack/heroku.ru start > $2 2>&1
# create the crashlog if exited without getting explicit kill signal
if [ $? != 0 ]; then
cp $2 log/crashlog.log
fi