Vlad the Deployer 配合 mod_rails 使用的文档

作者: wosmvp /wosmvp@gmail.com
日期: 2008/7/2
最初发表于:http://www.ruby-lang.org.cn


1. 测试环境:
1. Web服务器的URL: DreamHost提供
svn版本:1.4.2
2. SVN服务器的URL: Google Code提供
3. 测试机环境:
系统:Ubuntu-7.10-amd64
svn版本:1.4.4
Vlad the Deployer版本号: 自编译版 1.2.0.1 (2008/7/1日取源码)

2. 使用方法:
1) 安装Vlad the Deployer
下载 Vlad the Deployer 源码
git clone git://github.com/aussiegeek/vlad.git
打包代码为gem文件
gem build vlad.gemspec
安装 Vlad the Deployer
gem install vlad-1.2.0.1.gem -l

2) 添加mod_rails支持
在Rakefile中添加
require 'vlad'
Vlad.load :app => 'passenger'

3) 修改配置
配置文件为config/deploy.rb ,一个基本可以运行的deploy.rb修改
set :domain, "用户名@WEB服务器"
set :deploy_to, "在WEB服务器上的位置,如 /home/username/web "
set :repository, "SVN服务器"

本例中使用的deploy.rb:
set :svn_cmd, "svn --username 用户名 --password 密码"
set :domain, "***@www.***.com"
set :deploy_to, "程序位置"
set :repository, "Google svn地址"
4) 服务器端配置:



5) 包含的Rake任务:
rake vlad:cleanup # Clean up old releases.
rake vlad:debug # Show the vlad setup.
rake vlad:invoke # Invoke a single command on every remote server.
rake vlad:migrate # Run the migrate rake task for the the app.
rake vlad:rollback # Rolls back to a previous version and restarts.
rake vlad:setup # Setup your servers.
rake vlad:setup_app # Prepares application servers for deployment.
rake vlad:start # (Re)Start the web and app servers
rake vlad:start_app # Restart PassengerVlad.load :app => 'passenger'
rake vlad:start_web # (Re)Start the web servers
rake vlad:stop # Stop the web and app servers
rake vlad:stop_web # Stop the web servers
rake vlad:update # Updates your application server to the latest revision.

例如:
rake vlad:update vlad:migrate vlad:start_app
该命令代表的含义为更新后,再进行migrate ,然后重新启动WEB服务器


3. 其它注意事项:
1) 使用其它版本管理工具,例如git,需修改Rakefile
require 'vlad'
Vlad.load :scm => :git

2) SVN需要用户名,密码
在deploy.rb中设定Vlad the Deployer
set :svn_cmd, "svn --username 用户名 --password 密码"

3) 简化命令的使用
vlad采用的是Rake命令,可进行如下简化等:
rake vlad:update vlad:migrate vlad:start_app
修改为
task 'easyupdate'=> ['vlad:update', 'vlad:migrate','vlad:start_app']

然后可以通过
rake easyupdate
来执行
rake vlad:update vlad:migrate vlad:start_app
命令

4) 以下为所有可以设定的系统变量
== Core Variables

repository:: REQUIRED: Repository path: e.g. http://repo.example.com/svn
deploy_to:: REQUIRED: Deploy path on target machines. e.g. /var/www/app
domain:: REQUIRED: Used for the common case of a single target
server. e.g. example.com
current_path:: The full path on the remote host that will be symlinked
as 'current'. Defaults to "#{deploy_to}/current".
current_release:: The full path to the current release's actual location.
Defaults to "#{releases_path}/#{releases.last}".
deploy_timestamped:: Create timestamped release directories instead of using
revision numbers. Defaults to true.
deploy_via:: Which SCM command should be used when deploying the app.
Defaults to "export".
latest_release:: The most recent release, which may not yet have been
symlinked. Defaults to release_path.
migrate_args:: Set this to change the RAILS_ENV that 'rake db:migrate'
will run under. Defaults to "".
migrate_target:: Set this if you need to specify a particular migration
'VERSION' number. Defaults to "latest".
rails_env:: Specifies the RAILS_ENV environment variable that will
be used. Defaults to "production".
rake:: Set this if you need to specify an alternate path to
'rake'. Defaults to "rake".
release_name:: Name of the release directory, if deploy_timestamped is
true. Defaults to timestamp: "YYYYMMDDHHMMSS".
release_path:: Path to this release, which may not have been created
yet. Defaults to "#{releases_path}/#{release_name}".
releases:: An array of all existing releases, oldest first.
Defaults to latest release directory name.
releases_path:: Full path to the 'releases' directory on the remote host.
Defaults to "#{deploy_to}/releases".
revision:: Revision to use for release. Defaults to 'head'.
rsync_cmd:: Path to rsync command. Defaults to "rsync".
rsync_flags:: Flags for rsync. Defaults to ['-azP', '--delete'].
scm_path:: Path on the remote host that will be used as 'working
space' for SCM tasks. Defaults to "#{deploy_to}/scm".
shared_path:: Full path to remote 'shared' directory, symlinked into
your app by default. Defaults to "#{deploy_to}/shared".
ssh_cmd:: Path to ssh. Defaults to "ssh".
ssh_flags:: Flags for ssh. Defaults to "".
sudo_cmd:: Path to sudo command. Defaults to "sudo".
sudo_flags:: Flogs for sudo. Defaults to nil.
sudo_password:: Asks for password when referenced.
umask:: Sets your umask value. Defaults to "02".

