一. 安裝 capistrano
# 1 . yum install gem
# 2 . gem install capistrano 當前執行步驟如果報錯執行 執行3-8步驟
gem install 安裝很慢的情況下執行切換映象 gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
# 3. gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
# 4. curl -sSL https://get.rvm.io | bash -s stable 第一個不行 用第二個 curl -L get.rvm.io | bash -s stable
# 5. source /usr/local/rvm/scripts/rvm
# 6. rvm list know
# 7. rvm install 2.4.4
# 8. gem install capistrano
二. 使用
1.建立一個資料夾承載 capistrano 執行命令 cap install/cap init 初始化 capistrano
2. 編輯Capfile
require "capistrano/scm/svn"
install_plugin Capistrano::SCM::Svn
# 註釋掉GIT方式(預設是git方式)
# #require "capistrano/scm/git"
# #install_plugin Capistrano::SCM::Git**
3. 進入config目錄,編輯deploy.rb檔案
> lock "~> 3.11.2"
> set :application, "project_name"
> #手動輸入設定分支
> ask(:branch, "staging")
> #獲取分支
> set :repo_url, "svn://xx.xx.xxx.xxx:22223/smallapp/#{fetch(:branch)}/"
> #設定儲存版本
> set :keep_releases, 5
> set :pty, true
> #svn賬號
> set :svn_username, 'svn_username'
> #svn密碼
> set :svn_password, 'svn_password'
> set :current_directory,'current'
> #伺服器公共配置 日誌 靜態資源 配置檔案存放目錄 檔案內容需要先上傳
> set :shared_directory,'shared'
> #部署到伺服器指定目錄
> set :deploy_to, "/home/project_name"
> task :create_link do
> on roles(:web) do
> execute :rm, "-rf", "#{release_path}/trunk/www/logs"
> execute :rm, "-rf", "#{release_path}/trunk/www/site.config.php"
> execute :rm, "-rf", "#{release_path}/trunk/www/project_config/module_config/account.config.php"
> execute :ln, "-s", "#{shared_path}/www/logs #{release_path}/trunk/www/logs"
> execute :ln, "-s", "#{shared_path}/www/site.config.php #{release_path}/trunk/www/site.config.php #{release_path}/trunk/www/system_service.config.php"
> execute :ln, "-s", "#{shared_path}/www/project_config/module_config/account.config.php #{release_path}/trunk/www/project_config/module_config/account.config.php"
> end
> end
> #部署完畢建立軟連結到 shared 目錄下對應的配置檔案
> after "deploy:published", "create_link"
> role :web, 'deploy@伺服器地址',password: 伺服器密碼
**store-plaintext-passwords = yes**
釋出成功之後應該是這樣的
有關capistrano的更多說明請檢視官方文件 https://capistranorb.com/
本作品採用《CC 協議》,轉載必須註明作者和本文連結