技术开发 频道

svnserve 配置及权限管理

【IT168 技术文章】

    用SVN(Subversion)取代CVS的呼声越来越高。SVN也确实比CVS优胜很多,没有辜负众望。

    在日常工作中,如何配置好和利用好SVN,是很值得花些时间去研究研究的。在我应用SVN的这段时间里,更喜欢的是用svnserve加客户端来搭配使用。

    也就是将svnserve配置成为一个服务端,然后在Windows 下安装个TortoiseSVN 。这是一个不错的搭配选择。

    1 SVN安装 

    1.1 FreeBSD下安装SVN

    1.1.1 安装SVN

    # cd /usr/ports/devel/subversion
    # make NOPORTDOCS=YES -DWITH_SVNSERVE_WRAPPER install clean

    1.1.2 创建用户

    # pw useradd -s /bin/sh -d /var/empty -n svn

    1.2 Linux下安装SVN

    1.2.1 下载及编译安装SVN

    # wget http://subversion.tigris.org/downloads/subversion-1.3.2.tar.bz2
    # tar -jxvf subversion-1.3.2.tar.bz2
    # cd subversion-1.3.2
    # ./configure --with-zlib --enable-all-static

    1.2.2 创建用户

    # useradd -d /var/empty svn

    2 svnserve配置

    2.1 创建仓库

    2.1.1 创建仓库存放目录

    # mkdir -p /opt/svn/{repos,etc}

    2.1.2 创建SVN仓库

    # svnadmin create /opt/svn/repos/source1
    # svnadmin create /opt/svn/repos/source2
    # chown -R svn:svn /opt/svn/
    仓库名称可以根据自己的规划或喜好设定。

    2.2 配置仓库

    SVN的svnserve对于每个仓库,有一个独立的配置文件和独立的用户、权限管理。

    在这里仍然要保持配置文件svnserve.conf的独立,但是用户、权限管理是用统一的一个文件来存储。这样方便以后的管理和维护。

    另外要注意,即使svnserve服务已经运行,修改配置文件或者用户、权限管理文件,保存后马上生效,不需要重启服务。

    2.2.1 配置source1仓库

    进入仓库目录

    # cd /opt/svn/repos/source1

    2.2.2 修改配置

    你可以直接删除默认的svnserve.conf文件,然后使用下面的配置:

    # vi svnserve.conf
    [general]
    anon-access = none
    auth-access = write
    password-db = /opt/svn/etc/svn-user.conf
    authz-db = /opt/svn/etc/svn-authz.conf
    realm = My First Repository
    说明:

    anon-access = none #不允许匿名用户访问
    auth-access = write #通过验证的用户可以读和写
    password-db = /opt/svn/etc/svn-user.conf #用户保存文件
    authz-db = /opt/svn/etc/svn-authz.conf #权限管理文件
    realm = My First Repository #仓库名称 

    2.2.3 配置source2仓库

    # cd /opt/svn/repos/source2

    2.2.4 修改配置

    你可以直接删除默认的svnserve.conf文件,然后使用下面的配置:

    # vi svnserve.conf
    [general]
    anon-access = none
    auth-access = write
    password-db = /opt/svn/etc/svn-user.conf
    authz-db = /opt/svn/etc/svn-authz.conf
    realm = My Second Repository
    如果有更多的仓库,可以类推配置。

----------------------------------------------------------------------
    svnserve.conf的原始内容:

    ### This file controls the configuration of the svnserve daemon, if you
    ### use it to allow access to this repository. (If you only allow
    ### access through http: and/or file: URLs, then this file is
    ### irrelevant.)

    ### Visit http://subversion.tigris.org/ for more information.

    [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 = read
    # 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 conf directory.
    ### 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 conf
    ### directory. 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
----------------------------------------------------------------------
    3 用户及权限管理 

    3.1 用户管理

    3.1.1 创建用户存储文件

    # vi /opt/svn/etc/svn-user.conf

    3.1.2 设置用户帐号

    [users]
    harry = harryssecret
    sally = sallyssecret
    bote = botessecret
    说明:

    [users] #是必须的,标记为用户配置开始
    harry = harryssecret # harry 是用户名 , harryssecret是密码。注意,是明文密码
    sally = sallyssecret # 同上
    bote = botessecret # 同上
    往后所以仓库的用户都在这里记录就可以了。至于那个用户,允许访问那个仓库,在权限管理里限制。

    3.2 权限管理

    3.2.1 创建权限管理文件

    # vi /opt/svn/etc/svn-authz.conf

    3.2.1 设置权限管理

    [groups]
    source1 = harry
    source2 = sally

    [source1:/]
    @source1 = rw
    @source2 = r

    [source2:/]
    @source2 = rw   
    bote = rw

0
相关文章