Mac下搭建svn服务器教程分享

2015年03月24日 10:31 0 点赞 0 评论 更新于 2025-11-21 18:22

本文档在前人成果的基础上,经过亲自测试后完成,在此感谢前人的努力。本文将使用终端命令来完成 SVN 服务器的搭建。

说明:文档中 username 为 Mac 机的用户名称。

一、创建 SVN 目录

若你的机器是首次进行 SVN 的搭建,需要创建 SVN 目录。在终端中输入以下命令并回车:

mkdir /Users/username/svn

若有提示,很可能你的电脑已经存在了 svn 文件夹。若你不使用该文件夹,可将其删除后再重新运行上述命令。

二、创建 SVN Repository

在终端中输入以下命令:

svnadmin create /Users/username/svn/repository

三、查看 SVN Repository 下的文件

为了更好地理解 SVN,可查看 SVN Repository 下的文件。在终端中输入以下命令:

ls /Users/username/svn/repository/

该目录下会有六个文件:README.txtdbhooksconfformatlocks

四、配置 SVN 用户权限

1. 配置 authz 文件

在终端中输入以下命令查看 conf 目录下的文件:

ls /Users/username/svn/repository/conf

该目录下有三个文件:authzpasswdsvnserve.conf

接着,在终端中输入以下命令编辑 authz 文件:

vi /Users/username/svn/repository/conf/authz

进入编辑模式后,按下 i 键开始修改文件。文件中原始内容包含了关于授权文件的说明:

### 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]
# harry_sally_and_joe = harry,sally,&joe
[/]
#harry=123456
# &joe = r
# * =
# [repository:/baz/fuz]
# @harry_and_sally = rw
# * = r

将相关部分作如下修改:

  • [groups] 部分,将 #harry_sally_and_joe = harry,sally,&joe 修改为 username1_username2_……_and_usernamen = username1,username2,……,&usernamen。这里可以根据需要使用 SVN 的人数添加相应的用户名,务必按照此格式填写。
  • #harry = 123456 部分添加 username1 = userpasswordusername2 = userpassword 等。当然,按照提示还可以有其他的配置格式,比如 #* = password(这种做法是将所有人的密码都设为同一个)。请记住这些用户名和密码,后续步骤会用到。

修改完成后,按下 esc 键,输入 :wq 并回车,保存并退出文件。

2. 配置 passwd 文件

passwd 文件同样在当前目录下。在终端中输入以下命令编辑该文件:

vi /Users/username/svn/repository/conf/passwd

文件原始内容如下:

### This file is an example password file for svnserve.
### Its format is similar to that of svnserve.conf. As shown in the ### example below it contains one section labelled [users].
### The name and password for each user follow, one account per line.
[users]
# sally = sallyssecret

按照之前记住的用户名和密码进行配置,示例如下:

[users]
username1 = userpassword

配置完成后保存并退出文件。

3. 配置 svnserve.conf 文件

svnserve.conf 文件也在当前目录下。在终端中输入以下命令编辑该文件:

vi /Users/username/svn/repository/conf/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.apache.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 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
[sasl]
### This option specifies whether you want to use the Cyrus SASL ### library for authentication. Default is false.
### This section will be ignored if svnserve is not built with Cyrus ### SASL support; to check, run ‘svnserve –version’ and look for a line ### reading ‘Cyrus SASL authentication is available.’
# use - sasl = true
### These options specify the desired strength of the security layer ### that you want SASL to provide. 0 means no encryption, 1 means ### integrity - checking only, values larger than 1 are correlated
### to the effective key length for encryption (e.g. 128 means 128 - bit ### encryption). The values below are the defaults.
# min - encryption = 0
# max - encryption = 256

需要将以下部分的注释去掉并修改(注意红色部分一定要改过来):

anon - access = read
auth - access = write
password - db = passwd
authz - db = authz

五、启动服务器

在终端中输入以下命令启动 SVN 服务器:

svnserve –d –r /Users/username/svn/repository

若没有任何提示,则说明启动成功。若有提示,一般是已经有启动的 SVN 了,可使用 kill --help 查看如何终止相关进程。

六、项目操作

1. 将项目导入 SVN 库

这一步可能会报错,若报错可查看 authz 文件,需要在最后的用户名 = 密码后加 [/],并且删掉每行最前面的空格。

找到你的项目,记住它的路径 path(可在其目录下使用 pwd 命令查看,filename 即为你的文件名称)。在终端中输入以下命令将项目导入 SVN 库:

svn import path/filename svn://localhost/svn/repository/nameA –username username –m “Initial import”

其中,nameA 是你想要在 SVN 上保存文件库的名字。输入命令后按回车,之后按照提示输入你的密码即可。

2. Checkout 项目

在终端中输入以下命令 Checkout 项目:

svn checkout svn://127.0.0.1/svn/repository/name –username=username –password=password path/name

此处的 path 为你要保存 Checkout 文件的路径,name 为保存的文件夹名。建议创建一个文件夹来保存,否则文件会分散放置,不易查找。

3. Update 项目

更新项目只需在终端中输入以下命令:

svn update path/name

其中,path 为文件路径,name 为文件名。

4. Commit 项目

在终端中输入以下命令 Commit 项目:

svn commit path/name –m “msg”

此处的 msg 为你提交的简要介绍,必须有 -m 且双引号内必须有描述才能提交。

5. 其他命令操作

若想了解更多 SVN 命令操作,可在终端中输入 svn --help 进行查看。总之,多使用 --help 命令有助于掌握更多 SVN 操作。

作者信息

menghao

menghao

共发布了 3994 篇文章