您的位置:首页 > 运维架构 > Nginx

CentOS7 Nginx+mongrel+rails部署及部署(之rails篇)

2014-10-12 21:05 337 查看
1.安装ruby(1.8.7)

1.1 安装依赖

yum install -y zlib zlib-devel

1.2 安装ruby,下载ruby:

wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p374.tar.gz
进入下载目录解压:

tar -zxvf ruby-1.8.7-p374.tar.gz

进入解压后的目录,编译安装:

./configure --enable-pthread

make

sudo make install

安装完毕,查看版本:

ruby -v

ruby 1.8.7 (2013-06-27 patchlevel 374) [x86_64-linux]

2. 安装rubygems (1.8.25)

sudo yum -y install rubygems

安装完成查看版本:

gem -v

2.0.14

rubygems的版本高于1.8.25会存在
uninitialized constant Gem::SourceIndex (NameError)
问题。

首先,需要降版本为1.8.25:

gem update --system 1.8.25


其次,卸载版本高于1.8.25的rubygems已安装版本:


gem uninstall rubygems-update --version '> 1.8.25'


[/code]

再次查看gem版本,

gem -v

1.8.25

3. 添加gem镜像

3.1查看源

gem sources -l

*** CURRENT SOURCES ***
http://rubygems.org/
由于被墙,故需要改为国内镜像,具体操作如下:

gem sources --remove http://rubygems.org/
gem sources -a http://ruby.taobao.org/
查看修改后的镜像源:

gem sources -l

*** CURRENT SOURCES ***
http://ruby.taobao.org/
4. 安装rails(3.2)

4.1 gem安装rails 3.2.0

sudo gem install rails -V -v 3.2 --include-dependencies

查看版本:

rails -v

Rails 3.2.0

4.2 测试rails工程

rails新建工程,

rails new blog --skip-bundle

进入工程根目录,启动rails服务:

rails server

如果出现如下错误:

Could not find gem 'jquery-rails (>= 0) ruby' in the gems available on this machine.

则根据提示执行:

bundle install

如果出现如下错误信息:

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb

mkmf.rb can't find header files for ruby at /usr/share/include/ruby.h

Gem files will remain installed in /home/zhangwei/.gem/ruby/gems/json-1.8.1 for inspection.

Results logged to /home/zhangwei/.gem/ruby/gems/json-1.8.1/ext/json/ext/generator/gem_make.out

An error occurred while installing json (1.8.1), and Bundler cannot continue.

Make sure that `gem install json -v '1.8.1'` succeeds before bundling.

则首先解决can't find header files for ruby at /usr/share/include/ruby.h错误,执行:

sudo yum install ruby-devel -y
安装完毕后,再次运行
bundle install
如果出现如下错误:

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal',
'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
and check your shared library search path (the
location where your sqlite3 shared library is located).
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib64
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/ruby
--with-sqlite3-dir
--without-sqlite3-dir
--with-sqlite3-include
--without-sqlite3-include=${sqlite3-dir}/include
--with-sqlite3-lib
--without-sqlite3-lib=${sqlite3-dir}/
--enable-local
--disable-local

Gem files will remain installed in /home/zhangwei/.gem/ruby/gems/sqlite3-1.3.9 for inspection.
Results logged to /home/zhangwei/.gem/ruby/gems/sqlite3-1.3.9/ext/sqlite3/gem_make.out
An error occurred while installing sqlite3 (1.3.9), and Bundler cannot continue.
Make sure that `gem install sqlite3 -v '1.3.9'` succeeds before bundling.
则根据提示先解决checking for sqlite3.h... no
sqlite3.h is missing.问题,执行如下命令
yum install sqlite-devel -y
安装完后再次执行:
bundle install
则成功。

再次启动rails服务:
rails server
如果出现如下错误:
/home/zhangwei/.gem/ruby/gems/execjs-2.2.1/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
则表示没有安装js运行时库,需要安装Nodejs解决。
进入下载网站:http://www.nodejs.org/download/,下载Source Code  node-v0.10.32.tar.gz到本地。
解压,编译,安装:
tar -zxvf node-v0.10.32.tar.gz
./configure
make (编译时间比较久,去喝杯茶吧...)
sudo make install
安装完毕后,切回到blog工程目录,再次启动rails服务:
rails server
显示如下:
rails server
=> Booting WEBrick
=> Rails 3.2.0 application starting in development on http://0.0.0.0:3000 => Call with -d to detach
=> Ctrl-C to shutdown server
SECURITY WARNING: No secret option provided to Rack::Session::Cookie.
This poses a security threat. It is strongly recommended that you
provide a secret to prevent exploits that may be possible from crafted
cookies. This will not be supported in future versions of Rack, and
future versions will even invalidate your existing user cookies.

Called from: /usr/local/share/gems/gems/actionpack-3.2.0/lib/action_dispatch/middleware/session/abstract_store.rb:28:in `initialize'.
[2014-10-13 00:06:30] INFO  WEBrick 1.3.1
[2014-10-13 00:06:30] INFO  ruby 2.0.0 (2013-11-22) [x86_64-linux]
[2014-10-13 00:06:30] INFO  WEBrick::HTTPServer#start: pid=8149 port=3000
恭喜进入男生权利,赶紧进入我们得主页看下吧。
打开浏览器,输入:http://localhost:3000 如果看到了熟悉的rails主页,则说明rails环境搭建完成。
(未完待续...)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: