debian apache2 svn配置

来源:百度文库 编辑:神马文学网 时间:2024/04/28 19:53:26
安装:
debian:~# apt-get install subversion subversion-tools
创建一个新的储存库:
debian:~# mkdir /home/project/svn
debian:~# svnadmin create /home/project/svn/repos
导入你的源码:
debian:~# svn import /home/project/testfile:///home/project/svn/repos
debian:~# svn listfile:///home/project/svn/repos
111.py
222.py
下面介绍与Apache组合通过WebDAV方式访问Subversion库的方式:
首先要安装好Apache2,并安装好提供WebDAV访问和svn访问的的mod_dav模块和mod_dav_svn模块:
debian:~# apt-get install apache2 libapache2-svn
【配置方法1】
=========以下内容转载“Debian学习笔记”相关文档,连接:http://man.chinaunix.net/linux/debian/debian_learning/index.html============================
配置文件位于/etc/apache2/mods-enabled/目录下,配置文件共有两个,分别是dav_svn.conf和dav_svn.load,dav_svn.load文件负责装载必要的模块,内容如下:
# Load mod_dav_svn when apache starts
LoadModule dav_svn_module /usr/lib/apache2/modules/mod_dav_svn.so
LoadModule authz_svn_module /usr/lib/apache2/modules/mod_authz_svn.so
在装载mod_dav_svn.so前,必须先装载mod_dav.so模块。它由dav.load文件控制,内容如下:
LoadModule dav_module /usr/lib/apache2/modules/mod_dav.so
dav_svn.conf是mod_dav_svn.so模块的配置文件,内容如下:
# dav_svn.conf - Example Subversion/Apache configuration
#
# For details and further options see the Apache user manual and
# the Subversion book.
# ...
# URL controls how the repository appears to the outside world.
# In this example clients access the repository ashttp://hostname/svn/
                                 #设置访问路径
# Uncomment this to enable the repository,
DAV svn                                      #启用
# Set this to the path to your repository
SVNPath home/project/svn/repos                     #设置储存库路径,仅支持单个储存库,该路径要可被Apache进程访问。
#SVNParentPath /data/subversion               #如果subversion下有多个储存库,则用SVNParentPath
# The following allows for basic http authentication.  Basic authentication
# should not be considered secure for any particularly rigorous definition of
# secure.
# to create a passwd file                     #按下面的步骤创建Apache用户验证文件
# # rm -f /etc/apache2/dav_svn.passwd
# # htpasswd2 -c /etc/apache2/dav_svn.passwd dwhedon
# New password:
# Re-type new password:
# Adding password for user dwhedon
# #
# Uncomment the following 3 lines to enable Basic Authentication
AuthType Basic                               #启用Apache基础验证
AuthName "Subversion Repository"             #设置验证框标题
AuthUserFile /etc/apache2/dav_svn.passwd     #指定验证用户文件名
# Uncomment the following line to enable Authz Authentication
AuthzSVNAccessFile /etc/apache2/dav_svn.authz  #启用目录级别授权,dav_svn.authz是授权配置文档
# The following three lines allow anonymous read, but make
# committers authenticate themselves.
#    #允许匿名访问,不允许Commit,不能与AuthzSVNAccessFile同时使用
Require valid-user
#


修改/data/subversion目录访问权限使它可被Apache进程访问,我的Apache是用www-data启动的,所以设置方法如下:
debian:~# chown -R www-data.www-data /data/subversion
通过Apache的用户验证功能可以区别匿名用户和验证用户,从而赋予匿名用户读权限和验证用户读/写的权限。这些权限只能在全局范围内设置,不能设置具体的某个目录是否能被某个用户操作。要实现目录级别的授权,就要使用mod_authz_svn.so模块提供的AuthzSVNAccessFile指令。它会指定一个授权文档,该授权文档设置具体的目录权限。根据上面的配置,授权文档名叫dav_svn.authz,它的内容如下:
[groups]              #定义组
admin=jims,ringkee
tests=tester1,tester2
[erp:/]              #定义erp储存库根目录的访问权限
@admin=rw            #admin组有读写权限
tests=r              #test用户只有读权限
[oa:/test]           #定义oa储存库下test目录的访问权限
*=                   #禁止所有用户访问,星号代表所有用户,权限为空代表没有任何权限
ringkee=rw           #打开ringkee用户的读写权限
=========以上内容转载“Debian学习笔记”相关文档,连接:http://man.chinaunix.net/linux/debian/debian_learning/index.html============================
【配置方法2】
创建一个apache调用的用户组验证文件和一个用户名密码验证文件,这里我在之前创建的目录中新增加用户验证文件,以便apache调用:
用户组验证:
debian:~# mkdir /home/project/svn/conf/svn_repos.ini
内容如下:
[groups]
Admin =lili,ljr
Users =ds
#permissions "inherit" from parent to child directory.
[/]
* =
@Admin = rw
@Users = r
#在此分为2组,Admin,Users分别有对根目录下所有版本的访问、改写及仅有访问权
用户密码验证:
debian:~# mkdir /home/project/svn/conf/user_auth
在这里使用apache的用户设置命令htpasswd来设置用户
debian:~# htpasswd -c /home/project/svn/conf/user_auth lili
password:
debian:~# htpasswd -d /home/project/svn/conf/user_auth ljr
password:
debian:~# htpasswd -d /home/project/svn/conf/user_auth ds
password:
于方法1不同之处在于,方法2为自己通过在/etc/apache2/sites-enabled新建访问路径来支持svn的调用。
具体方式如下:
新建配置文件/etc/apache2/sites-enabled/svn并设置如下以便apache调用:
debian:~# vi /etc/apache2/sites-enabled/svn
Listen 8998
NameVirtualHost 192.168.xxx.xxx:8998

ServerName 192.168.xxx.xxx:8998

DAV svn
SVNPath /home/project/svn/repos
AuthType Basic
AuthName "market SVN  repository"
AuthUserFile /home/project/svn/conf/user_auth
Require valid-user
Order Deny,Allow
Allow from all
AuthzSVNAccessFile /home/project/svn/conf/svn_repos.ini


=====================================
我是通过第二种方式配置的。
ok,截止此svn服务器可谓架设完毕,大家可以使用客户端尝试svn checkouthttp://192.168.XX.XX:8998/svn-repos/ 尝试连接了