== Apache Web Variables:

web_command:: Command to execute when controlling the web server.
Defaults to "apachectl".

== Mongrel App Variables:

mongrel_address:: Defaults to "127.0.0.1"
mongrel_clean:: Defaults to false
mongrel_command:: Defaults to 'mongrel_rails'
mongrel_conf:: Defaults to "#{shared_path}/mongrel_cluster.conf"
mongrel_config_script:: Defaults to nil
mongrel_environment:: Defaults to "production"
mongrel_group:: Defaults to nil
mongrel_log_file:: Defaults to nil
mongrel_pid_file:: Defaults to nil
mongrel_port:: Defaults to 8000
mongrel_prefix:: Defaults to nil
mongrel_servers:: Defaults to 2
mongrel_user:: Defaults to nil

== Perforce SCM Variables:

p4_cmd:: The perforce command to use. Defaults to "p4"
source:: A perforce SCM worker instance.

== Subversion SCM Variables:

source:: A subversion SCM worker instance.
svn_cmd:: The subversion command to use. Defaults to "svn"

== Git - The Distributed SCM

git_cmd:: The git command to use. Defaults to "git"
VLAD(Vector of Locally Aggregated Descriptors)是一种图像表示方法,常用于图像检索和计算机视觉任务中。它通过聚合局部特征描述符来生成图像的紧凑表示。 以下是一个简单的C++实现示例,展示了如何实现VLAD图像表示: ```cpp #include <iostream> #include <vector> #include <opencv2/opencv.hpp> // 聚类算法(这里使用K-means) cv::Mat kmeansClustering(const std::vector<cv::Mat>& descriptors, int numClusters) { cv::Mat allDescriptors; for (const cv::Mat& descriptor : descriptors) { allDescriptors.push_back(descriptor); } cv::Mat labels, centers; cv::TermCriteria criteria(cv::TermCriteria::EPS + cv::TermCriteria::MAX_ITER, 100, 0.01); cv::kmeans(allDescriptors, numClusters, labels, criteria, 1, cv::KMEANS_PP_CENTERS, centers); return centers; } // 计算VLAD图像表示 cv::Mat computeVLAD(const std::vector<cv::Mat>& descriptors, const cv::Mat& visualWords) { int descriptorSize = descriptors[0].cols; cv::Mat vlad(visualWords.rows, descriptorSize, CV_32F, cv::Scalar(0)); for (const cv::Mat& descriptor : descriptors) { // 找到每个描述符最近的视觉词 cv::Mat difference = visualWords - descriptor; cv::Mat distances; cv::reduce(difference.mul(difference), distances, 1, cv::REDUCE_SUM); cv::Point minLoc; cv::minMaxLoc(distances, nullptr, nullptr, &minLoc); // 计算每个视觉词的残差 cv::Mat residual = descriptor - visualWords.row(minLoc.y); // 更新VLAD表示 for (int i = 0; i < descriptorSize; i++) { vlad.at<float>(minLoc.y, i) += residual.at<float>(0, i); } } // 归一化VLAD表示 cv::normalize(vlad, vlad, 1.0, 0.0, cv::NORM_L2); return vlad; } int main() { // 假设有一组局部特征描述符(使用OpenCV的Mat表示) std::vector<cv::Mat> descriptors = { (cv::Mat_<float>(1, 128) << /* descriptor values */ ), (cv::Mat_<float>(1, 128) << /* descriptor values */ ), (cv::Mat_<float>(1, 128) << /* descriptor values */ ), // ... }; // 聚类算法,得到视觉词汇 int numClusters = 100; cv::Mat visualWords = kmeansClustering(descriptors, numClusters); // 计算VLAD图像表示 cv::Mat vlad = computeVLAD(descriptors, visualWords); // 输出VLAD表示结果 std::cout << "VLAD Representation:\n" << vlad << std::endl; return 0; } ``` 在这个示例中,`descriptors`是一组局部特征描述符,每个描述符用一个`cv::Mat`对象表示。首先,使用K-means聚类算法将所有描述符聚类成`numClusters`个视觉词汇,并得到`visualWords`矩阵。然后,根据每个描述符找到最近的视觉词,并计算每个视觉词的残差。将残差累加到VLAD表示中,并进行归一化处理。最后,输出VLAD图像表示结果。 请注意,这只是一个简单的VLAD图像表示的C++实现示例,供你参考。在实际应用中,你可能需要根据具体需求进行修改和扩展,例如使用更复杂的特征提取方法、改进聚类算法等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值