2015-03-03 133 views
2

請幫助配置capistrano進行部署。 我有SSH:Capistrano部署配置

  • 用戶:用戶
  • 主機:8.8.8.8:6554
  • 通:123

然後,我已經到位桶庫[email protected]:somerepo /代碼git的

我只需要將代碼從默認分支部署到[email protected]:8888:/ public_html/test /。在本地機器上我有ssh密鑰,允許我無需密碼連接。但卡皮斯特拉諾沒有連接。

有我的配​​置:

lock '3.3.5' 
set :application, 'App' 
set :scm, :git 
set :repo_url, '[email protected]:somerepo/code.git' 
set :scm_passphrase, "" 
set :scm_user, "[email protected]" 
set :user, 'User' 
set :deploy_to, '/public_html/test' 
set :app_dir, "/public_html/test" 
set :ssh_options, {:forward_agent => true} 
role :web, '8.8.8.8:6554' 

namespace :deploy do 
    after :restart, :clear_cache do 
    on roles(:web), in: :groups, limit: 3, wait: 10 do 
    end 
    end 
end 

錯誤:

connection closed by remote host ** Invoke deploy:failed (first_time) ** Execute deploy:failed

+1

請幫助別人。我今天需要部署這個。 – 2015-03-03 08:09:26

回答

1

步驟1:中的Gemfile

gem 'capistrano' 
gem 'capistrano-bundler' 
gem 'capistrano-rails' 

步驟2:

第3步:cap install ##就會生成設定文件的

第4步:Capfile並粘貼以下代碼##該文件將平行於Rails應用程序

require 'capistrano/setup' 
require 'capistrano/deploy' 
require 'capistrano/bundler' 
require 'capistrano/rails/assets' 
require 'capistrano/rails/migrations' 
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r } 

步驟5:配置/ deploy.rb,這將是通用於ENV

該文件將被共享/通用跨應用環境

set :application, 'your_app' ## keep in mind that your app dir name will be your_app 
    set :repo_url, '[email protected]:somerepo/code.git' 
    set :branch, 'master' 
    set :use_sudo, true 
    set :deploy_to, '/public_html/test' 
    set :linked_files, fetch(:linked_files, []).push('config/database.yml') 
    set :linked_dirs, fetch(:linked_dirs, []).push('bin', 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system') 
namespace :deploy do 

    after :restart, :clear_cache do 
    on roles(:web), in: :groups, limit: 3, wait: 10 do 
     # Here we can do anything such as: 
     # within release_path do 
     # execute :rake, 'cache:clear' 
     # end 
    end 
    end 

end 

第六步:我們創建ENV特定的文件,現在對於生產環境

config/deploy/production.rb ##這個文件將被生成cap install這個時候你以前沒有必要的命令

請注意除此以外的所有代碼

role :app, %w{8.8.8.8:6554} 
set :ssh_options, { 
       user: 'User' 
      } 

步驟6:現在做ssh to your serverssh [email protected]:6554 現在它會要求輸入密碼...give password

第7步:現在默認的程序將會/var/www/app,在這裏你需要相應地,但在你的情況下創建的文件夾,你set :deploy_to, '/public_html/test'#確保目錄名稱後跟/「正斜槓」這個錯誤我做了很多次

sudo mkdir -p /public_html 
sudo mkdir -p /public_html/test 
sudo chown User:User /public_html/test # `chown` will change the owner ship so that `User` user can `**Read/Write**` 
umask 0002 
mkdir /public_html/test/releases ## these are convention 
mkdir /public_html/test/shared ## these are convention 
sudo chown User:User public_html/test/releases 
sudo chown User:User public_html/test/shared 
mkdir .ssh 
chmod .ssh 007 
ssh-keygen -t rsa 
and follow the step ## this will generate ssh key 
cat .ssh/id_rsa.pub 

現在加上這關鍵看你的回購的進入=>設置=>部署鍵按鈕=>點擊那個和添加Key。把標籤命名爲任何你想要的東西,並粘貼ssh key在這裏。

那它服務器

第八步:現在,您需要將您的SSH密鑰添加到服務器 對於做cat ~/.ssh/id_rsa.pub如果你有rsa鍵其他明智的產生RSA密鑰是很容易到箱子

步驟9:登錄到服務器使用ssh

`vi .ssh/authorized_keys` and paste your local machine rsa key 

保存並退出

步驟10:cap -T ##列出所有任務

步驟11:cap production deploy:check

因爲database.yml文件,是不是會引發錯誤there

對於那vi /public_html/test/shared/config/database.yml

development: 
    adapter: postgresql 
    database: testdb_cap 
    pool: 5 
    timeout: 5000 

保存並退出

再做cap production deploy:check

這一次也不會引發任何錯誤

步驟12:

cap production deploy 

,這就是它

請檢查這個ruby rake task after deploymewnt

+0

這沒有用。 SSHKit ::命令::失敗:git退出狀態:127 – 2015-03-05 09:40:06

+0

@МаксимВладимирович:你的問題解決了嗎?因爲我有一些問題但無法解決:P – VKatz 2016-03-30 07:35:16

+0

不,這對我沒有幫助。 – 2016-04-01 08:40:45