学习 Capistrano ,主要考虑用其做代码的自动化发布
参考:
https://github.com/capistrano/capistrano
https://github.com/capistrano/capistrano/wiki
http://huacnlee.com/blog/using-nginx-proxy-to-mirror-rubygem-org/
http://ruby.taobao.org/
http://www.mysqlops.com/2011/11/28/rake-code.html
DEPENDENCIES
Net::SSH
Net::SFTP
Net::SCP
Net::SSH::Gateway
HighLine
Ruby ≥ 1.8.7 ########### 注意这个
安装
wget ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz
tar xzvf ruby-2.0.0-p247.tar.gz
cd ruby-2.0.0-p247
./configure
make
make install
ruby -v
wget http://production.cf.rubygems.org/rubygems/rubygems-2.0.6.tgz
tar xzf rubygems-2.0.6.tgz
cd rubygems-2.0.6
/usr/local/bin/ruby setup.rb
gem -v
[root@test-102 ~]# gem env gem 环境变量
RubyGems Environment:
- RUBYGEMS VERSION: 2.0.6
- RUBY VERSION: 2.0.0 (2013-06-27 patchlevel 247) [x86_64-linux]
- INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/2.0.0
- RUBY EXECUTABLE: /usr/local/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /usr/local/lib/ruby/gems/2.0.0
- /root/.gem/ruby/2.0.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://ruby.taobao.org/"] ############# gem默认安装完成非这个源地址,因默认源被墙,很慢
- REMOTE SOURCES:
- http://ruby.taobao.org/ ############### gem默认安装完成非这个源地址,因默认源被强,很慢
gem sources --remove https://rubygems.org/
gem sources -a http://ruby.taobao.org/
没有修改 sources 安装 capistrano 报错
[root@test-102 rubygems-2.0.6]# gem install capistrano
ERROR: Could not find a valid gem 'capistrano' (>= 0), here is why:
Unable to download data from https://rubygems.org/ - Errno::ETIMEDOUT: Connection timed out - connect(2) (https://rubygems.org/latest_specs.4.8.gz)
安装 capistrano 前后 gem list 输出对比
[root@test-102 rubygems-2.0.6]# gem list
*** LOCAL GEMS ***
bigdecimal (1.2.0)
io-console (0.4.2)
json (1.7.7)
minitest (4.3.2)
psych (2.0.0)
rake (0.9.6)
rdoc (4.0.0)
test-unit (2.0.0.0)
gem install capistrano
[root@test-102 ~]# gem list
*** LOCAL GEMS ***
bigdecimal (1.2.0)
capistrano (2.15.5)
highline (1.6.19)
io-console (0.4.2)
json (1.7.7)
minitest (4.3.2)
net-scp (1.1.2)
net-sftp (2.1.2)
net-ssh (2.6.8)
net-ssh-gateway (1.2.0)
psych (2.0.0)
rake (0.9.6)
rdoc (4.0.0)
test-unit (2.0.0.0)
cap -h capistrano 能干的事情
cap -H capistrano 能干事情详细说明
没有注意ruby 版本要求,导致cap 环境检查报错,折腾了蛮久,搞烦了,就去看看知乎。回来谷歌再搞
/usr/lib/ruby/gems/1.8/gems/capistrano-2.15.5/lib/capistrano/configuration/actions/file_transfer.rb:39: warning: parenthesize argument(s) for future version
/usr/lib/ruby/gems/1.8/gems/capistrano-2.15.5/lib/capistrano/configuration.rb:48: undefined method `owner' for #<UnboundMethod: Capistrano::Configuration(Object)#taguri> (NoMethodError)
from /usr/lib/ruby/gems/1.8/gems/capistrano-2.15.5/lib/capistrano/configuration.rb:46:in `select'
from /usr/lib/ruby/gems/1.8/gems/capistrano-2.15.5/lib/capistrano/configuration.rb:46
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /usr/lib/ruby/gems/1.8/gems/capistrano-2.15.5/lib/capistrano.rb:3
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /usr/lib/ruby/gems/1.8/gems/capistrano-2.15.5/lib/capistrano/cli.rb:1
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /usr/lib/ruby/gems/1.8/gems/capistrano-2.15.5/bin/cap:3
from /usr/bin/cap:19:in `load'
from /usr/bin/cap:19
符合依赖版本后,环境检查,正常
[root@test-102 cap]# cap deploy:check
* 2013-08-15 15:15:48 executing `deploy:check'
* executing multiple commands in parallel
-> "else" :: "test -d /u/apps/set your application name here/releases"
-> "else" :: "test -d /u/apps/set your application name here/releases"
-> "else" :: "test -d /u/apps/set your application name here/releases"
-> "else" :: "test -d /u/apps/set your application name here/releases"
servers: ["your web-server here", "your app-server here", "your primary db-server here", "your slave db-server here"]
connection failed for: your app-server here (SocketError: getaddrinfo: Name or service not known), your web-server here (SocketError: getaddrinfo: Name or service not known), your primary db-server here (SocketError: getaddrinfo: Name or service not known), your slave db-server here (SocketError: getaddrinfo: Name or service not known)