ITeye博客

Capistrano deploy.rb文件的记录

xu_wccq · 2008-11-18 19:57 · ruby · Markdown


#  在redhat 内核中不需要sudo 方式运行。
set :use_sudo, false # Do not use sudo ro run command.

set :domain, 'www.firebirds.com' 
set :application, 'ruby_on_rails'
set :user, 'root' # connect to server use this variable. # 连接app服务器,并执行命令

set :repository, "svn://172.10.12.8/www/ror/trunk"

set :port, 8888 # connect server use ssh with this port#  ssh连接app服务器的端口号.

set :deploy_to, "/var/www/ror" # deploy to server location


# set :scm, :subversion
set :scm_username, 'xxx'

set :scm_password, proc{Capistrano::CLI.password_prompt('SVN pass:')} # 在出现SVN pass: 时输入svn密码. # 在第一次用过后,svn shell会记住此密码,下次可不用。

# control mongrel_cluster
#require 'mongrel_cluster/recipes'
#set :mongrel_conf, "/etc/mongrel_cluster/spare.yml"

role :app, "172.10.12.8"
role :web, "172.10.12.8"
role :db,  "172.10.12.8", :primary => true
 
# app, web, db 都 在同一台机器上如下即可
#server "172.10.12.8", :app, :web, :db, :primary => true

set :deploy_via, :export   # 在服务器上连接到源码库里去更新
# set :deploy_via, :copy  # 在本地打包上传至服务器

set :runner, user   # excute command with the front of user defined.


# Does not look like you are using the fastcgi processes that reaper is
# designed to restart in the setup you described.  In your cap script set
# them to false.  EG  set :spinner, "false".  See the manual for details.
set :spinner, "false"   # 使用fascgi 的话,把此行注释

#after 'deploy', 'deploy:cleanup'  # hock after deploy
#after 'deploy:migrations', 'deploy:cleanup'  # hock after deploy:migrations



在用capistrano 进行部署的时候,会希望专用一个web app来管理 这些部署 应用程序如:ccrb
那么ssh 也需要自动登陆出服务器上,如下:但这样不够安全,最好的是不定期的生成ssh密钥;
如:
客户机要想自动登陆到服务器192.168.188.199 上.
 1 . 在客户机上制作密钥
 2. 把密钥拷至服务器上,追加到.ssh/authorized_keys 文件中.

以下操作在 客户机 上进行


[root@ ~]# ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa): 
Enter passphrase (empty for no passphrase):   # 回车
Enter same passphrase again:  # 回车
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
ad:85:bddb5:ddr:a544c:fc:ef:57:dd:4b:ef:a9:8a:db root@~

[root@ ~]# cd /root/.ssh/id_dsa
id_dsa      id_dsa.pub  
[root@ ~]# scp -P 65534 /root/.ssh/id_dsa.pub root@192.168.188.199:/root/.ssh/ 


在远程服务器上 完成


cd .ssh
umask 077
cat ./id_rsa.pub >> authorized_keys


回到客户机上用 ssh 192.168.188.199 -p65534 此时不用输密码即可登陆到服务器上.

http://snippets.dzone.com/tags/rails

评论(1)

  1. #1 楼 · xu_wccq · 2008-11-20 21:39
    
    # This defines a deployment "recipe" that you can feed to capistrano
    # (http://manuals.rubyonrails.com/read/book/17). It allows you to automate
    # (among other things) the deployment of your application.
    
    # =============================================================================
    # REQUIRED VARIABLES
    # =============================================================================
    # You must always specify the application and repository for every recipe. The
    # repository must be the URL of the repository you want this recipe to
    # correspond to. The deploy_to path must be the path on each machine that will
    # form the root of the application path.
    
    set :application, "CruiseControl.rb"
    set :repository, "svn://rubyforge.org/var/svn/cruisecontrolrb/trunk"
    
    # =============================================================================
    # ROLES
    # =============================================================================
    # You can define any number of roles, each of which contains any number of
    # machines. Roles might include such things as :web, or :app, or :db, defining
    # what the purpose of each machine is. You can also specify options that can
    # be used to single out a specific subset of boxes in a particular role, like
    # :primary => true.
    
    role :web, "localhost"
    #role :app, "app01.example.com", "app02.example.com", "app03.example.com"
    #role :db,  "db01.example.com", :primary => true
    #role :db,  "db02.example.com", "db03.example.com"
    
    # =============================================================================
    # OPTIONAL VARIABLES
    # =============================================================================
    # set :deploy_to, "/path/to/deployment" # defaults to "/u/apps/#{application}"
    # set :user, "flippy"            # defaults to the currently logged in user
    # set :scm, :darcs               # defaults to :subversion
    # set :svn, "/path/to/svn"       # defaults to searching the PATH
    # set :darcs, "/path/to/darcs"   # defaults to searching the PATH
    # set :cvs, "/path/to/cvs"       # defaults to searching the PATH
    # set :gateway, "gate.host.com"  # default to no gateway
    
    # =============================================================================
    # SSH OPTIONS
    # =============================================================================
    # ssh_options[:keys] = %w(/path/to/my/key /path/to/another/key)
    # ssh_options[:port] = 25
    
    # =============================================================================
    # TASKS
    # =============================================================================
    # Define tasks that run on all (or only some) of the machines. You can specify
    # a role (or set of roles) that each task should be executed on. You can also
    # narrow the set of servers to a subset of a role by specifying options, which
    # must match the options given for the servers to select (like :primary => true)
    
    # Tasks may take advantage of several different helper methods to interact
    # with the remote server(s). These are:
    #
    # * run(command, options={}, &block): execute the given command on all servers
    #   associated with the current task, in parallel. The block, if given, should
    #   accept three parameters: the communication channel, a symbol identifying the
    #   type of stream (:err or :out), and the data. The block is invoked for all
    #   output from the command, allowing you to inspect output and act
    #   accordingly.
    # * sudo(command, options={}, &block): same as run, but it executes the command
    #   via sudo.
    # * delete(path, options={}): deletes the given file or directory from all
    #   associated servers. If :recursive => true is given in the options, the
    #   delete uses "rm -rf" instead of "rm -f".
    # * put(buffer, path, options={}): creates or overwrites a file at "path" on
    #   all associated servers, populating it with the contents of "buffer". You
    #   can specify :mode as an integer value, which will be used to set the mode
    #   on the file.
    # * render(template, options={}) or render(options={}): renders the given
    #   template and returns a string. Alternatively, if the :template key is given,
    #   it will be treated as the contents of the template to render. Any other keys
    #   are treated as local variables, which are made available to the (ERb)
    #   template.
    
    
    
    

评论功能维护中,当前仅展示历史评论。