分享

Centos+Nginx搭建SVN服务器

 文档集成 2014-01-25

Google的svn服务是免费的,但是总是时不时抽风连不上,有时候让人抓狂。前两天刚入手了一台阿里云主机,今天尝试在主机上安装svn服务器来托管自己项目的代码。

1. 采用yum源安装svn服务端,命令行如下:

1
yum install <a title="subversion" href="http:///?tag=subversion">subversion</a>

安装完成后,检查是否安装成功:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@AY130705154825404b69Z /]# <a title="svnserve" href="http:///?tag=svnserve">svnserve</a> --version
svnserve, version 1.6.11 (r934486)
   compiled Apr 11 2013, 16:13:51
Copyright (C) 2000-2009 CollabNet.
Subversion is open source software, see http://subversion.tigris.org/
This product includes software developed by CollabNet (http://www.Collab.Net/).
The following repository back-end (FS) modules are available:
* fs_base : Module for working with a Berkeley DB repository.
* fs_fs : Module for working with a plain file (FSFS) repository.
Cyrus SASL authentication is available.

2. 配置svn服务器,步骤如下:

(1) 创建svn仓库:

先创建svn仓库根目录:

1
2
mkdir -p /home/svnroot
chmod -R 777 /home/svnroot
1
svnadmin create /home/svnroot/project

(2) nginx.conf指定一个域名到 /home/svnroot 目录,并关闭文件列表显示:

1
2
3
4
5
6
7
8
server
        {
                listen          80;
                server_name     svn.***.com;
                index           index.html index.htm default.htm default.html;
                root            /home/svnroot;
                autoindex       off;
        }

(3) 配置该project的svn权限信息:

在/home/svnroot/project目录下存在如下文件目录:

1
conf  db  format  hooks  locks  README.txt

编辑权限相关:

[1] svn服务配置,如密码库,默认权限等

1
vim conf/svnserve.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[general]
### These options control access to the repository for unauthenticated
### and authenticated users.  Valid values are "write", "read",
### and "none".  The sample settings below are the defaults.
anon-access = none
auth-access = write
### The password-db option controls the location of the password
### database file.  Unless you specify a path starting with a /,
### the file's location is relative to the directory containing
### this configuration file.
### If SASL is enabled (see below), this file will NOT be used.
### Uncomment the line below to use the default password file.
password-db = passwd
### The authz-db option controls the location of the authorization
### rules for path-based access control.  Unless you specify a path
### starting with a /, the file's location is relative to the the
### directory containing this file.  If you don't specify an
### authz-db, no path-based access control is done.
### Uncomment the line below to use the default authorization file.
authz-db = authz
### This option specifies the authentication realm of the repository.
### If two repositories have the same authentication realm, they should
### have the same password database, and vice versa.  The default realm
### is repository's uuid.
realm = My First Repository

[2] 设置账号和密码,密码数据库在上面已经指定了:

1
vim conf/passwd
1
2
[users]
riqi=dfasddf03ndb

[3] 设置账号或者账号组相应的权限,读和写:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[aliases]
# joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average
[groups]
# harry_and_sally = harry,sally
# harry_sally_and_joe = harry,sally,&joe
[/]
riqi=rw
# harry = rw
# &joe = r
# * =
# [repository:/baz/fuz]
# @harry_and_sally = rw
# * = r

上面直接指定riqi账号的权限为读写,比较简单。如果有多个开发人员,可以将多个开发人员归属到一个组,然后设置一个组的权限就可以了,格式为:@+组名=权限列表

(4) 权限设置好后,启动svn服务:

1
svnserve -d -r /home/svnroot

(5) 检出一个版本:

1
svn co --username riqi --password dfasddf03ndb https://svn.***.com/project /home/wwwroot/project/

补充:

svn提供了hooks功能,可以在svn操作过程中触发一些操作,如提交代码前检测代码变更原因,提交代码后自动update最新版本到指定目录等等。如上操作分别通过hooks/pre-commit和hooks/post-commit实现,默认hooks目录下会存放*.tmpl文件,供参考使用。如果要启用的话,可以将.tmpl后缀去掉,然后给脚本赋予可执行权限,如提交代码后触发版本更新到指定目录:

1
vim hooks/post-commit
1
/usr/bin/svn update --username riqi --password dfasddf03ndb /home/wwwroot/project/

其它hooks应用请参考网络资料!

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多