Rails 应用程序无法在 AWS Elastic Beanstalk 上运行,sqlite3 错误
Posted
技术标签:
【中文标题】Rails 应用程序无法在 AWS Elastic Beanstalk 上运行,sqlite3 错误【英文标题】:Rails app doesn't run on AWS Elastic Beanstalk, sqlite3 error 【发布时间】:2014-08-04 02:16:13 【问题描述】:我一直试图开始在 AWS 的 Elastic Beanstalk 上运行 Rails,但遇到了一个看似无法克服的障碍:虽然我能够启动一个新的 Elastic Beanstalk 运行示例应用程序,但我似乎无法获得一个 EB 实例来成功运行我自己的代码。
以下是我采取的步骤:
-
在 OSX 10.9.3 上本地运行 ruby 1.9.3p545
已安装 aws-eb 客户端工具。
严格按照 Amazon 的以下教程进行操作:Deploying a Rails Application to AWS Elastic Beanstalk (tl;dnr: 使用 'rails new' 创建一个新的 rails 应用程序,提交到 git,然后使用 'eb init' 创建一个类型为 ' 的 EB 实例64 位 Amazon Linux 2014.03 v1.0.3 运行 Ruby 1.9.3' 然后运行 'eb start')
在等待创建 EB 实例的时间似乎很长之后,我导航到 Amazon 提供的 URL。
我没有看到我的 rails 应用程序(顺便说一句,它在本地运行良好),而是看到可怕的“我们很抱歉,但出了点问题”页面:
我已多次尝试这些步骤,结果相同。我尝试过使用不同的环境(例如 Ruby 2.0.0 Puma 和 Passenger 的环境,必要时通过 rvm 更新我的 ruby)。
在这被标记为重复之前,让我直接声明,我查看了以下问题并发现它们没有解决我的问题:
AWS Elastic Beanstalk: Launching a new Rails App
Deploying an existing Rails app to AWS Elastic Beanstalk
按照问题“AWS Elastic Beanstalk:启动新的 Rails 应用程序”中的建议,这似乎与我的问题非常相似,我让应用程序运行了一夜,但仍然出现错误。
我已经 ssh 进入了实例。有趣的是,production.log 和 development.log 似乎都是空的(无论如何都在 /var/app/support/logs 中)。但是,我在passenger.log 中找到以下内容:
*********截图*********
[ 2014-06-12 21:42:38.8400 5133/7fe66aee4700 代理/HelperAgent/RequestHandler.h:2210 ]:[客户端 20] 无法签出会话。
错误页面:
无法加载此类文件 -- sqlite3/sqlite3_native (LoadError)
/usr/local/share/gems1.9/gems/sqlite3-1.3.9/lib/sqlite3.rb:6:in require'
/usr/local/share/gems1.9/gems/sqlite3-1.3.9/lib/sqlite3.rb:6:in
rescue in '
/usr/local/share/gems1.9/gems/sqlite3-1.3.9/lib/sqlite3.rb:2:in <top (required)>'
/usr/local/share/gems1.9/gems/bundler-1.6.2/lib/bundler/runtime.rb:76:in
require'
/usr/local/share/gems1.9/gems/bundler-1.6.2/lib/bundler/runtime.rb:76:in block (2 levels) in require'
/usr/local/share/gems1.9/gems/bundler-1.6.2/lib/bundler/runtime.rb:72:in
each'
/usr/local/share/gems1.9/gems/bundler-1.6.2/lib/bundler/runtime.rb:72:in block in require'
/usr/local/share/gems1.9/gems/bundler-1.6.2/lib/bundler/runtime.rb:61:in
each'
/usr/local/share/gems1.9/gems/bundler-1.6.2/lib/bundler/runtime.rb:61:in require'
/usr/local/share/gems1.9/gems/bundler-1.6.2/lib/bundler.rb:132:in
require'
/var/app/current/config/application.rb:7:in <top (required)>'
/var/app/current/config/environment.rb:2:in
require'
/var/app/current/config/environment.rb:2:in <top (required)>'
config.ru:3:in
require'
config.ru:3:in block in <main>'
/usr/local/share/gems1.9/gems/rack-1.5.2/lib/rack/builder.rb:55:in
instance_eval'
/usr/local/share/gems1.9/gems/rack-1.5.2/lib/rack/builder.rb:55:in initialize'
config.ru:1:in
new'
config.ru:1:in <main>'
/usr/local/share/gems1.9/gems/passenger-4.0.41/helper-scripts/rack-preloader.rb:112:in
eval'
/usr/local/share/gems1.9/gems/passenger-4.0.41/helper-scripts/rack-preloader.rb:112:in preload_app'
/usr/local/share/gems1.9/gems/passenger-4.0.41/helper-scripts/rack-preloader.rb:158:in
'
/usr/local/share/gems1.9/gems/passenger-4.0.41/helper-scripts/rack-preloader.rb:29:in <module:PhusionPassenger>'
/usr/local/share/gems1.9/gems/passenger-4.0.41/helper-scripts/rack-preloader.rb:28:in
'
应用程序 5241 标准输出: 应用程序 5241 标准输出: [ 2014-06-12 21:45:26.2512 5133/7fe66d1ef700 Pool2/Implementation.cpp:883 ]:无法为组 /var/app/current#default 生成进程:启动 th$ 时发生错误 在'无效乘客::ApplicationPool2::SmartSpawner::handleErrorResponse(Passenger::ApplicationPool2::SmartSpawner::StartupDetails&)' (SmartSpawner.h:455) 在 'std::string Passenger::ApplicationPool2::SmartSpawner::negotiatePreloaderStartup(Passenger::ApplicationPool2::SmartSpawner::StartupDetails&)' (SmartSpawner.h:566) 在“无效乘客::ApplicationPool2::SmartSpawner::startPreloader()”(SmartSpawner.h:206) 在'虚拟乘客::ApplicationPool2::ProcessPtr Passenger::ApplicationPool2::SmartSpawner::spawn(const Passenger::ApplicationPool2::Options&)' (SmartSpawner.h:752) 在 'void Passenger::ApplicationPool2::Group::spawnThreadRealMain(const Passenger::ApplicationPool2::SpawnerPtr&, const Passenger::ApplicationPool2::Options&, unsigned in$
********结束片段********
不确定 sqlite3 是否是问题所在,但它似乎已安装在实例上。以防万一,我再次安装了 sqlite3 gem。
这是乘客状态的输出:
Version : 4.0.41
Date : 2014-06-13 13:25:52 +0000
Instance: 5148
----------- General information -----------
Max pool size : 6
Processes : 0
Requests in top-level queue : 0
----------- Application groups -----------
/var/app/current#default:
App root: /var/app/current
Requests in queue: 0
我不是专家,但似乎乘客没有运行(进程 == 0)。
我错过了什么?是否有一些我忽略设置为 true 的“JUST_WORK_DARNIT”配置?
如果 sqlite3 安装确实存在问题,如下所示,我可以做些什么来解决这个问题?
【问题讨论】:
【参考方案1】:是的,sqlite3 gem 是问题所在。它已安装,但未正确安装。缺少一个密钥文件(即 sqlite3_native 库文件)。
【讨论】:
关于正确安装 sqlite3 gem 的任何想法?我认为仅仅重新运行 gem install 是不够的,因为我已经尝试过了。 抱歉,我对 Elastic Beanstalk 不够熟悉,无法回答这个问题。【参考方案2】:您可以尝试通过运行yum install sqlite-devel
来安装 sqlite-devel 吗?
您可能想使用 ebextensions 在 beanstalk 上进行尝试。
在部署到 beanstalk 之前,尝试在您的应用源目录中创建一个路径为 .ebextensions/00-myfile.config
的文件。
packages:
yum:
sqlite-devel: []
听起来类似于这里讨论的问题Why can't I install the SQLite gem?
让我知道这是否有效。
更新
Rails 4 改变了一件事。您可能遇到了这个问题。 请参阅此处的讨论:https://github.com/rails/rails/pull/8468 由于上述更改,rails 4 生成的默认示例应用程序无法在生产模式下运行。但是,您可以通过修改示例应用程序以包含非默认网页来使其工作。
我尝试了以下方法: 运行“rails new appname”、“git init”、“eb init”后尝试以下步骤。 (基于this 的回答)。
-
编辑 config/routes.rb 使其包含
root :to => 'proto#index'
使用以下内容创建 app/controllers/proto_controller.rb
class ProtoController < ApplicationController
def index
end
end
创建文件 app/views/proto/index.html.erb 并在该文件中写入一些内容...“Hello World”。
然后启动您的环境。那应该行得通。 当我尝试不遵循上述三个步骤时,我也会得到一个错误页面。但是通过这些更改,我看不到错误页面。
我建议您在新环境的新目录中执行上述步骤。我使用最新的 Ruby 解决方案堆栈“64bit Amazon Linux 2014.03 v1.0.4 running Ruby 2.0 (Puma)”进行了测试。
此外,当您到达this 教程的第 6 步时,您可能最终将 gem 'sqlite3' 替换为 gem 'mysql2' ,但这是运行示例应用程序之后的下一步。
【讨论】:
我会在早上的第一件事上试一试...感谢您的提示!我假设配置文件条目是什么将在 beanstalk 启动新实例时使其工作? 按照您的建议进行操作并添加了配置文件。我在乘客日志中仍然遇到同样的错误。我登录到实例以验证是否已通过运行“yum install sqlite-devel”安装了 sqlite-devel,结果如下:“Package sqlite-devel-3.7.17-1.9.amzn1.x86_64 already installed and latest version”我感谢您对此的帮助...您还有其他建议吗? 您的应用在本地运行吗?另外,使用上面的 ebextension,您是否尝试过新环境。另一个猜测github.com/rails/rails/issues/11208 此外,rails 4 更改了一些内容,以使您不再在生产环境中看到示例应用程序页面github.com/rails/rails/pull/8468 如果您的应用程序在 localhost 上运行但在部署后无法运行,您可以尝试定义自定义 Rails 控制器。您还尝试了哪个 ruby puma 解决方案堆栈。你能给出确切的 namd,比如 64bit Amazon Linux ... 是的,该应用程序在本地运行。是的,我确实尝试了一个全新的环境和 Rails 应用程序。此外,刚刚尝试在 eb 实例上运行“rails server”并得到相同的 sqlite 错误。我为最近的测试所做的实例是列表中的第 27 位:“1.9.3 on 64bit Amazon Linux 2014.03 v1.0.3”。上周我在 Puma 上试用它时,它是“Amazon Linux 2014.03 v1.0.4 上的 2.0 (Puma)”。以上是关于Rails 应用程序无法在 AWS Elastic Beanstalk 上运行,sqlite3 错误的主要内容,如果未能解决你的问题,请参考以下文章