在 Centos 7 和 Capistrano 上部署 RoR 似乎无法在任何地方启动服务器
Deploying RoR on Centos 7 and Capistrano doesn't seem to start the server anywhere
背景资料:
CentOS 7、Ruby 2.2.3、Rails 4.2.4、Capistrano 3.5.0 - 我只是一个 Rails 开发人员,而不是系统管理员,所以服务器的东西太多了在我的头上,我理解它只是偶尔过得去......
与我合作的系统管理员决定使用本教程在新的 Centos 7 VM 上设置 rails:https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-centos-7
然后我将他指向本教程的中间部分,以便设置我可以在 capistrano 中使用的部署用户:https://www.digitalocean.com/community/tutorials/how-to-automate-ruby-on-rails-application-deployments-using-capistrano
然后我使用 capistrano 尝试将 Rails 应用代码上的 Ruby 推送到 VM。
好像在他设置centos的时候(不知道是他还是提供虚拟机的服务),IP地址80端口已经显示了一些非rails的内容。因此,我猜最好的办法是尝试部署到端口 3000 并让系统管理员将其转发到端口 80?无论如何,我不知道如何让 capistrano 以特定绑定开始 rails。当我 运行 cap production deploy
它成功无误,但我不知道在浏览器中 running/how 访问它的位置。如果我通过 SSH 进入虚拟机,cd /home/deployer/rails/railsapp/current
然后 运行 rails s --binding=0.0.0.0 --environment=production
我可以通过 http://the-public-ip:3000 访问该站点。显然,这仅适用于在我启动命令行并 运行ning 时测试代码是否正常工作,但不适合实际部署。
所以我的问题是:如何让 capistrano 在生产模式下将我的 rails 应用程序部署到端口 3000?或者我应该告诉系统管理员做一些让 capistrano 以开箱即用的方式启动 rails 的事情(而不必在 capistrano 任务中做任何特殊的事情或专门绑定到 0.0.0.0 端口 3000 ).
这是我的 deploy.rb
lock '3.5.0'
set :application, 'xxxxxxx'
set :repo_url, 'https://xxxxxxx:xxxxxxx@bitbucket.org/xxxxxxx/xxxxxxx.git'
set :deploy_to, '/home/deployer/rails/railsapp/'
set :scm, :git
set :branch, "staging-deploy"
set :use_sudo, false
set :rails_env, "production"
set :deploy_via, :copy
set :ssh_options, {:forward_agent => true}
set :rails_env, "production"
set :keep_releases, 5
ipaddresses = [
'xx.xx.xxx.xxx'
]
role :web, ipaddresses
role :app, ipaddresses
set :log_level, :info
set :pty, true
namespace :deploy do
after :publishing, :restart
end
这里是 deploy/production.rb:
ipaddresses = [
'xx.xx.xxx.xxx'
]
ipaddresses.each do |ip|
server ip,
user: 'deployer',
roles: %w{web app},
ssh_options: {
forward_agent: false,
auth_methods: %w(password),
password: 'thepasswordhere',
user: 'deployer'
}
end
其他花絮:我所做的一切 deployment/SSH 和通过浏览器访问站点都是在通过 Cisco AnyConnect 通过 VPN 连接时完成的。不确定这会如何影响事情。
在我的deploy.rb中,我天真地尝试了这个,当然没有成功:
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:all), in: :sequence, wait: 5 do
execute "rails s --binding=0.0.0.0 --environment=production"
end
end
after :publishing, :restart
end
我认为存在误会。 capistrano 将为您做的基本上是将您的 Rails 应用程序复制到服务器上的目录中。
您仍然需要一个 Web 服务器 运行 来管理您的应用程序。理论上,您可以通过 ssh 连接到您的服务器和 运行 rails s --binding=0.0.0.0 --environment=production
(如您所写),但这将使用 Ruby 的内置 webrick 服务器,该服务器仅用于开发(不适合由于各种原因 运行 在生产中)。
在生产环境中托管您的应用有多种选择,例如Nginx 或 Apache 连同 Passenger.
背景资料: CentOS 7、Ruby 2.2.3、Rails 4.2.4、Capistrano 3.5.0 - 我只是一个 Rails 开发人员,而不是系统管理员,所以服务器的东西太多了在我的头上,我理解它只是偶尔过得去......
与我合作的系统管理员决定使用本教程在新的 Centos 7 VM 上设置 rails:https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-centos-7
然后我将他指向本教程的中间部分,以便设置我可以在 capistrano 中使用的部署用户:https://www.digitalocean.com/community/tutorials/how-to-automate-ruby-on-rails-application-deployments-using-capistrano
然后我使用 capistrano 尝试将 Rails 应用代码上的 Ruby 推送到 VM。
好像在他设置centos的时候(不知道是他还是提供虚拟机的服务),IP地址80端口已经显示了一些非rails的内容。因此,我猜最好的办法是尝试部署到端口 3000 并让系统管理员将其转发到端口 80?无论如何,我不知道如何让 capistrano 以特定绑定开始 rails。当我 运行 cap production deploy
它成功无误,但我不知道在浏览器中 running/how 访问它的位置。如果我通过 SSH 进入虚拟机,cd /home/deployer/rails/railsapp/current
然后 运行 rails s --binding=0.0.0.0 --environment=production
我可以通过 http://the-public-ip:3000 访问该站点。显然,这仅适用于在我启动命令行并 运行ning 时测试代码是否正常工作,但不适合实际部署。
所以我的问题是:如何让 capistrano 在生产模式下将我的 rails 应用程序部署到端口 3000?或者我应该告诉系统管理员做一些让 capistrano 以开箱即用的方式启动 rails 的事情(而不必在 capistrano 任务中做任何特殊的事情或专门绑定到 0.0.0.0 端口 3000 ).
这是我的 deploy.rb
lock '3.5.0'
set :application, 'xxxxxxx'
set :repo_url, 'https://xxxxxxx:xxxxxxx@bitbucket.org/xxxxxxx/xxxxxxx.git'
set :deploy_to, '/home/deployer/rails/railsapp/'
set :scm, :git
set :branch, "staging-deploy"
set :use_sudo, false
set :rails_env, "production"
set :deploy_via, :copy
set :ssh_options, {:forward_agent => true}
set :rails_env, "production"
set :keep_releases, 5
ipaddresses = [
'xx.xx.xxx.xxx'
]
role :web, ipaddresses
role :app, ipaddresses
set :log_level, :info
set :pty, true
namespace :deploy do
after :publishing, :restart
end
这里是 deploy/production.rb:
ipaddresses = [
'xx.xx.xxx.xxx'
]
ipaddresses.each do |ip|
server ip,
user: 'deployer',
roles: %w{web app},
ssh_options: {
forward_agent: false,
auth_methods: %w(password),
password: 'thepasswordhere',
user: 'deployer'
}
end
其他花絮:我所做的一切 deployment/SSH 和通过浏览器访问站点都是在通过 Cisco AnyConnect 通过 VPN 连接时完成的。不确定这会如何影响事情。
在我的deploy.rb中,我天真地尝试了这个,当然没有成功:
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:all), in: :sequence, wait: 5 do
execute "rails s --binding=0.0.0.0 --environment=production"
end
end
after :publishing, :restart
end
我认为存在误会。 capistrano 将为您做的基本上是将您的 Rails 应用程序复制到服务器上的目录中。
您仍然需要一个 Web 服务器 运行 来管理您的应用程序。理论上,您可以通过 ssh 连接到您的服务器和 运行 rails s --binding=0.0.0.0 --environment=production
(如您所写),但这将使用 Ruby 的内置 webrick 服务器,该服务器仅用于开发(不适合由于各种原因 运行 在生产中)。
在生产环境中托管您的应用有多种选择,例如Nginx 或 Apache 连同 Passenger.