windwos下svn配置和基于Apache配置

1,软件下载

系统要求Windows XP(32-bit and 64-bit)、Windows Server 2003 (32-bit and 64-bit)、Windows Server 2008 (64-bit)、Windows Vista(32-bit and 64-bit)、Windows 7 (32-bit and 64-bit)。

下载WANdiscoSubversion,它包括Subversion、Apache、TortoiseSVN软件包。

2,软件安装

根据提示安装即可。

注意以下几点:

1. 建立一个svn server。在第2步选择组件中,选择了subversion 1.6.12 server选项。如果你仅仅只需要svn client,就可以去掉这个选项。

2. 在第4步,Apache Httpd configuration如下图所示:


Repository Directory,意思是版本库目录。默认为:C:\repositories。
Repository Location Prefix,意思是URL访问版本库的根目录。默认为/svn,例如:
http://192.168.1.2/svn/repository/
Repository Directory对应的内容改为,你存放版本库的目录。例如:d:\svn。
直接按Install安装也可以,可以通过修改配置文件Apache2/conf/subversion.conf的方式修改。

3,建立版本库(Repository)

运行Subversion服务器需要首先要建立一个版本库(Repository),可以看作服务器上存放数据的数据库。Svn把与当前版本库对应项目的所有修改信息,保存到版本库中。

1) 在安装了Subversion服务器之后,可以直接运行,如:

cmd命令界面输入:

3. svnadmin create d:\svn\repository

就会在目录d:\svn\repository下创建一个版本库,版本库模式为BDB。

2) 我们也可以使用TortoiseSVN图形化的完成这一步:

在目录d:\svn\repository下"右键->TortoiseSVN->Create Repository here...“然后就创建了一系列目录和文件

4,配置用户和权限

1) 来到d:\svn\repository\conf目录,修改svnserve.conf:

改为:

[general]

# anon-access = read

auth-access = write

password-db = passwd

authz-db = authz

realm = testproject

注意以上所有命令,必须置顶,即去除#号的同时也要去掉空格号。

下面来解释下上面命令的意思。

"anon-access = read"意思是,匿名访问用户权限为:读。

"auth-access = write"意思是,验证用户权限为:读写。

"password-db = passwd"意思是,用户密码文件(配置允许访问的svn用户及密码)指向: 同目录的passwd。当然你也可以用绝对路径的方式指定。

"authz-db = authz"意思是,权限配置文件指向:同目录的authz。权限配置文件会更改用户密码文件中定义的默认权限。

"realm = testproject"意思是,版本库标识符,在权限配置文件中会用到。

2) 然后修改同目录的passwd文件,去掉下面三行的注释:

[users]

# harry = harryssecret

# sally = sallyssecret

最后变成:

[users]

harry = harryssecret

sally = sallyssecret

在passwd文件中,“=”前的字符就是用户名,后面的就是密码。还要注意“[users]”前面的注释“#”一定要删除掉。

3) 在是修改同目录下的authz文件。

* 权限配置文件中出现的用户名必须已在用户配置文件中定义。

* 对权限配置文件的修改立即生效,不必重启svn。

用户组格式:

[groups]

<用户组名> = <用户1>,<用户2>

其中,1个用户组可以包含1个或多个用户,用户间以逗号分隔。

版本库目录格式:

[<版本库>:/项目/目录]

@<用户组名> = <权限>

<用户名> = <权限>

其中,方框号内部分可以有多种写法:

/ 表示根目录及以下。根目录是svnserve启动时指定的,我们指定为E:\svn。这样,/就是表示对全部版本库设置权限。

结合以上所述,创建的版本库repository,及其svnserve.conf配置文件中"realm = testproject"

testproject:/ 表示对版本库repository设置权限

testproject:/abc 表示对版本库repository中的abc项目设置权限

testproject:/abc/aaa 表示对版本库repository中的abc项目的aaa目录设置权限

