Category Archives: 部署

自定义capistrano维护页面

capistrano是目前最为流行的Rails部署工具,不过一旦进入产品阶段,我们可能希望在部署时显示一个“站点正在维护中”的页面,而不是正在升级中的应用,当前版本(2.5)的capistrano提供了两个内置任务来完成这一工作,它们就是deploy:web:disable和 deploy:web:enable,如果你仔细查看capistrano的部署目录,会在current/public目录下发现一个system目录,它是一个指向shared/system的链接,因此我们首先需要在shared目录下建立system目录,capistrano使用它来存放维护页面。 server$ mkdir deploy/shared 现在如果我们执行cap deploy:web:disable,capistrano会通过sftp上传一个默认的站点维护页面到shared/system /maintenance.html,而deploy:web:enable则会将这个页面删除,但是这个任务本身并不能将应用屏蔽掉,我们需要修改前端服务器的rewrite规则。 如果你使用nginx,那么加入下面几行到你的nginx.conf: server {   root /current/deploy/path/public;   if (-f $document_root/system/maintenance.html) {     set $maintenance 1;   }   if ($request_uri ~* (jpg|jpeg|gif|js|css)$) {     set $maintenance 0;   }   if ($maintenance) {     rewrite ^(.*)$ /system/maintenance.html last;     break;   }   location / {     …. 这样nginx会首先判断维护页面是否存在,如果存在,则将所有清除都转向维护页面,如果使用apache,则需要修改.htaccess(未验证): RewriteCond %{REQUEST_URI} !\.(css|jpg|js|gif|png)$ RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f RewriteCond %{SCRIPT_FILENAME} !maintenance.html RewriteRule ^.*$ [...]

Posted in 部署 | 1 Comment

nginx+mongrel cluster配置指南

准备工作 安装PCRE库: $ ftp ftp.csx.cam.ac.uk username: anonymous > cd pub/software/programming/pcre/ > get pcre-7.4.tar.bz2 > quit $ tar -jxvf pcre-7.4.tar.bz2 $ cd pcre-7.4 $ ./configure $ make 不需要安装它,只是编译nginx时需要用到而已。 安装nginx $ wget http://sysoev.ru/nginx/nginx-0.5.32.tar.gz $ tar -zxvf nginx-0.5.32.tar.gz $ cd nginx-0.5.32 $ ./configure –with-pcre=../pcre-7.4 $ make $ sudo make install 配置nginx 修改/usr/local/nginx/conf/nginx.conf: user someuser; worker_processes 1; error_log logs/error.log [...]

Posted in 部署 | 2 Comments

Rails部署艺术

翻译自:Ezra Zygmuntowicz, “Xen and the Art of Rails Deployment” 听到Rails部署这两词,可能你首先想到的是下面这堆东西: CGI Apache1.3/mod_fastcgi Lighttpd/fcgi Apache2/mod_fcgid Lighttpd/SCGI Lightspeed 但时代已经变了,新时代需要新思维 Mongrel:The year of the dog Mongrel是由Zed Shaw完成的一个HTTP Server,它: 使用Ragel + C的快速HTTP解析 使用C的快速URI过滤器 堆栈式请求处理 配置灵活 安全同时兼容RFC的HTTP解析器 Mongrel就足够了? 答案是:不够,因为: Rails请求分发需要使用互斥锁 一个Mongrel实例只能同时处理一个请求 需要使用Mongrel_cluster创建多个实例来获取可伸缩性 因此,你仍然需要一个前端HTTP Server,幸好有一大堆: Pen,Pound,Balance,Haproxy(不支持静态文件,只是代理) Lightspeed,支持静态文件和代理 Apache2.2.x/mod_proxy_balancer,同上 这就搞定了?还不行: Pen(不支持SSL,不能限制连接速率) Pound(不支持高负载,不能限制链接速率) Haproxy(可限制连接速率,性能非常高,不支持静态文件 Lightspeed,免费版功能严重残缺 Apache2.2.x,没什么不好,就是:太臃肿了 那怎么办? Nginx:From Russia, with Love Nginx有什么好处: 专为性能优化而开发,性能是其最重要的考量 [...]

Posted in 部署 | Leave a comment