知识共享许可协议
本作品采用知识共享署名-非商业性使用-禁止演绎 3.0 未本地化版本许可协议进行许可。

Rails on Debain (Nginx + Passenger) 安装记录

各版本说明

  • Debian GNU/Linux 7
  • Linux debian 3.2.0-4-amd64 #1 SMP Debian 3.2.57-3 x86_64 GNU/Linux
  • ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux]
  • rvm 1.25.25 (stable)
  • gem 2.2.2
  • Bundler version 1.6.2
  • node v0.10.28
  • nginx version: nginx/1.4.7
  • Phusion Passenger version 4.0.41
  • Rails 4.1.1

安装基础软件

  • 更新源

    vim /etc/apt/sources.list
    修改成 http://mirrors.yun-idc.org 的源
    
  • 增加 Passenger 的源

    vim  /etc/apt/sources.list.d/passenger.list
    deb https://oss-binaries.phusionpassenger.com/apt/passenger wheezy main
    
    apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7
    
  • 安装 apt-transport-https

    apt-get install apt-transport-https
    
  • 更新

    apt-get update
    apt-get upgrade
    
  • 安装软件

    apt-get install curl wget build-essential libcurl4-openssl-dev cmake
    

安装Rails

  • 安装rvm

    curl -L https://get.rvm.io | bash -s stable
    source /etc/profile.d/rvm.sh
    rvm -v
    
  • 安装Ruby

    rvm install 2.1.1
    rvm 2.1.1 --default
    ruby -v
    gem -v
    gem source -r https://rubygems.org/
    gem source -a http://ruby.taobao.org
    
  • 安装Rails

    gem install rails
    rails -v
    

安装Node.js

  • 下载解压

    wget http://nodejs.org/dist/v0.10.28/node-v0.10.28.tar.gz
    tar zxvf node-v0.10.28.tar.gz
    cd node-v0.10.28
    
  • 配置编译安装

    ./configure
    make
    make install
    

安装Nginx & Passenger

  • 移除旧的nginx

    apt-get remove nginx nginx-full nginx-light nginx-naxsi nginx-common
    
  • 安装Passenger

    apt-get install nginx-extras passenger
    
  • 安装模块

    passenger-install-nginx-module
    

配置nginx

  • 打开配置文件

    vim /etc/nginx/nginx.conf
    
  • 设置 Passenger 参数

    passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
    passenger_ruby /usr/local/rvm/gems/ruby-2.1.1/wrappers/ruby;
    
  • 设置 server

    server {
        listen 80;
        server_name _;
        root /data0/www/public;
        passenger_enabled on;
    }
    

安装MySQL

  • 下载解压

    http://www.percona.com/redir/downloads/Percona-Server-5.6/LATEST/source/tarball/percona-server-5.6.17-65.0.tar.gz
    tar zxvf percona-server-5.6.17-65.0.tar.gz
    cd percona-server-5.6.17-65.0
    
  • 系统用户设置

    groupadd mysql && useradd -g mysql mysql && mkdir -p /opt/mysql && mkdir -p /data1/mysql && chown -R mysql:mysql /data1/mysql
    
  • cmake

    cmake -DCMAKE_INSTALL_PREFIX=/opt/mysql \
    -DMYSQL_UNIX_ADDR=/data1/mysql/mysql.sock \
    -DDEFAULT_CHARSET=gbk \
    -DDEFAULT_COLLATION=gbk_chinese_ci \
    -DWITH_EXTRA_CHARSETS:STRING=armscii8,ascii,big5,cp1250,cp1251,cp1256,cp1257,cp850,cp852,cp866,cp932,dec8,eucjpms,euckr,gb2312,gbk,geostd8,greek,hebrew,hp8,keybcs2,koi8r,koi8u,latin1,latin2,latin5,latin7,macce,macroman,sjis,swe7,tis620,ucs2,ujis,utf8 \
    -DWITH_MYISAM_STORAGE_ENGINE=1 \
    -DWITH_INNOBASE_STORAGE_ENGINE=1 \
    -DWITH_MEMORY_STORAGE_ENGINE=1 \
    -DWITH_READLINE=1 \
    -DENABLED_LOCAL_INFILE=1 \
    -DMYSQL_DATADIR=/data1/mysql \
    -DMYSQL_USER=mysql \
    -DMYSQL_TCP_PORT=3306
    
  • 编译安装

    make && make install    
    
  • 安装开发包

    apt-get install libmysqlclient-dev libmysql-ruby
    
  • 设置启动脚本

    cp ./support-files/mysql.server /etc/init.d/mysqld && chmod 755 /etc/init.d/mysqld
    
  • 设置开机自动启动

    vim /etc/rc.local
    /etc/init.d/mysqld start
    
  • 更新配置文件

    vim /etc/mysql/my.cnf
    #basedir                = /usr
    #datadir                = /var/lib/mysql
    lc-messages-dir = /opt/mysql/share
    
  • 初始化数据库

    chmod 755 ./scripts/mysql_install_db && ./scripts/mysql_install_db --user=mysql --basedir=/opt/mysql --datadir=/data1/mysql
    
  • 增加软链接

    ln -s /opt/mysql/bin/mysql /usr/bin/mysql
    
  • 启动

    service mysqld start
    
  • 修改密码

    /opt/mysql/bin/mysqladmin -u root password '123123'
    
  • 重启

    service mysqld restart