Centos 5.5 VPS下部署Rails3环境,RubyEE,+nginx+Passenger+mysql

这二天部署一个项目,部署在Centos 5.5 下,本来用的ubuntu 10.4,结果由于 paperclip和passenger的问题,放弃了。换成Centos后,问题消失。记录下


1,yum update,

2.安装必要的一些包,
yum groupinstall "Development Tools"、
yum install zlib-devel wget openssl-devel pcre pcre-devel


3.下载rubyee1.8.7
  
wget http://rubyforge.org/frs/download.php/71096/ruby-enterprise-1.8.7-2010.02.tar.gz


4,解压
 
tar xzvf ruby-enterprise-1.8.7-2010.02.tar.gz
(下载的版本)

5.安装
  .
/ruby-enterprise-1.8.7-2010.02/installer

  如果有依赖包没安装的话会有提示,按提示安装。中间选择下你安装的路径,我安到/opt/rubyee下了,然后一路安装下,会花点时间,
  安装后,修改 /etc/profile,把rubyee路径加上,如我的是/opt/rubyee/bin;
  ruby -v看下,如果没问题说明安装成功

6 安装Passenger和nginx
  rubyee带了passenger,直接
/opt/rubyee/bin/passenger-install-nginx-module

然后,安提示安装,我用了默认的, 安在了/opt/nginx 下

7。vim /etc/rc.d/init.d/nginx
添加如下
 
#!/bin/sh
#
# nginx – this script starts and stops the nginx daemin
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /opt/nginx/conf/nginx.conf
# pidfile: /opt/nginx/logs/nginx.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

nginx="/opt/nginx/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/opt/nginx/conf/nginx.conf"

lockfile=/var/lock/subsys/nginx

start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}

stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}

restart() {
configtest || return $?
stop
start
}

reload() {
configtest || return $?
echo -n $”Reloading $prog: ”
killproc $nginx -HUP
RETVAL=$?
echo
}

force_reload() {
restart
}

configtest() {
$nginx -t -c $NGINX_CONF_FILE
}

rh_status() {
status $prog
}

rh_status_q() {
rh_status >/dev/null 2>&1
}

case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac


8.
chmod +x /etc/rc.d/init.d/nginx
chkconfig --add nginx
chkconfig --level 35 nginx on


9.启动nginx
/etc/rc.d/init.d/nginx start

如果没问题,可用ip访问下看看,正常显示的话说明成功

10。安装mysql
  yum install mysql-server
/sbin/chkconfig --levels 235 mysqld on

启动service mysqld start

11.安装mysql gem
yum install mysql-devel

gem install mysql --no-rdoc --no-ri -- --with-mysql-dir=/usr/bin --with-mysql-lib=/usr/lib/mysql --with-mysql-include=/usr/include/mysql


12.安装rails3
 sudo gem install rails --pre --no-ri --no-rdoc


13.安装git (ubuntu直接  sudo apt-get git-core就OK)
wget http://kernel.org/pub/software/scm/git/git-1.7.1.tar.gz

tar -xzvf git-1.7.1.tar.gz

cd git-1.7.1

./configure --prefix=/usr/local

make

sudo make install


13. 安装ImageMagic
 
 wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz

           tar xvfz ImageMagick.tar.gz
             cd  ImageMagick-6.6.3-2
             ./configure
              make
              sudo make install

我直接用的默认路径,这样会安在/usr/local/bin
这里路径要注意,在passenger中 用paperclip会出现个错误,必须为paperclip的配置文件中加上Paperclip.options[:command_path] = '/usr/local/bin' ,,我在 ubuntu中加上后,只能上传 gif,的,其它格式的图片一传仍然报错,,最后搞了半天没办法,换甩 Centos没问题了。。


14.配置nginx
   
vim /opt/nginx/conf/nginx.conf

    加上
 
 server {
    listen 80;
    # server_name www.sitename.com;
    root /home/sites/websits/current/public;
(注意一定要是public 目录,前面是网站的存放目录 )   
     passenger_enabled on;
}


所有环境搞琮后就是上传部署了,我最终选择了capistrano,,部署后要注意的是网站目录的写权限,上传图片如果没有写权限会出错。。。


你可能感兴趣的:(nginx,mysql,centos,git,Ruby)