• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
导航菜单
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx
您的位置:首页 > 服务器 >windows > 自动化代码部署、代码回滚、命令执行软件之capistrano

自动化代码部署、代码回滚、命令执行软件之capistrano

作者:网友 字体:[增加 减小] 来源:互联网

本文主要包含san juan capistrano,capistrano,capistrano beach,我的世界命令方块代码,命令方块代码等服务器相关知识,网友希望可以进行参考

Hi,本周第一天没什么事,所以就先分享一下我研究自动化代码部署与回滚软件的经验。这个软件有什么用途?主要是解决自动进行代码的部署,避免手动部署时出现错误,节省时间,同时在出现问题的时候,能回滚到之前的版本或者你指定的版本),我在gitlab里找到了这样的软件,名为capistrano。下面就先给大家介绍一下。

文章结构

一、介绍

二、要求的环境

三、安装

四、命令行测试

五、代码部署结合git)

六、代码部署结合svn)

七、代码回滚

八、总结

九、namespace

一、介绍

Capistrano是一种在多台服务器上运行脚本的开源工具,它主要用于部署web应用。它自动完成多台服务器上新版本的同步更新,包括数据库的改变。Capistrano最初由Jamis Buck用Ruby开发,并用RubyGems部署渠道部署。现在Capistrano不仅限于应用Ruby on Rails的 web应用框架,而且可以用于部署用其他框架的web应用程序,比如用PHP开发的。Capistran最初是用来应用于bash指令行。现在Ruby on Rails框架的用于也可以使用它的新特性,例如,对当前web应用部署改变使其更新版本,或者使其回滚到之前的旧版本。

二、要求的环境

1、Ruby一定要1.9.x;

2、server端与client端一定要进行ssh信任或者client端统一一个相同的密码;

三、安装

gem install capistrano

四、命令行测试

root@ubuntu:/tmp# cat capfile
task :du, :hosts => "ubuntu.hadoop.com" do
run "df -h"
end

在ubuntu.hadoop.com本机)机器上运行df –h命令查看磁盘空间

root@ubuntu:/tmp# cap du
* 2013-06-25 13:34:48 executing `du'
* executing "df -h"
servers: ["ubuntu.hadoop.com"]
[ubuntu.hadoop.com] executing command
** [out :: ubuntu.hadoop.com] Filesystem               Size  Used Avail Use% Mounted on
** [out :: ubuntu.hadoop.com] /dev/mapper/ubuntu-root   39G  3.3G   33G  10% /
** [out :: ubuntu.hadoop.com] udev                     489M  4.0K  489M   1% /dev
** [out :: ubuntu.hadoop.com] tmpfs                    199M  336K  199M   1% /run
** [out :: ubuntu.hadoop.com] none                     5.0M     0  5.0M   0% /run/lock
** [out :: ubuntu.hadoop.com] none                     498M     0  498M   0% /run/shm
** [out :: ubuntu.hadoop.com] /dev/sda1                228M   51M  166M  24% /boot
command finished in 981ms

可以看到类似使用python的fabric,但capistrano比fabric多了一个代码回滚功能。

需要注意的是如果你的client机器的ssh端口不是默认22的话,你还想操作的话,需要添加

ssh_options[:port] = 50020#ssh port

如果不添加的话,就会出现connection failed for: ip (Errno::ECONNREFUSED: Connection refused - connect(2))

如果你在使用iptables的机器上使用capistrano,只需要开启ssh端口就可以正常的使用capistrano。

五、代码部署结合git)

测试环境

主机名                 ip          状态      ruby
ubuntu.hadoop.com   192.168.56.102  server      1.9.3
server.hadoo.com        192.168.56.101  client      1.9.3

1、进入tmp目录,然后创建capi目录

cd /tmp
mkdir capi
cd capi

2、capistrano部署我的应用

capify .

这将产生两个文件,一个是capfile,这个是Capistrano需要的主要文件,就像make自动产生makefile,rake自动产生Rakefile一样,Capistrano默认寻找并加载capfile文件,默认产生的rapfile非常小,它所做的事就是加载“config/deploy.rb";第二个文件是"config/deploy.rb",这个文件包含你的应用程序部署所需的设置。Ralis的所有设置文档都放在config目录下,通常,你不需要管capfile文件,只需要把精力放在config/deploy.rb的设置和优化上。如果你的Capistrano用于非Rails环境,你可能只有一个capfile文件,而没有config/deploy.rb这个文件。

3、修改config/deploy.rb文件

set :application, "test"
set :scm, :git
set :repository,  "ssh://git@192.168.1.250/data/gitrepo/jsonLib.git"
set :deploy_to, "/tmp/result"
set :normalize_asset_timestamps, false
# set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent guess based on known version control directory names
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
role :web, "192.168.56.101"                          # Your HTTP server, Apache/etc
role :app, "192.168.56.101"                          # This may be the same as your `Web` server
role :db,  "192.168.56.101", :primary => true # This is where Rails migrations will run
#role :db,  "your slave db-server here"

我的修改内容如上

主要是从192.168.1.250里获取git库,然后应用部署到192.168.56.102机器的/tmp/result目录。

set :application, "test"

是告诉Capistrano我们的应用程序被"调用"了

set :scm, :git

默认启动svn,而不是git,如果使用的话,需要set :scm, :git开启。

set :repository,  "ssh://git@192.168.1.250/data/gitrepo/jsonLib.git"

然后我们需要告诉Capistrano我们的源代码在哪里,这个地址你的本地主机和服务器都可以到达。

set :deploy_to, "/tmp/result"

我们需要告诉Capistran我们的应用放在服务器的哪里,如果不加的话,默认为"/u/apps/#{application}"。

set :normalize_asset_timestamps, false

如果不添加这句话,在deploy:update的时候会出现

*** [err :: 192.168.56.101] find: `/tmp/result_svn/releases/20130625071724/public/images'
*** [err :: 192.168.56.101] : No such file or directory
*** [err :: 192.168.56.101] find: `/tmp/result_svn/releases/20130625071724/public/stylesheets': No such file or directory
*** [err :: 192.168.56.101] find: `/tmp/result_svn/releases/20130625071724/public/javascripts': No such file or directory

