我使用Apache-Passenger组合和一个脚本(见下文),但我读了很多关于推动Node的基准。JS在Nginx负载均衡器后面 - 并且至少提供webservices API,这可能是有道理的。
我的脚本是:
def build_a_new_oxenserver()
site = siteurl.gsub(/\./,"_")
system("rake add_site['#{siteurl}','#{site}','#{id}']") if Rails.env.production?
default_tmpl = open(File.expand_path(Rails.root + "public/default_template.html")).read
tmpl = Template.create(:ox_id=>id, :name=>"first template", :content=>default_tmpl)
pg=Page.create(:ox_id=>id, :language_id=>1, :template_id=>tmpl.id, :title=>"Home", :menu_label=>"Zu Hause", :ancestry=>nil, :root=>true)
# add the Paragraph element to this ox's toolbox
self.elements << Element.find(1)
# add an Article, a Paragraph, and a Post
pe = PageElement.create(:element_id => Element.find(1))
pe.elementable = Paragraph.create(:content=>"This is written *in bold* -")
pe.save
pg.page_elements << pe
end
的add_site耙确实在生产服务器上的远程工作 - 创建必要的文件夹,配置文件和链接脚本来得到一个新的“实例”上运行。通过这种方式,我可以扩展我的服务,并且只需付出一点努力,我就能够扩展负载平衡功能。
请注意,此解决方案是一个“共享源代码”版本
搂草脚本是这样的:
#
# rake add_site["www.domain.tld", "www_domain_tld", 131]
desc "Task for adding new oxenserver site"
task :add_site, :domain, :site, :ox_id do |t, args|
service_path = /data/www/html/app_service
site_string = %{
<VirtualHost *:80>
ServerName #{args[:domain]}
DocumentRoot #{service_path}/sites/#{args[:site]}/public
PassengerAppRoot #{service_path}/sites/#{args[:site]}
SetEnv OX_ID #{args[:ox_id]}
<Directory #{service_path}/sites/#{args[:site]}/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
}
File.open("tmp/#{args[:site]}.conf", "w") do |f|
f.write site_string
end
site_start = %{
mv #{service_path}/current/tmp/#{args[:site]}.conf /data/apache/conf.d/#{args[:site]}.conf
service httpd restart
}
File.open("tmp/#{args[:site]}.sh", "w") do |f|
f.write site_start
end
#
sites_dir = "#{service_path}/sites/#{args[:site]}"
shared_sites_dir = "#{service_path}/shared/sites/#{args[:site]}"
shared_oxen_dir = "#{service_path}/shared/sites/oxen"
current = "#{service_path}/current"
# prepare system files/directories
system "mkdir #{sites_dir} #{shared_sites_dir} #{shared_sites_dir}/public"
system "cd #{sites_dir} && cp -rus #{current}/* ."
system "cd #{shared_sites_dir}/public && cp -r #{shared_oxen_dir}/public/* ."
system "cd #{shared_sites_dir} && mkdir log tmp && cd #{sites_dir} && rm -rf public log tmp && ln -s #{shared_sites_dir}/public public && ln -s #{shared_sites_dir}/log log && ln -s #{shared_sites_dir}/tmp tmp"
system "cd #{sites_dir} && touch tmp/restart.txt log/production.log"
system "mv tmp/#{args[:site]}.sh public/system/job_queue/#{args[:site]}.sh"
end
观看http://confreaks.net/videos/709-rubyconf2011-threading-versus-evented后,您可能想要更改为jRuby。与乘客nginx是一个更普遍的路径去。 – drhenner 2011-12-22 17:01:56
@ user458221谢谢,我会看看这个视频:) 虽然我关心的是更多关于当下的架构和设计选择! 但我猜这值得担心表现呢^^ – 2011-12-22 18:52:23