配置Apache+SVN以及SVN同步WEB
2012-03-06 22:09
344 查看
转载出处: http://snowolf.iteye.com/blog/740347 http://www.cnblogs.com/php5/archive/2011/08/25/2153727.html http://blog.chinaunix.net/space.php?uid=24727220&do=blog&id=3033004
选用Ubuntu Server 10.04,Apache 2.2.14,Subversion 1.6.6。
步骤:
安装SVN相关模块
配置SVN版本库
配置APACHE
简单测试
1.安装SVN相关模块
这里主要用到的是Subversion 以及Apache与SVN相关的模块(DAV_SVN)!
执行命令,安装:
Shell代码
sudo apt-get install subversion libapache2-svn
注意观察安装后的结果:
引用
Considering dependency dav for dav_svn:
Enabling module dav.
Enabling module dav_svn.
Run '/etc/init.d/apache2 restart' to activate new configuration!
如果看到这样的提示,那说明DAV_SVN模块已经成功安装,可以重启Apache看看是否正常启动:
Shell代码
sudo /etc/init.d/apache2 restart
或者,使用
Shell代码
sudo service apache2 restart
以我本机为例,正常启动了:
引用
zlex@localhost:~$ sudo /etc/init.d/apache2 restart
* Restarting web server apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
... waiting .apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
当然,稍后你可能需要修改/etc/apache2/mods-available/dav_svn.conf文件,配置SVN版本库等。
2.配置SVN版本库
完成上述操作,只是为Apache获知SVN给出了一种途径,最关键的还是要配置SVN相关部分!
首先,我们要创建subversion组并把www-data作为subversion中的一员。因为,apache是通过www-data账户启动的,我们需要让它能够访问subversion组的文件!
Shell代码
sudo addgroup subversion
sudo usermod -G subversion -a www-data
然后,我们要配置版本库:
我们可以在/var/lib目录下构建一个svn目录,作为SVN版本库根目录:
Shell代码
cd /var/lib
sudo mkdir svn
假设我们要创建版本库zlex:
Shell代码
cd svn
sudo svnadmin create zlex
更改版本库所属用户、组:
Shell代码
sudo chown -R root:subversion zlex
赋予组成员对所有新加入文件仓库的文件拥有相应的权限:
Shell代码
sudo chmod -R g+rws zlex
试试
Shell代码
svn co file://localhost/var/lib/svn/zlex
,这时候应该可以访问了!
3.配置Apache
接下来,我们需要修改/etc/apache2/mods-available/dav_svn.conf文件,配置SVN版本库:
Shell代码
sudo vi /etc/apache2/mods-available/dav_svn.conf
打开红框中的注释,
Conf代码
# dav_svn.conf - Example Subversion/Apache configuration
#
# For details and further options see the Apache user manual and
# the Subversion book.
#
# NOTE: for a setup with multiple vhosts, you will want to do this
# configuration in /etc/apache2/sites-available/*, not here.
# <Location URL> ... </Location>
# URL controls how the repository appears to the outside world.
# In this example clients access the repository as http://hostname/svn/ # Note, a literal /svn should NOT exist in your document root.
<Location /svn>
# Uncomment this to enable the repository
DAV svn
# Set this to the path to your repository
#SVNPath /var/lib/svn
# Alternatively, use SVNParentPath if you have multiple repositories under
# under a single directory (/var/lib/svn/repo1, /var/lib/svn/repo2, ...).
# You need either SVNPath and SVNParentPath, but not both.
SVNParentPath /var/lib/svn
# Access control is done at 3 levels: (1) Apache authentication, via
# any of several methods. A "Basic Auth" section is commented out
# below. (2) Apache <Limit> and <LimitExcept>, also commented out
# below. (3) mod_authz_svn is a svn-specific authorization module
# which offers fine-grained read/write access control for paths
# within a repository. (The first two layers are coarse-grained; you
# can only enable/disable access to an entire repository.) Note that
# mod_authz_svn is noticeably slower than the other two layers, so if
# you don't need the fine-grained control, don't configure it.
# Basic Authentication is repository-wide. It is not secure unless
# you are using https. See the 'htpasswd' command to create and
# manage the password file - and the documentation for the
# 'auth_basic' and 'authn_file' modules, which you will need for this
# (enable them with 'a2enmod').
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd
# To enable authorization via mod_authz_svn
AuthzSVNAccessFile /etc/apache2/dav_svn.authz
# The following three lines allow anonymous read, but make
# committers authenticate themselves. It requires the 'authz_user'
# module (enable it with 'a2enmod').
#<LimitExcept GET PROPFIND OPTIONS REPORT>
Require valid-user
#</LimitExcept>
</Location>
分述:
<Location /svn>与</Location>成对儿出现!
DAV svn开启DAV模块支持!
SVNPath /var/lib/svn与SVNParentPath /var/lib/svn选其一,不可同时出现!建议使用SVNParentPath,可以在SVN根目录下创建多个SVN版本库!
引用
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd
定义了授权类型、并指定了密码文件(/etc/apache2/dav_svn.passwd)。
AuthzSVNAccessFile /etc/apache2/dav_svn.authz授权配置文件,规定了路径访问权限!
引用
#<LimitExcept GET PROPFIND OPTIONS REPORT>
Require valid-user
#</LimitExcept>
建议只使用Require valid-user,打开<LimitExcept/>注释,将允许匿名访问!
现在通过命令设置SVN账户:
Shell代码
sudo htpasswd -c /etc/apache2/dav_svn.passwd <username>
这里用到参数-c,是因为/etc/apache2/dav_svn.passwd文件不存在,如果文件存在,则无需该参数!否则,将覆盖掉原有密码文件!
形如:
引用
sudo htpasswd -c /etc/apache2/dav_svn.passwd snowolf
New password:
Re-type new password:
Updating password for user snowolf
可以追加多个账户!
引用
sudo htpasswd /etc/apache2/dav_svn.passwd zlex
New password:
Re-type new password:
Updating password for user zlex
现在,需要设置路径访问权限文件AuthzSVNAccessFile /etc/apache2/dav_svn.authz。
我们先做一个默认的配置,当前这个文件还不存在:
Shell代码
sudo vi /etc/apache2/dav_svn.authz
然后追加:
引用
[zlex:/]
* = r
这样,所有授权用户就都能够看到zlex项目了!
然后访问http://localhost/svn/zlex:
试试检出:
Shell代码
svn co http://localhost/svn/zlex --username snowolf
我们通过组方式管理项目,修改/etc/apache2/dav_svn.authz 文件:
Shell代码
sudo vi /etc/apache2/dav_svn.authz
我们定义一个超级用户组admin,组中成员为snowolf;开发组developer,组中成员为snowolf,zlex,多个用户用逗号分隔。
引用
[groups]
admin = snowolf
developer = snowolf, zlex
让admin和developer组成员有创建项目版本库的权限,其余用户只有查看权限:
引用
[zlex:/]
*=r
@admin = rw
@developer = rw
给出一个完整配置:
引用
[groups]
admin = snowolf
developer = zlex
[zlex:/]
@admin = rw
@developer = rw
* =
有关Subversion详细配置,参照Subversion官方中文文档!
修改这个配置文件时,不需要重启apache!
4.简单测试
我们之前构建了一个项目仓库——zlex,现在项目有了,我们需要构建相应的版本库管理,及trunk、tags以及branches!
用命令创建:
Shell代码
svn mkdir "http://localhost/svn/zlex/branches" "http://localhost/svn/zlex/tags" "http://localhost/svn/zlex/trunk" -m "create a new project zlex" --username "snowolf"
这时,我们用zlex账号提交一个docs目录:
Shell代码
svn mkdir "http://192.168.49.132/svn/zlex/docs" -m "文档目录" --username zlex
系统会提示输入密码:
192.168.49.132是我本机的IP地址!
我们可以使用命令将项目签出:
Shell代码
svn checkout "http://localhost/svn/zlex/trunk@HEAD" -r HEAD --depth infinity zlex-svn --username zlex
我们随便修改一个文件:
提交修改:
如果你参照征服 Apache + SSL完成了HTTPS平台搭建,这时候,也可以使用HTTPS方式访问了:
4.SVN同步WEB
原理:基于subversion的钩子,即hook(在每个版本库下有hooks文件夹,里面有很多钩子程序)。在subversion执行一个操作时,那会相应的首先去调用相关的钩子程序(如果存在的话)。那么实现一个同步的测试服务器,我们只需要在一个用户执行完毕一个commit操作之后,让钩子程序去自动更新测试服务器的文件即可。通过这个思路,我们需要作的就是建立一个post-commit的钩子。
钩子文件在你的svn版本库hooks目录下,即存放subversion版本数据的文件夹。以我写的情况为例,
Linux的钩子文件应该在/var/lib/svn/project/hooks里
hooks文件详解
# start-commit 提交前触发事务
# pre-commit 提交完成前触发事务
# post-commit 提交完成时触发事务
# pre-revprop-change 版本属性修改前触发事务
# post-revprop-change 版本属性修改后触发事务
1) 使用checkout建立一个工作复本
(a) cd /var/www
(b) sudo svn co file://localhost/var/lib/svn/project
2) 建立钩子文件
(a) cd /var/lib/svn/project/hooks
(b) sudo cp -r post-commit.tpl post-commit
(c) sudo gedit post-commit
输入以下内容
#!/bin/sh
REPOS="$1"
REV="$2"
export LANG=en_US.UTF-8
svn update --username SVN帐号 --password SVN密码 /var/www/project
说明:REPOS即第一个变量$1是subversion数据库的地址,REV即第二的变量$2是commit之后的版本号,注意:脚本左边不能留空格。
(d) 编辑完毕后设置文件权限为可执行:
sudo chmod 755 post-commit
3) sudo chown -R www-data:www-data /var/www/project
sudo -R u+w /var/www/project
说明因为apache是使用用户www-data运行, 所以必须给用户www-data设置/var/www/project的权限, 不然当使用SVN同步WEB时,会提示没有权限.
选用Ubuntu Server 10.04,Apache 2.2.14,Subversion 1.6.6。
步骤:
安装SVN相关模块
配置SVN版本库
配置APACHE
简单测试
1.安装SVN相关模块
这里主要用到的是Subversion 以及Apache与SVN相关的模块(DAV_SVN)!
执行命令,安装:
Shell代码
sudo apt-get install subversion libapache2-svn
注意观察安装后的结果:
引用
Considering dependency dav for dav_svn:
Enabling module dav.
Enabling module dav_svn.
Run '/etc/init.d/apache2 restart' to activate new configuration!
如果看到这样的提示,那说明DAV_SVN模块已经成功安装,可以重启Apache看看是否正常启动:
Shell代码
sudo /etc/init.d/apache2 restart
或者,使用
Shell代码
sudo service apache2 restart
以我本机为例,正常启动了:
引用
zlex@localhost:~$ sudo /etc/init.d/apache2 restart
* Restarting web server apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
... waiting .apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
当然,稍后你可能需要修改/etc/apache2/mods-available/dav_svn.conf文件,配置SVN版本库等。
2.配置SVN版本库
完成上述操作,只是为Apache获知SVN给出了一种途径,最关键的还是要配置SVN相关部分!
首先,我们要创建subversion组并把www-data作为subversion中的一员。因为,apache是通过www-data账户启动的,我们需要让它能够访问subversion组的文件!
Shell代码
sudo addgroup subversion
sudo usermod -G subversion -a www-data
然后,我们要配置版本库:
我们可以在/var/lib目录下构建一个svn目录,作为SVN版本库根目录:
Shell代码
cd /var/lib
sudo mkdir svn
假设我们要创建版本库zlex:
Shell代码
cd svn
sudo svnadmin create zlex
更改版本库所属用户、组:
Shell代码
sudo chown -R root:subversion zlex
赋予组成员对所有新加入文件仓库的文件拥有相应的权限:
Shell代码
sudo chmod -R g+rws zlex
试试
Shell代码
svn co file://localhost/var/lib/svn/zlex
,这时候应该可以访问了!
3.配置Apache
接下来,我们需要修改/etc/apache2/mods-available/dav_svn.conf文件,配置SVN版本库:
Shell代码
sudo vi /etc/apache2/mods-available/dav_svn.conf
打开红框中的注释,
Conf代码
# dav_svn.conf - Example Subversion/Apache configuration
#
# For details and further options see the Apache user manual and
# the Subversion book.
#
# NOTE: for a setup with multiple vhosts, you will want to do this
# configuration in /etc/apache2/sites-available/*, not here.
# <Location URL> ... </Location>
# URL controls how the repository appears to the outside world.
# In this example clients access the repository as http://hostname/svn/ # Note, a literal /svn should NOT exist in your document root.
<Location /svn>
# Uncomment this to enable the repository
DAV svn
# Set this to the path to your repository
#SVNPath /var/lib/svn
# Alternatively, use SVNParentPath if you have multiple repositories under
# under a single directory (/var/lib/svn/repo1, /var/lib/svn/repo2, ...).
# You need either SVNPath and SVNParentPath, but not both.
SVNParentPath /var/lib/svn
# Access control is done at 3 levels: (1) Apache authentication, via
# any of several methods. A "Basic Auth" section is commented out
# below. (2) Apache <Limit> and <LimitExcept>, also commented out
# below. (3) mod_authz_svn is a svn-specific authorization module
# which offers fine-grained read/write access control for paths
# within a repository. (The first two layers are coarse-grained; you
# can only enable/disable access to an entire repository.) Note that
# mod_authz_svn is noticeably slower than the other two layers, so if
# you don't need the fine-grained control, don't configure it.
# Basic Authentication is repository-wide. It is not secure unless
# you are using https. See the 'htpasswd' command to create and
# manage the password file - and the documentation for the
# 'auth_basic' and 'authn_file' modules, which you will need for this
# (enable them with 'a2enmod').
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd
# To enable authorization via mod_authz_svn
AuthzSVNAccessFile /etc/apache2/dav_svn.authz
# The following three lines allow anonymous read, but make
# committers authenticate themselves. It requires the 'authz_user'
# module (enable it with 'a2enmod').
#<LimitExcept GET PROPFIND OPTIONS REPORT>
Require valid-user
#</LimitExcept>
</Location>
分述:
<Location /svn>与</Location>成对儿出现!
DAV svn开启DAV模块支持!
SVNPath /var/lib/svn与SVNParentPath /var/lib/svn选其一,不可同时出现!建议使用SVNParentPath,可以在SVN根目录下创建多个SVN版本库!
引用
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd
定义了授权类型、并指定了密码文件(/etc/apache2/dav_svn.passwd)。
AuthzSVNAccessFile /etc/apache2/dav_svn.authz授权配置文件,规定了路径访问权限!
引用
#<LimitExcept GET PROPFIND OPTIONS REPORT>
Require valid-user
#</LimitExcept>
建议只使用Require valid-user,打开<LimitExcept/>注释,将允许匿名访问!
现在通过命令设置SVN账户:
Shell代码
sudo htpasswd -c /etc/apache2/dav_svn.passwd <username>
这里用到参数-c,是因为/etc/apache2/dav_svn.passwd文件不存在,如果文件存在,则无需该参数!否则,将覆盖掉原有密码文件!
形如:
引用
sudo htpasswd -c /etc/apache2/dav_svn.passwd snowolf
New password:
Re-type new password:
Updating password for user snowolf
可以追加多个账户!
引用
sudo htpasswd /etc/apache2/dav_svn.passwd zlex
New password:
Re-type new password:
Updating password for user zlex
现在,需要设置路径访问权限文件AuthzSVNAccessFile /etc/apache2/dav_svn.authz。
我们先做一个默认的配置,当前这个文件还不存在:
Shell代码
sudo vi /etc/apache2/dav_svn.authz
然后追加:
引用
[zlex:/]
* = r
这样,所有授权用户就都能够看到zlex项目了!
然后访问http://localhost/svn/zlex:
试试检出:
Shell代码
svn co http://localhost/svn/zlex --username snowolf
我们通过组方式管理项目,修改/etc/apache2/dav_svn.authz 文件:
Shell代码
sudo vi /etc/apache2/dav_svn.authz
我们定义一个超级用户组admin,组中成员为snowolf;开发组developer,组中成员为snowolf,zlex,多个用户用逗号分隔。
引用
[groups]
admin = snowolf
developer = snowolf, zlex
让admin和developer组成员有创建项目版本库的权限,其余用户只有查看权限:
引用
[zlex:/]
*=r
@admin = rw
@developer = rw
给出一个完整配置:
引用
[groups]
admin = snowolf
developer = zlex
[zlex:/]
@admin = rw
@developer = rw
* =
有关Subversion详细配置,参照Subversion官方中文文档!
修改这个配置文件时,不需要重启apache!
4.简单测试
我们之前构建了一个项目仓库——zlex,现在项目有了,我们需要构建相应的版本库管理,及trunk、tags以及branches!
用命令创建:
Shell代码
svn mkdir "http://localhost/svn/zlex/branches" "http://localhost/svn/zlex/tags" "http://localhost/svn/zlex/trunk" -m "create a new project zlex" --username "snowolf"
这时,我们用zlex账号提交一个docs目录:
Shell代码
svn mkdir "http://192.168.49.132/svn/zlex/docs" -m "文档目录" --username zlex
系统会提示输入密码:
192.168.49.132是我本机的IP地址!
我们可以使用命令将项目签出:
Shell代码
svn checkout "http://localhost/svn/zlex/trunk@HEAD" -r HEAD --depth infinity zlex-svn --username zlex
我们随便修改一个文件:
提交修改:
如果你参照征服 Apache + SSL完成了HTTPS平台搭建,这时候,也可以使用HTTPS方式访问了:
4.SVN同步WEB
原理:基于subversion的钩子,即hook(在每个版本库下有hooks文件夹,里面有很多钩子程序)。在subversion执行一个操作时,那会相应的首先去调用相关的钩子程序(如果存在的话)。那么实现一个同步的测试服务器,我们只需要在一个用户执行完毕一个commit操作之后,让钩子程序去自动更新测试服务器的文件即可。通过这个思路,我们需要作的就是建立一个post-commit的钩子。
钩子文件在你的svn版本库hooks目录下,即存放subversion版本数据的文件夹。以我写的情况为例,
Linux的钩子文件应该在/var/lib/svn/project/hooks里
hooks文件详解
# start-commit 提交前触发事务
# pre-commit 提交完成前触发事务
# post-commit 提交完成时触发事务
# pre-revprop-change 版本属性修改前触发事务
# post-revprop-change 版本属性修改后触发事务
1) 使用checkout建立一个工作复本
(a) cd /var/www
(b) sudo svn co file://localhost/var/lib/svn/project
2) 建立钩子文件
(a) cd /var/lib/svn/project/hooks
(b) sudo cp -r post-commit.tpl post-commit
(c) sudo gedit post-commit
输入以下内容
#!/bin/sh
REPOS="$1"
REV="$2"
export LANG=en_US.UTF-8
svn update --username SVN帐号 --password SVN密码 /var/www/project
说明:REPOS即第一个变量$1是subversion数据库的地址,REV即第二的变量$2是commit之后的版本号,注意:脚本左边不能留空格。
(d) 编辑完毕后设置文件权限为可执行:
sudo chmod 755 post-commit
3) sudo chown -R www-data:www-data /var/www/project
sudo -R u+w /var/www/project
说明因为apache是使用用户www-data运行, 所以必须给用户www-data设置/var/www/project的权限, 不然当使用SVN同步WEB时,会提示没有权限.
相关文章推荐
- svn服务器配置以及自动同步到web服务器
- svn服务器的搭建以及利用svn hook与web根目录同步
- Centos6.3下apache+svn部署web版本同步 推荐
- Linux下SVN部署/安全及权限配置,实现web同步更新
- Linux下SVN部署/安全及权限配置,实现web同步更新
- SVN配置以及自己主动部署到apache虚拟文件夹
- 服务器搭建javaWeb开发环境—svn安装与配置以及使用
- CentOs+Apache+websvn的配置必须成功版! 推荐
- Linux下SVN部署/安全及权限配置,实现web同步更新
- 记--linux 下svn安装配置,同步web目录
- 阿里云服务器安装wdcp面板和SVN服务器,以及实现同步更新web根目录
- SVN-1.5.3+Apache-2.0.59在windows下的配置与权限设置,以及配置HTTP方式访问SVN服务器
- JAVAWEB开发之Solr的入门——Solr的简介以及简单配置和使用、solrJ的使用、Solr数据同步插件
- yum搭建svn apache 利用钩子检出到web目录 自动同步
- 【原创】在Windows 环境下利用SVN和Apache以及Ankh配置源代码管理服务
- Centos下SVN安装以及同步到web目录
- SVN配置以及自动部署到apache虚拟目录
- Linux 下 Trac SVN apache SSL 配置安装以及整合
- Centos下SVN安装以及同步到web目录
- ubuntu配置svn服务器并且同步更新web目录