版本库标识符(repository's uuid)的作用,当两个版本库使用同一个权限配置文件时候,用于区分不同的版本库。

权限主体可以是用户组、用户或*,用户组在前面加@,*表示全部用户。权限可以是w、r、wr和空,空表示没有任何权限。

示例:

[groups]
admin =  harry,sally

[/]
@admin = rw

[testproject:/abc/aaa]
king = rw


[testproject:/]
@admin = rw

注意:在基于apache配置的SVN 中
"realm = <版本库的文件夹名称>"(例如:版本库文件夹名称为repository
[repository:/]
@admin = rw)

5-1,运行独立服务器

cmd命令界面中运行
svnserve -d -r E:\svn

我们的服务器程序就已经启动了。注意不要关闭命令行窗口,关闭窗口也会把svnserve停止。这时,我们可以用"svn://localhost"了

5-2,初始化导入

来到我们想要导入的项目,例如:E:\flexworkspace\flex

右键->TortoiseSVN->Import...

在URL of repository输入"file:///e:/svn/repository/flex"

在URL of repository输入“svn://192.168.1.2/repository/flex”

在URL of repository输入“http://localhost/svn/repository/flex”(需要配置apache)

在Import Message中输入你的日志信息

完成之后目录没有任何变化,如果没有报错,数据就已经全部导入到了我们刚才定义的版本库中。

需要注意的是,这一步操作可以完全在另一台安装 了TortoiseSVN的主机上进行。例如运行svnserve的主机IP是133.96.121.22,则URL部分输入的内容就是 “svn://133.96.121.22/repository”。这里注意,svn://在svn独立服务器启动,即第5-1步执行的情况下,才被支持的一种通信协议。

"svn://localhost"指向的是,命令"svnserve -d -r E:\svn" -r后面指向的目录E:\svn。

7,基本客户端操作

取出版本库到一个工作拷贝:

来到任意空目录下,例如:E:\project,运行右键->Checkout,在URL of repository中输入svn://localhost/repository/flex,这样我们就得到了一份工作拷贝。

在工作拷贝中作出修改并提交:

打开任意文件例如:readme.txt,作出修改,然后右键->Commit...,这样我们就把修改提交到了版本库,我们可以运行。

察看所作的修改:

readme.txt上右键 ->TortoiseSVN->Show Log,这样我们就可以看到我们对这个文件所有的提交。在版本1上右键->Compare with working copy,我们可以比较工作拷贝的文件和版本1的区别。

8,配置基于Apache的SVN服务器

8.1.安装

如果安装的是WANdiscoSubversion,同时配置了以上设置。就可以通过浏览器访问你的版本库了。

在浏览器中输入:http://localhost/svn/repository

8.2.设置

当然,我们要知其然,更要求其所以然。有两个Apache配置文件与svn有关,分别是httd.conf和subversion.conf。

使用如记事本之类的文本编辑器编辑Apache的配置文件(例如D:\WANdisco\Subversion\Apache2\conf),修改以下内容:

subversion.conf的设置,从httpd.conf最后行“Include conf/subversion.conf”可以看出,subversion.conf只是httpd.conf的扩展文件而已。

首先,看subversion.conf文件内容,去除不需要的注释:
#
# WANdisco Subversion Configuration
# http://www.wandisco.com
#
# For more information on HTTPD configuration options for Subversion please see:
# http://svnbook.red-bean.com/nightly/en/svn.serverconfig.httpd.html
# Please remember that when using webdav HTTPD needs read and write access your repositories.

# You can generate your username/password file data from here:
# http://www.htaccesstools.com/htpasswd-generator/

Timeout 3000000
MaxKeepAliveRequests 0                                                          
KeepAlive On                                                                    
KeepAliveTimeout 300000
ThreadsPerChild 300
MaxRequestsPerChild  0

<VirtualHost *:80>
 KeepAlive On
 <Location /svn>
  DAV svn
  #SVNPath "D:\SVN\ls"
  SVNParentPath "D:\SVN"
  # SVNParentPath and authz fix http://subversion.tigris.org/issues/show_bug.cgi?id=2753
  RedirectMatch ^(/svn)$ $1/ 
  AuthType Basic
  AuthName "Subversion repositories!Login needed!"
  # If you didn't specify a password file during installation the
  # next line needs to be configured for user authentication.
  AuthUserFile "D:\WANdisco\conf\passwd"
  AuthzSVNAccessFile "D:\SVN\Repository\conf\authz"
  # Satisfy Any
  Require valid-user
  # Order allow,deny
  # Allow from all
  SVNAutoversioning on
 </Location>
 # Enable Subversion logging 
CustomLog logs/svn_logfile "%t %u %{SVN-ACTION}e" env=SVN-ACTION 
</VirtualHost>



主要来解释下,<Location /svn></VirtualHost>之间内容的意思。

DAV svn
告诉Apache哪个模块使用svn作为根目录。

SVNPath
其语法是:
   <Location /svn/repos_name>
    DAV svn
    SVNPath /absolute/path/to/repository
</Location>
其中 "/svn/repos_name" 就是客户端存取特定档案库的 URI(Uniform Resource Indentifier),SVNPath 后面指定的路径则是档案库的绝对路径,假设我们的档案库实际存放的路径是 d:/svn/repository,并且希望客户端使用 "http://myserver/svn/repos_name" 的 URL 来存取档案库,例如:
<Location /svn>
    DAV svn
    SVNPath d:/svn/repository
</Location>

SVNParentPath
如果你的档案库都集中放在某个目录之下,例如:d:/svn,那你就可以使用 SVNParentPath 的方式指定档案库的根路径,例如:
<Location /svn>
    DAV svn
    SVNParentPath "d:/svn"
</Location>
这表示可以让任何人都可以透过 http://myserver/svn/<档案库名称> 的方式,存取位于 d:/svn 这个目录以下的所有档案库。也就是说,这个设定动作只需要一次,如果使用 SVNPath,你必须为各个档案库分别指定对应的路径。
以上两种设定方式都可以,方便起见,这里我用 SVNParentPath 来统一指定所有档案库的父层 URL 路径。
注意:当设定方式为SVNParentPath 时,访问URL必须为 http://myserver/svn/<档案库名称>(例如:http://192.168.1.2/svn/repository),如果使用 http://myserver/svn将出现如下错误:
Forbidden You don't have permission to access /svn/ on this server。

AuthType Basic。
启用基本的验证,比如用户名/密码对

AuthName "Subversion repositories"
当一个验证对话框弹出时,告诉用户这个验证是用来做什么的

AuthUserFile "D:\WANdisco\conf\passwd"
指定D:\WANdisco\Subversion\passwd用为密码文件用来验证用户的用户名及密码

AuthzSVNAccessFile "D:\WANdisco\conf\authz"
指定D:\WANdisco\Subversion\authz来限定各个用户或组在版本库中目录的访问权限

Require valid-user
限定用户只有输入正确的用户名及密码后才能访问这个路径

其中,passwd文件需要用Apache2\bin下的htpasswd.exe来生成。

在命令行下,进入bin目录下,运行htpasswd -c passwd <username>。将会提示你输入密码。成功输入密码后,将在bin目录下生成passwd文件。把它放到D:\WANdisco\Subversion\下即可


注意:在使用Apache的时候,档案库文件夹->conf文件夹下(svnserver.conf,passwd,authz)文件是没有用的,不需要启动独立服务器(svnserve -d -r d:svn)

authz
### This file is an example authorization file for svnserve.
### Its format is identical to that of mod_authz_svn authorization
### files.
### As shown below each section defines authorizations for the path and
### (optional) repository specified by the section name.
### The authorizations follow. An authorization line can refer to:
###  - a single user,
###  - a group of users defined in a special [groups] section,
###  - an alias defined in a special [aliases] section,
###  - all authenticated users, using the '$authenticated' token,
###  - only anonymous users, using the '$anonymous' token,
###  - anyone, using the '*' wildcard.
###
### A match can be inverted by prefixing the rule with '~'. Rules can
### grant read ('r') access, read-write ('rw') access, or no access
### ('').

[aliases]
# joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average

[groups]
admin = admin
# harry_and_sally = harry,sally
# harry_sally_and_joe = harry,sally,&joe

# [/foo/bar]
# harry = rw
# &joe = r
# * =

# [repository:/baz/fuz]
# @harry_and_sally = rw
# * = r

[repository:/flex]
@admin = rw


passwd
admin:$apr1$hZ9bl.Lv$25M8fEtNuPymBhPw8cWBA0

或者
admin:admin
xes:2860086

猜你喜欢

转载自xuershan.iteye.com/blog/772666
今日推荐