最后关于nginx+passenger+ror+mysql的安装部署过程
前置庫安裝
?
sudo apt-get install gcc sudo apt-get install build-essentialsudo apt-get install gcc g++ build-essential libssl-dev libreadline5-dev zlib1g-dev linux-headers-genericsudo?apt-get?install?zlib1g-dev?libssl-dev?libreadline5-dev?libxml2-dev sudo apt-get install libcurl4-openssl-dev libssl-dev zlib1g-dev libreadline5-devsudo apt-get install curl git-core?
?
sudo apt-get install bison build-essential zlib1g zlib1g-dev libssl-dev libreadline5-dev libxml2-dev subversion autoconf安裝RVMbash < <( 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 notestype rvm | head -n1 result is :rvm is a function安裝ruby 1.9.2rvm listrvm 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-devsudo apt-get install build-essential libpcre3-dev libssl-dev libxslt-dev libgd2-xpm-dev libgeoip-dev zlib1g-devwget 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.67Please 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 Railsapplications on Nginx.Deploying a Ruby on Rails application: an exampleSuppose you have a Ruby on Rails application in /somewhere. Add a server blockto 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 andoptimization 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.confnginx.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來檢測配置的正確性安裝并配置mysqlsudo apt-get install mysql-server-5.1sudo 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 tzselectsudo cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime?sudo ntpdate cn.pool.ntp.orgdate 重啟mysql服務sudo service mysql restart 檢查前面的設置mysql -uroot -pmysql> 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>?
3)mysql> select host,user,password from user;
4)grant all privileges on *.* to? root@192.168.1.100 ?identified by 'password'?grant?all?on?*.*?to?root@'%'?identified?by?'密碼';?
?注意: (1)192.168.15.101是欲連接到此Mysql數據庫的客戶端的IP地址,而不是Mysql數據庫所在數據庫服務器的IP地址,切記
????????????? (2)password就是Mysql數據庫root用戶的password,根據實際情況需要修改
use mysql;上傳程序及mysql數據腳本備份將數據導入mysql,生產庫和開發庫使用一模一樣的配置mysql -uroot -pxxxx <2010-12-11進行備份數據導入,相應的導出腳本為mysqldump --database b2c2_development -uroot -pxxxx >20101210使用cron作每日備份bachup_mysql.sh#!/bin/shname=$(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?imagemagickpaperclip插件需要這個庫預先裝,一般情況下已經裝了
安裝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.javaeye.com/blog/756391
http://rvm.beginrescueend.com/integration/passenger/
http://ivice.javaeye.com/blog/730795
?
passenger命令
mlzboy@mlzboy:~$ rvmsudo passenger-status
----------- General information -----------
max ? ? ?= 6
count ? ?= 0
active ? = 0
inactive = 0
Waiting on global queue: 0
?
----------- Application groups -----------
mlzboy@mlzboy:~$ rvmsudo passenger-status^C
mlzboy@mlzboy:~$ rvmsudo passenger-memory-stats
------------- Apache processes -------------
*** WARNING: The Apache executable cannot be found.
Please set the APXS2 environment variable to your 'apxs2' executable's filename, or set the HTTPD environment variable to your 'httpd' or 'apache2' executable's filename.
?
?
-------- Nginx processes --------
PID ?PPID ?VMSize ?Private ?Name
---------------------------------
985 ?1 ? ? 6.1 MB ?0.1 MB ? nginx: master process /usr/local/nginx/sbin/nginx
986 ?985 ? 6.4 MB ?0.3 MB ? nginx: worker process
### Processes: 2
### Total private dirty RSS: 0.42 MB
?
?
--- Passenger processes ----
PID ?VMSize ? Private ?Name
----------------------------
945 ?4.2 MB ? 0.2 MB ? PassengerWatchdog
948 ?17.4 MB ?0.5 MB ? PassengerHelperAgent
950 ?10.4 MB ?4.5 MB ? Passenger spawn server
953 ?9.2 MB ? 0.5 MB ? PassengerLoggingAgent
### Processes: 4
### Total private dirty RSS: 5.75 MB
?
?
總結
以上是生活随笔為你收集整理的最后关于nginx+passenger+ror+mysql的安装部署过程的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C# 枚举在项目中的应用总结
- 下一篇: VS Tips]Visual Studi