`
mlzboy
  • 浏览: 703707 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

最后关于nginx+passenger+ror+mysql的安装部署过程

阅读更多

前置库安装

 

sudo apt-get install gcc
sudo apt-get install build-essential
sudo apt-get install gcc g++ build-essential libssl-dev libreadline5-dev zlib1g-dev linux-headers-generic
sudo apt-get install zlib1g-dev libssl-dev libreadline5-dev libxml2-dev

sudo apt-get install libcurl4-openssl-dev libssl-dev zlib1g-dev libreadline5-dev
sudo apt-get install curl  git-core

 


sudo apt-get install bison build-essential zlib1g zlib1g-dev libssl-dev libreadline5-dev libxml2-dev subversion autoconf
安装RVM
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
sudo vi /home/mlzboy/.bashrc
将[ -z "$PS1" ] && return替换为 if [[ -n "$PS1" ]] ; then

 


在最后加上
fi # <= be sure to close the if at the end of the .bashrc.
# This is a good place to source rvm v v v
 [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"  # This loads RVM into a shell session.

使用source ~/.bashrc 可使更改立刻生效,也可新打开终端
进行测试
rvm notes
type rvm | head -n1 
result is :rvm is a function
安装ruby 1.9.2
rvm list
rvm install 1.9.2

 



 

 

 

  在安装完rails1.9.2后,将它设为默认的 rvm 1.9.2 --default 安装passenger gem install passenger 安装nginx 备份旧的nginx可执行文件及目录特别是nginx.conf,并将原来运行的nginx进程停止,虽然书上说可以进行平滑升级。 查看原有nginx配置参数 strings /usr/local/nginx/sbin/nginx | grep configure --add-module=../uwsgi-0.9.5.4/nginx/ --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module

 
sudo apt-get install libpcre3 libpcre3-dev sudo apt-get install libcurl4-openssl-dev   sudo apt-get install openssl libssl-dev
sudo apt-get install build-essential libpcre3-dev libssl-dev libxslt-dev libgd2-xpm-dev libgeoip-dev zlib1g-dev
wget http://nginx.org/download/nginx-0.7.67.tar.gz

tar xvf nginx-0.7.67.tar.gz

使用rvmsudo passenger-install-nginx-module进行升级安装nginx

根据提示:Please specify the directory: /home/mlzboy/nginx-0.7.67
Please specify a prefix directory [/opt/nginx]: /usr/local/nginx
Extra arguments to pass to configure script:  --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module
完成后会提示两段话

Nginx with Passenger support was successfully installed.
Please edit your Nginx configuration file (probably /usr/local/nginx/conf/nginx.conf),
and set the passenger_root and passenger_ruby configuration options in the
'http' block, like this:
  http {
      ...
      passenger_root /home/mlzboy/.rvm/gems/ruby-1.9.2-p0/gems/passenger-3.0.1;
      passenger_ruby /home/mlzboy/.rvm/wrappers/ruby-1.9.2-p0/ruby;
      ...
  }
After you (re)start Nginx, you are ready to deploy any number of Ruby on Rails
applications on Nginx.
Deploying a Ruby on Rails application: an example
Suppose you have a Ruby on Rails application in /somewhere. Add a server block
to your Nginx configuration file, set its root to /somewhere/public, and set
'passenger_enabled on', like this:

   server {
      listen 80;
      server_name www.yourhost.com;
      root /somewhere/public;   # <--- be sure to point to 'public'!
      passenger_enabled on;
   }

And that's it! You may also want to check the Users Guide for security and
optimization tips and other useful information:

  /home/mlzboy/.rvm/gems/ruby-1.9.2-p0/gems/passenger-3.0.1/doc/Users guide Nginx.html
从目前的情况来看,如果原有nginx则nginx.conf不会被覆盖
sudo /usr/local/nginx/conf/nginx.conf
nginx.conf以下部分进行更改
在第1行
user mlzboy;

在http{...}节内

 

加入以下两行
      passenger_root /home/mlzboy/.rvm/gems/ruby-1.9.2-p0/gems/passenger-3.0.1;
      passenger_ruby /home/mlzboy/.rvm/wrappers/ruby-1.9.2-p0/ruby;
在server节加入如下,局部根据具体情况更改
    server { 
 listen       80;
 server_name  localhost; 
 root    /home/mlzboy/my/b2c2/public;
 passenger_enabled on;
 rails_env       development;
保存后使用./sbin/nginx -t来检测配置的正确性
安装并配置mysql
sudo apt-get install mysql-server-5.1
sudo vi /etc/mysql/my.cnf
做以下更改以达到,能被外部访问,中国时区,utf-8支持,红色标记为改动部分
[client]
default-character-set=utf8
port            = 3306
socket          = /var/run/mysqld/mysqld.sock

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket          = /var/run/mysqld/mysqld.sock
nice            = 0

[mysqld]
default-character-set=utf8
init_connect='SET NAMES utf8'
default-time-zone = '+8:00'
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address           = 127.0.0.1

更改系统时区

sudo tzselect
sudo cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
 sudo ntpdate cn.pool.ntp.org
date

重启mysql服务
sudo service mysql restart
检查前面的设置
mysql -uroot -p
mysql> show variables like '%time_zone%';
+------------------+--------+
| Variable_name    | Value  |
+------------------+--------+
| system_time_zone | CST    |
| time_zone        | +08:00 |
+------------------+--------+
2 rows in set (0.00 sec)

mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2010-12-10 22:22:26 |
+---------------------+
1 row in set (0.00 sec)

mysql> show variables like 'character%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
使外网特定ip能访问远程mysql,还需要进行以下配置
二、Mysql数据库的修改
1) [root@etc etc]# mysql -u  root  -p
Enter password:
2)mysql> use mysql;
3)mysql> select host,user,password from user;
4)grant all privileges on *.* to  root@192.168.1.100  identified by 'password'
 注意: (1)192.168.15.101是欲连接到此Mysql数据库的客户端的IP地址,而不是Mysql数据库所在数据库服务器的IP地址,切记
              (2)password就是Mysql数据库root用户的password,根据实际情况需要修改

上传程序及mysql数据脚本备份
将数据导入mysql,生产库和开发库使用一模一样的配置
mysql -uroot -pxxxx <2010-12-11进行备份数据导入,相应的导出脚本为mysqldump --database b2c2_development -uroot -pxxxx >20101210
使用cron作每日备份
bachup_mysql.sh
#!/bin/sh
name=$(date +%Y-%m-%d)
/usr/bin/mysqldump --database b2c2_development -uroot -pzhoubt | /bin/gzip>/home/mlzboy/my/backup_mysql/$name.gz 
安装bundler及程序相关的依赖项
gem install bundler(注意是bundler,不是bundle)
sudo apt-get install imagemagick
paperclip插件需要这个库预先装,一般情况下已经装了

安装rails3的mysql2 gem需要sudo apt-get install libmysql-ruby libmysqlclient-dev

安装sqlite3-rubygem需要下面这个库的支持sudo apt-get install libsqlite3-dev  

 



进入b2c2项目使用bundle install进行安装

 

passenger集成文档
http://rvm.beginrescueend.com/integration/passenger/

 

http://xcell.me/posts/3-installing-rails-3-through-rvm

http://thoughtrails.com/episodes/4-deployment-of-production-enviroment-ruby-1-9-2-rails-3-nginx-passenger-and-postgresql-with-rvm

http://ivice.iteye.com/blog/756391

http://rvm.beginrescueend.com/integration/passenger/

http://ivice.iteye.com/blog/730795

今天为测试完成部署的辛勤劳动成果展

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics