国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

Linux系統(tǒng)上配置Nginx+Ruby on Rails+MySQL超攻略

2019-10-26 19:27:51
字體:
供稿:網(wǎng)友

安裝 RVM

通常使用 RVM 或 rbenv 來安裝 Ruby,這里選用 RVM。

$ curl -sSL https://get.rvm.io | bash -s stable

載入 RVM :

$ source /home/libuchao/.rvm/scripts/rvm$ rvm -vrvm 1.25.12 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com> ......

再執(zhí)行以下命令:

$ type rvmrvm is a function......

說明 RVM 安裝正確。
安裝 Ruby

用 RVM 安裝 Ruby

$ rvm install 2.1.0$ rvm use 2.1.0 --default$ ruby -vruby 2.1.0p0

國內(nèi)服務器推薦替換 RubyGems 的到淘寶鏡像

$ gem sources -r https://rubygems.org/$ gem sources -a http://ruby.taobao.org/

否則安裝 Gem 可能會非常非常慢。
安裝 Rails

其實 Rails 也是一個 Gem

$ gem install rails --no-ri --no-rdoc -V......$ rails -vRails 4.0.2

至此,Rails 環(huán)境已經(jīng)安裝完成。
安裝 MySQL

安裝 Mysql 及相應的庫文件:

$ sudo apt-get install mysql-server libmysqlclient-dev

然后進行一些安裝方面的設置:

$ /usr/bin/mysql_secure_installation

創(chuàng)建相應的數(shù)據(jù)庫,并為它新建一個權限小一些的用戶:

mysql> CREATE DATABASE blix_production;mysql> GRANT ALL PRIVILEGES ON blix_production.* TO blix@localhost IDENTIFIED BY "123456";mysql> flush privileges;mysql> exit

導入數(shù)據(jù):

$ mysql -u blix -p blix_production < database.sql

安裝 Nginx

Nginx 專門處理靜態(tài)請求,并作為 Unicorn 的反向代理

編輯 /etc/apt/sources.list,末尾處添加以下兩行

deb http://nginx.org/packages/ubuntu/ precise nginxdeb-src http://nginx.org/packages/ubuntu/ precise nginx

添加 Nginx 簽名

$ wget http://nginx.org/keys/nginx_signing.key$ sudo apt-key add nginx_signing.key

安裝 Nginx

$ sudo apt-get update$ sudo apt-get install nginx

安裝完成后可以在瀏覽器中輸入 http://server-ipaddress 查看是否安裝正確。
配置 Unicorn

首先編譯一下靜態(tài)文件:

$ RAILS_ENV=production rake assets:clean$ RAILS_ENV=production rake assets:precompile

Unicorn 配置參考:

worker_processes 2timeout 30APP_PATH = File.expand_path("../..", __FILE__)working_directory APP_PATHlisten 8080, :tcp_nopush => truelisten "/tmp/unicorn.sock", :backlog => 64stderr_path APP_PATH + "/log/unicorn.stderr.log"stdout_path APP_PATH + "/log/unicorn.stdout.log"pid APP_PATH + "/tmp/pids/unicorn.pid"

Unicorn 自啟動腳本:

#!/bin/shset -e# Example init script, this can be used with nginx, too,# since nginx and unicorn accept the same signals# Feel free to change any of the following variables for your app:TIMEOUT=${TIMEOUT-60}APP_ROOT=/home/libuchao/blixAPP_USER=libuchaoPID=$APP_ROOT/tmp/pids/unicorn.pidCMD="unicorn_rails -D -E production -c $APP_ROOT/config/unicorn.rb"action="$1"set -uold_pid="$PID.oldbin"cd $APP_ROOT || exit 1sig () {    test -s "$PID" && kill -$1 `cat $PID`}oldsig () {    test -s $old_pid && kill -$1 `cat $old_pid`}case $action instart)    sig 0 && echo >&2 "Already running" && exit 0    su -c "$CMD" - $APP_USER    ;;stop)    sig QUIT && exit 0    echo >&2 "Not running"    ;;force-stop)    sig TERM && exit 0    echo >&2 "Not running"    ;;restart|reload)    sig HUP && echo reloaded OK && exit 0    echo >&2 "Couldn't reload, starting '$CMD' instead"    su -c "$CMD" - $APP_USER    ;;upgrade)    if sig USR2 && sleep 2 && sig 0 && oldsig QUIT    then        n=$TIMEOUT        while test -s $old_pid && test $n -ge 0        do            printf '.' && sleep 1 && n=$(( $n - 1 ))        done        echo        if test $n -lt 0 && test -s $old_pid        then            echo >&2 "$old_pid still exists after $TIMEOUT seconds"            exit 1        fi        exit 0    fi    echo >&2 "Couldn't upgrade, starting '$CMD' instead"    su -c "$CMD" - $APP_USER    ;;reopen-logs)    sig USR1    ;;*)    echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"    exit 1    ;;esac            
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 襄汾县| 沁水县| 安泽县| 平舆县| 惠州市| 平阴县| 兰考县| 房产| 浪卡子县| 山东| 屯门区| 内江市| 虞城县| 射洪县| 木里| 壤塘县| 富宁县| 盐亭县| 玉山县| 铁力市| 华池县| 商水县| 岢岚县| 淮滨县| 麦盖提县| 湘潭市| 沿河| 渑池县| 蒲城县| 都匀市| 玉溪市| 通山县| 十堰市| 汉沽区| 滦南县| 漾濞| 寿光市| 榆中县| 镶黄旗| 宝丰县| 江都市|