ubuntu安装和配置subversion

ubuntu:12.04.1
在本地安装ubuntu,并与apache集成

1、安装subversion
引用
apt-get install subversion
apt-get install subversion-tools

2、安装apache
引用
apt-get install apache2
apt-get install libapache2-svn

3、配置subversion与apache集成
1)查看/etc/apache2/mods-enabled/dav_svn.load文件,有mod_dav_svn.so和mod_authz_svn.so这两个动态库说明apache已经加载了Subversion的访问控制模块。
如果没有,手动添加
引用
# Depends: dav
LoadModule dav_svn_module /usr/lib/apache2/modules/mod_dav_svn.so
LoadModule authz_svn_module /usr/lib/apache2/modules/mod_authz_svn.so

2)编辑/etc/apache2/mods-enabled/dav_svn.conf文件,取消svn配置的注释,修改后的内容如下
引用
<Location /svn>

  # Uncomment this to enable the repository
  DAV svn

  # Set this to the path to your repository
  #SVNPath /usr/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 /usr/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 (enable that module separately):
  <IfModule mod_authz_svn.c>
    AuthzSVNAccessFile /etc/apache2/dav_svn.authz
  </IfModule>

  # 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>

3)创建配置中的两个文件
引用
touch /etc/apache2/dav_svn.passwd
touch /etc/apache2/dav_svn.authz

4)配置完成后重启apache
引用
/etc/init.d/apache2 restart

4、建立版本库
引用
makedir /usr/svn/
makedir /usr/svn/repos
svnadmin create --fs-type fsfs /usr/svn/repos

指定数据存储为 FSFS,如果要指定为 Berkeley DB,则将 fsfs 替换为 bdb,推荐选用FSFS格式。
检查版本库是否可以checkout:
引用
root@AY130321164319777920:~# svn co file:///usr/svn/repos
Checked out revision 0.

5、添加项目
需要考虑的是,将每一个项目分别放在不同的版本库里面,还是将它们放在统一的版本库里面。统一的版本库更加容易升级和备份,但由于访问权限控制是针对整个版本库的,也为不同项目配置不同的访问权限带来了麻烦。所以,应该根据实际情况权衡考虑。
引用
mkdir /home/project
mkdir /home/project/gboat3
root@AY130321164319777920:/home# svn import /home/project file:///usr/svn/repos --message "init"
Adding         /home/project/gboat3

Committed revision 1.

用 svn list 确认导入的项目是否正确
引用
root@AY130321164319777920:/home# svn list --verbose file:///usr/svn/repos
      1 root                  Apr 23 20:02 ./
      1 root                  Apr 23 20:02 gboat3/

6、subversion添加用户
添加第一个用户,要加参数-c。以后不用加。
引用
htpasswd -c /etc/apache2/dav_svn.passwd user1

Subversion追加用户:
引用
htpasswd /etc/apache2/dav_svn.passwd user2

7、subversion分配权限
新添加的用户是不能访问Subversion的,还要为他分配权限。编辑/etc/apache2/dav_svn.authz文件
引用

[groups]
admin = user1
gboat = user1,user2
[/]
@admin = rw
* = r
[/gboat3]
user1= rw
@gboat = rw
* = r

其中* = 表示其它所有用户都没有任何权限。@表示用户组,*表示所有用户,[/]表示全部目录。注意顶格写。UTF-8格式才能配置SVN权限,Linux下默认是UTF-8,Windows下有转换工具,比如Eclipse->Edit->最后一项。
特别注意:权限分配时,不能写成user1, user2=r,这样提交时会出现错误:svn Commit failed checkout of 403 forbidden。应该写成user1= r和user2= r
8、subversion启动
引用
svnserve -d -r /home/svn/repos

Subversion 设计了一个抽象的网络层,版本库建立完毕之后,可以通过各种服务器向外公布。svnserve 是 Subversion 自带的一个小型的服务器,它使用独立的协议与客户端。–i 作为 inetd 启动。-d参数表示svnserve将会作为一个服务程序运行在后台。-r参数表示将/home/svn指定为代码库的根目录。这样,当客户端使用类似svn://192.168.0.1/repos这样的URL访问服务器的时候,其所访问的真实库是/home/svn/repos。另外如 --listen-port,--listen-host 可以指定绑定的地址和端口,-R 可以强制设定为 Read-Only 模式。
启动后检查服务
引用
ps -ef | grep svnserv


P.S.
【1】apache配置说明:
<Location /svn>  意思是Subversion版本可用的URL是http://SubversionServerIP/svn
DAV SVN  告诉Apache是哪个模块响应哪个URL的请求,在这里是Subversion模块
SVNParentPath /home/svn  告诉Subversion需要查看的版本库在/home/svn之下。如果不希望为每个单独的项目都进行单独的设置,可以把所有项目都存放在统一的资源库目录,使用SVNParentPath指令来指定存放所有项目的路径。否则使用SVNPath
SVNPath  单版本库时使用此项指明版本库的路径,但在多版本库中不要使用此项
AuthType Basic  认证类型为基本认证,就是用户名和密码
AuthName "Subversion repository"  认证名称,将在浏览器界面弹出一个对话框,标题为Subversion repository
AuthUserFile /etc/apache2/dav_svn.passwd  指定使用的认证密码文件,即访问版本库用户的文件,用apache的htpasswd命令生成
AuthzSVNAccessFile /etc/apache2/dav_svn.authz  设定访问版本库权限的文件
Require valid-user  要求验证用户,即不能匿名访问。如果没有该语句,则只能第一个用户可以访问新建库
【2】版本库各文件夹说明
conf 目录下存放了版本库的配置文件,包括用户访问控制和权限控制等内容;
dav 目录是提供给 Apache 相关模块的目录;
db 目录下存放着 Subversion 所要管理的所有受版本控制的数据,不同的存储方式(Berkeley DB 或者 FSFS)下有着不同的目录结构,不过我们一般不用直接修改和查看这个目录下的内容,Subversion 的命令可以安全的操作这个目录;
hooks 目录存放着钩子脚本及其模版(一种版本库事件触发程序);
locks 目录存放着 Subversion 版本库锁定数据,用来追踪存取文件库的客户端;
format 文件是一个文本文件,里面只放了一个整数,表示当前文件库配置的版本号

猜你喜欢

转载自lysming.iteye.com/blog/1852268