原因是

Capistrano default behavior is to 'touch' all assets files. (To make sure that any cache get the deployment date). Assets are images, stylesheets, etc.
If your PHP application is not using these directories, capistrano complains in such an ugly way.
To disable asset timestamps updates, simply add:

app,web,db是Capistrano需要的三种角色:

web:你的服务器软件运行的地方;

app:你的应用层运行的地方;

db:迁移运行的地方;

4、部署目录结构

cap deploy:setup

会在192.168.56.101创建/tmp/result目录,然后在这个目录里创建releases与shared目录

root@ubuntu:/tmp/capi# cap deploy:setup
* 2013-06-25 15:26:47 executing `deploy:setup'
* executing "sudo -p 'sudo password: ' mkdir -p /tmp/result /tmp/result/releases /tmp/result/shared /tmp/result/shared/system /tmp/result/shared/log /tmp/result/shared/pids"
servers: ["192.168.56.101"]
[192.168.56.101] executing command
command finished in 781ms
* executing "sudo -p 'sudo password: ' chmod g+w /tmp/result /tmp/result/releases /tmp/result/shared /tmp/result/shared/system /tmp/result/shared/log /tmp/result/shared/pids"
servers: ["192.168.56.101"]
[192.168.56.101] executing command
command finished in 40ms

5、检查

root@ubuntu:/tmp/capi# cap deploy:check
* 2013-06-25 15:29:04 executing `deploy:check'
* executing "test -d /tmp/result/releases"
servers: ["192.168.56.101"]
[192.168.56.101] executing command
command finished in 819ms
* executing "test -w /tmp/result"
servers: ["192.168.56.101"]
[192.168.56.101] executing command
command finished in 25ms
* executing "test -w /tmp/result/releases"
servers: ["192.168.56.101"]
[192.168.56.101] executing command
command finished in 26ms
* executing "which git"
servers: ["192.168.56.101"]
[192.168.56.101] executing command
command finished in 26ms
You appear to have all necessary dependencies
  


 
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • 自动化代码部署、代码回滚、命令执行软件之capistrano

相关文章

  • 如何将文件所有者改为TrustedInstaller
  • 【微软的VDI】Windows Server 2012 RDS存储相关
  • 三、安装Nginx 0.8.46【LNMP安装 】
  • oracle数据库使用nfs存储,启动报错提示无法锁定文件
  • Windows 组策略无法启动的解决方法
  • cwRsync实现windows服务器间的同步备份
  • Windows server 2003 创建域如何操作?
  • 构建高科可用性Heartbeat
  • IIS PUT写权限利用演示
  • SoluVM ISO安装Windows 2003图文详解

文章分类

  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx

最近更新的内容

    • IIS环境启用GZip压缩方法图文详解
    • IIS中配置phpmyadmin图文教程
    • Server Application Error 的解决方案
    • windows 2003 关闭“关闭事件跟踪程序”图解
    • 即时通讯开发平台AnyChat 的性能优势
    • .Net IIS分析器错误信息: 无法识别的属性“type”问题
    • IIS启用GZip失败之原因:临时目录权限没设好
    • liunx服务使用(nfs服务和ftp服务还有samba服务)
    • 远程桌面连接服务器和修改远程端口图解
    • Windows2003 如何查看端口是否已打开及端口占用情况

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有