1、阿里云的一鍵安裝web全環境
下載一鍵安裝web全環境 sh.zip 壓縮包
上傳至服務器,解壓、執行腳本,具體步驟詳見這里
$ mv sh.zip /home/tmp/ & cd /home/tmp $ unzip sh.zip $ chmod -R 777 sh & cd sh # 任意選擇一種方法執行腳本 # 方法一 $ ./install.sh # 方法二 $ ./install_nginx_xxx.sh $ ./install_mysql_xxx.sh
2、安裝RVM與指定的Ruby版本
安裝RVM與指定的Ruby版本
$ curl -L https://get.rvm.io | bash -s stable --ruby=1.9.3 # 注意安裝完成后,根據提示執行source命令
查看是否安裝成功
$ ruby -v ruby 1.9.3p448 (2013-06-27 revision 41675) [i686-linux] $ gem -v 2.1.9
更換 gem source,提高gem下載速度
$ gem source -r https://rubygems.org/ $ gem source -a http://ruby.taobao.org
3、安裝git、編譯 javascript 運行時環境 node.js
安裝git工具
$ yum install git
編譯node.js(javascript運行時環境)
$ git clone https://github.com/joyent/node.git $ cd node $ ./configure && make && make install #如果無法編譯,說名需要叫python升級到2.6或2.7 #如果缺少bz2,需要yum install bzip2-devel后,重新編譯python
克隆你的項目
$ git clone path/to/your/project.git # 安裝項目指定gem包 $ cd path/to/your/project $ bundle install
4、配置unicorn文件并運行生產環境
查看unicorn配置實例 config/unicorn.rb
啟動unicron生產環境
$ unicorn_rails -c config/unicorn.rb -E production -D
關閉unicorn進程
$ kill -9 $(cat tmp/pids/unicorn.pid )
5、配置nginx虛擬主機
添加nginx虛擬主機配置
$ vim /path/to/your/nginx/vhosts/xxxx.conf
配置內容(將漢字替換成相應有效內容):
upstream unicorn_server { server unix:項目根目錄/tmp/sockets/unicorn.sock fail_timeout=0; } server { listen 80; server_name 域名; root 項目根目錄/public; location / { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_buffering on; if (!-f $request_filename) { proxy_pass http://unicorn_server; break; } } location ~ ^/(assets)/ { expires max; add_header Cache-Control public; } }
友情提示
低內存服務器添加內存釋放任務
$ vim /etc/crontab
在最后一行添加如下內容(每天凌晨1點釋放內存):
00 1 * * * echo 3 > /proc/sys/vm/drop_caches