Apache + SVN配置

SVN用了很久,不过一直没有机会配置。以前工作的时候都是技术总监、部门经理搞定,自己很少有机会尝试。更别说基于svn方式、http方式,亦或是https方式访问svn了,只有用的份,没有了解的份。最近,配置Apache开窍,索性再深入一步,搭建基于HTTPS平台的Apache+SVN平台。

选用Ubuntu Server 10.04,Apache 2.2.14,Subversion 1.6.6。

步骤:
  1. 安装SVN相关模块
  2. 配置SVN版本库
  3. 配置APACHE
  4. 简单测试

1.安装SVN相关模块
这里主要用到的是Subversion 以及Apache与SVN相关的模块(DAV_SVN)!
执行命令,安装:


  1. sudo apt-get install subversion libapache2-svn    
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看看是否正常启动:


  1. sudo /etc/init.d/apache2 restart    
sudo /etc/init.d/apache2 restart  


或者,使用


  1. sudo service apache2 restart    
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组的文件!

  1. sudo addgroup subversion    
  2. sudo usermod -G subversion -a www-data    
    sudo addgroup subversion  
    sudo usermod -G subversion -a www-data  

然后,我们要配置版本库:
我们可以在/var/lib目录下构建一个svn目录,作为SVN版本库根目录:

  1. cd /var/lib    
  2. sudo mkdir svn    
    cd /var/lib  
    sudo mkdir svn  

假设我们要创建版本库zlex:

  1. cd svn    
  2. sudo svnadmin create zlex    
    cd svn  
    sudo svnadmin create zlex  

更改版本库所属用户、组:


  1. sudo chown -R root:subversion zlex    
sudo chown -R root:subversion zlex  


赋予组成员对所有新加入文件仓库的文件拥有相应的权限:


  1. sudo chmod -R g+rws zlex    
sudo chmod -R g+rws zlex  

试试

  1. svn co file://localhost/var/lib/svn/zlex    
svn co file://localhost/var/lib/svn/zlex  


,这时候应该可以访问了!

3.配置Apache
接下来,我们需要修改/etc/apache2/mods-available/dav_svn.conf文件,配置SVN版本库:


  1. sudo vi /etc/apache2/mods-available/dav_svn.conf    
sudo vi /etc/apache2/mods-available/dav_svn.conf  



打开红框中的注释,


  1. # dav_svn.conf - Example Subversion/Apache configuration    
  2. #    
  3. # For details and further options see the Apache user manual and    
  4. # the Subversion book.    
  5. #    
  6. # NOTE: for a setup with multiple vhosts, you will want to do this    
  7. # configuration in /etc/apache2/sites-available/*, not here.    
  8.     
  9. <Location URL> … </Location>    
  10. # URL controls how the repository appears to the outside world.    
  11. # In this example clients access the repository as http://hostname/svn/    
  12. # Note, a literal /svn should NOT exist in your document root.    
  13. <Location /svn>    
  14.     
  15.   # Uncomment this to enable the repository    
  16.   DAV svn    
  17.     
  18.   # Set this to the path to your repository    
  19.   #SVNPath /var/lib/svn    
  20.   # Alternatively, use SVNParentPath if you have multiple repositories under    
  21.   # under a single directory (/var/lib/svn/repo1, /var/lib/svn/repo2, …).    
  22.   # You need either SVNPath and SVNParentPath, but not both.    
  23.   SVNParentPath /var/lib/svn    
  24.     
  25.   # Access control is done at 3 levels: (1) Apache authentication, via    
  26.   # any of several methods.  A “Basic Auth” section is commented out    
  27.   # below.  (2) Apache <Limit> and <LimitExcept>, also commented out    
  28.   # below.  (3) mod_authz_svn is a svn-specific authorization module    
  29.   # which offers fine-grained read/write access control for paths    
  30.   # within a repository.  (The first two layers are coarse-grained; you    
  31.   # can only enable/disable access to an entire repository.)  Note that    
  32.   # mod_authz_svn is noticeably slower than the other two layers, so if    
  33.   # you don’t need the fine-grained control, don’t configure it.    
  34.     
  35.   # Basic Authentication is repository-wide.  It is not secure unless    
  36.   # you are using https.  See the ‘htpasswd’ command to create and    
  37.   # manage the password file - and the documentation for the    
  38.   # ‘auth_basic’ and ‘authn_file’ modules, which you will need for this    
  39.   # (enable them with ‘a2enmod’).    
  40.   AuthType Basic    
  41.   AuthName “Subversion Repository”    
  42.   AuthUserFile /etc/apache2/dav_svn.passwd    
  43.     
  44.   # To enable authorization via mod_authz_svn    
  45.   AuthzSVNAccessFile /etc/apache2/dav_svn.authz    
  46.     
  47.   # The following three lines allow anonymous read, but make    
  48.   # committers authenticate themselves.  It requires the ‘authz_user’    
  49.   # module (enable it with ‘a2enmod’).    
  50.   #<LimitExcept GET PROPFIND OPTIONS REPORT>    
  51.     Require valid-user    
  52.   #</LimitExcept>     
  53.     
  54. </Location>    
    # 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/svnSVNParentPath /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账户:

  1. sudo htpasswd -c /etc/apache2/dav_svn.passwd <username>    
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
我们先做一个默认的配置,当前这个文件还不存在:

  1. sudo vi /etc/apache2/dav_svn.authz    
sudo vi /etc/apache2/dav_svn.authz  

然后追加:
引用

[zlex:/]
* = r


这样,所有授权用户就都能够看到zlex项目了!

然后访问http://localhost/svn/zlex

试试检出:


  1. svn co http://localhost/svn/zlex –username snowolf    
    svn co http://localhost/svn/zlex --username snowolf  


我们通过组方式管理项目,修改 /etc/apache2/dav_svn.authz 文件:

  1. sudo vi /etc/apache2/dav_svn.authz      
    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!
用命令创建:


  1. 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”       
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目录:

  1. svn mkdir “http://192.168.49.132/svn/zlex/docs” -m ”文档目录” –username zlex    
    svn mkdir "http://192.168.49.132/svn/zlex/docs" -m "文档目录" --username zlex  

系统会提示输入密码:

192.168.49.132是我本机的IP地址!
我们可以使用命令将项目签出:

  1. svn checkout “http://localhost/svn/zlex/trunk@HEAD” -r HEAD –depth infinity zlex-svn –username zlex    
    svn checkout "http://localhost/svn/zlex/trunk@HEAD" -r HEAD --depth infinity zlex-svn --username zlex  

我们随便修改一个文件:

提交修改:



如果你参照 征服 Apache + SSL完成了HTTPS平台搭建,这时候,也可以使用HTTPS方式访问了:



本文转载自:

http://snowolf.iteye.com/blog/740347



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值