现在的位置: 首页 > 综合 > 正文

SVN安装配置摘要

2014年03月24日 ⁄ 综合 ⁄ 共 12119字 ⁄ 字号 评论关闭

SVN(SubVersion)是新一代版本控制软件,它在CVS的基础上开发,修正了CVS的种种弊端,有望成为开源界CVS的替代品。

(1) 准备工作

可从svn的官方网站http://subversion.tigris.org/下载最新版本的svn。

$ cd ~/build$ wget http://subversion.tigris.org/downloads/subversion-1.3.0.tar.gz$ tar zxvf subversion-1.3.0.tar.gz$ cd subversion-1.3.0$ more INSTALL...I.    BUILD REQUIREMENTS      =====================...1.  Apache Portable Runtime 0.9.7  (http://apr.apache.org/)## svn的发行包已经包含APR和APR-util,如果你不希望用默认的包,你可以在./configure## 中选项--with-apr=和--with-apr-util=指定## 你也可以下载最新的apr和apr-util包,然后存放为./apr和./apr-util,## 这样它就会参与整个编译过程...2.  autoconf 2.50 or newer (Unix only)## 仅在计划编译最新版本的源码才要...3.  libtool 1.4 or newer (Unix only)## 仅在计划编译最新版本的源码才要...4.  Neon library 0.24.7 or 0.25.3  (http://www.webdav.org/neon/)The Neon library allows a Subversion client to interact with remoterepositories over the Internet via a WebDAV based protocol.## 你可以下载Neon-x.x.x,然后存放为./neon,这样它会参与整个编译过程## 你可以指定一个已经编译好的neon,这需要在./configure中指定LDFLAGS变量,## 还需要指定--with-neon=选项,这个选项所指的目录中应该有bin/neon-config程序...5.  Berkeley DB 4.X## 如果不打算使用Berkeley DB做版本库,或者仅仅安装svn客户端,则可不用装## 建议 Berkeley DB 4.3或者4.2## 你可以在./configure中指定位置 --with-berkeley-db=/usr/local/BerkeleyDB.4.3...6.  Apache Web Server 2.0.49 or newer (http://httpd.apache.org/download.cgi)## 用来存取你的subversion仓库## 当然你也可以用svn自己的server:svnserver...6.1 Apache Web Server 2.0.54 or newer (Windows only)          (http://httpd.apache.org/download.cgi)...7.  Python 2.0 (http://www.python.org/)## 主要用作make check,应该可以不要...8.  Visual C++ 6.0 or newer (Windows Only)...9. Perl 5.8 or newer (Windows only)...10. MASM 6 or newer (Windows only, optional)...11. Libraries for our libraries## 主要是一些相关库,比如Neon需要SSL加密,则OpenSSL库必须要有......II.   INSTALLATION      ===============A.  Building from a Tarball or RPM...2.  Building from an RPM...Unpack it, and use the standard GNU procedure to compile:          $ ./configure          $ make          # make install      You can also run the full test suite by running 'make check'....B.  Building the Latest Source under Unix## 如果你已经安装了Subversion,而又想更新到最新版,则看看这个...III.  BUILDING A SUBVERSION SERVER      =============================A.  Setting Up Apache1.  Obtaining and Installing Apache 2.0...$ svn co /        http://svn.apache.org/repos/asf/httpd/httpd/branches/2.0.x httpd-2.0      Checkout the "apr" and "apr-util" modules into the srclib/ directory:      $ cd httpd-2.0/srclib      $ svn co /        http://svn.apache.org/repos/asf/apr/apr/branches/0.9.x apr      $ svn co /        http://svn.apache.org/repos/asf/apr/apr-util/branches/0.9.x apr-util      At the top of the httpd-2.0 tree:          $ ./buildconf          $ ./configure --enable-dav --enable-so --enable-maintainer-mode## 你还可以通过--with-dbm=db4和--with-berkeley-db=/usr/local/BerkeleyDB.4.2## 指定BerkeleyDB的位置## --enable-ssl启用SSL支持##  --enable-deflate启用压缩支持...Compile and install apache:          $ make && make installB.  Making and Installing the Subversion Server## 切换到svn源码目录,可以$ ./configure --with-apxs=...配置Subversion## 当make完后应该可以在Apache的modules目录发现 mod_dav_svn.so...C.  Configuring Apache for Subversion## 确保你的httpd.conf在加载mod_dav.so之后有这么一行:## LoadModule dav_svn_module     modules/mod_dav_svn.so#### 在httpd.conf的底部,配置如下:## ##           DAV svn##           SVNPath /absolute/path/to/repository## #### 为了限制访问,你可以在Location里加上:## AuthType Basic## AuthName "Subversion repository"## AuthUserFile /my/svn/user/passwd/file#### 如果你想让读和写都要验证,可加上 Require valid-user#### 如果仅仅让写要验证,加上##   ##               Require valid-user##   #### 如果要对读和写分开控制,可以加上 ##  AuthGroupFile /my/svn/group/file##  ##      Require group svn_committers##  ##  ##      Require group svn_committers##      Require group svn_readers##  #### mod_dav需要根据域名判断服务器,因此必须配置正确的ServerName。## 如果svn库是在基于名称的虚拟主机中,需要配置ServerAlias#### 如果要指定内容压缩,可配置## SetOutputFilter DEFLATE#### 注意,Apache用户(通常是nobody)必须能读Berkeley DB文件... E.  Alternative:  'svnserve' and ra_svn## 另一种可选的网络层是svn自己的通信协议,客户端是 libsvn_ra_svn,## 服务段是svnserver进程,这种通信没有加密措施。...      $ svnserve -d     # becomes a background daemon      $ svn checkout svn://localhost/usr/local/svn/repository...'svnserve' has built-in CRAM-MD5 authentication (so you canuse non-system accounts), and can also be tunneled over SSH(so you can use existing system accounts). ...

这段文字说明了如何安装svn以及如何配置服务程序。根据这段文字的指示,我们开始我们的svn安装配置之旅吧。

(2) 安装Berkeley DB 4.3.29

$ cd ~/build$ wget http://downloads.sleepycat.com/db-4.3.29.tar.gz$ tar zxvf db-4.3.29.tar.gz$ cd db-4.3.29/build_unix$ ../dist/configure --prefix=/usr/local/BerkeleyDB-4.3.29 --enable-cxx --enable-rpc$ make$ make install$ echo /usr/local/BerkeleyDB-4.3.29/lib >> /etc/ld.so.conf$ ldconfig -v

(3) 安装Apache 2.0.55

$ cd ~/build$ wget http://mirror.vmmatrix.net/apache/httpd/httpd-2.0.55.tar.gz$ tar zxvf httpd-2.0.55.tar.gz$ cd httpd-2.0.55$ CFLAGS="-O2" ./configure --prefix=/usr/local/apache2 /--enable-rewrite=shared --enable-dav=shared --enable-so /--with-dbm=db4 --with-berkeley-db=/usr/local/BerkeleyDB-4.3.29 /--enable-deflate=shared --enable-ssl=shared$ make$ make install

(4) 安装Subversion 1.3.0

$ cd ~/build$ cd subversion-1.3.0$ ./configure --prefix=/usr/local/svn-1.3.0 /--with-apxs=/usr/local/apache2/bin/apxs --with-ssl /--with-berkeley-db=/usr/local/BerkeleyDB-4.3.29 /--with-zlib$ make$ make install$ ln -s /usr/local/svn-1.3.0 /usr/local/svn

为了方便我们使用,我们建立了一个软连接/usr/local/svn。

(5) 配置svnserve

我们先配置svnserve服务方式,过后我们再考虑使用Apache方式实现服务。

首先,给我们的svn服务一个名分。IANA为Subversion协议保留3690端口,你可以加在/etc/services中。

$ vi /etc/services...svn           3690/tcp   # Subversionsvn           3690/udp   # Subversion...

其次,准备你的svn仓库,配置你的svnserve。

 # SVN版本库将放置在/usr/local/repository/svn/test下,仓库类型为BerkeleyDB$ svnadmin create --fs-type bdb /usr/local/repository/svn/test# 建立svn用户运行svn服务$ useradd -s /sbin/nologin -d /dev/null svn$ chown -R svn.svn /usr/local/repository/svn# 建立svnserve的配置文件$ vi /usr/local/repository/svn/test/conf/svnserve.conf[general]password-db = passwdrealm = example realmanon-access = readauth-access = write$ vi /usr/local/repository/svn/test/conf/passwdlarry = foopasswdmarchday=barpasswd

我们编辑svnserve配置文件svnserve.conf,通过CRAM-MD5方式认证用户。用户名和口令对保存在文件passwd中。匿名用户可读,认证用户可写。此外还有一个配置文件authz,可细化权限控制,这里不作改变。

svnserve也可以通过SSH进行认证,这种方式稍后再讲。

svnserve的启动方式有两种选择:配置xinetd(或者inited)或者以独立的进程启动。

对于xinetd启动的方式,你可以建立一个文件 /etc/xinetd.d/svn,内容如下:

service svn{        disable = no        socket_type     = stream        wait            = no        user            = svn        server          = /usr/local/svn/bin/svnserve        server_args     = -i -r /usr/local/repository/svn        log_on_failure  += USERID}

然后运行命令 service xinetd restart 就可以了。
而对于后一种方式,你可以直接通过 -d 参数启动svnserver。

$ /usr/local/svn/bin/svnserver -d -r /usr/local/repository/svn

如果你检查一下网络服务状态,应该可以发现svn端口正被监听。

$ netstat -la...tcp  0  0 *:svn  *:*  LISTEN...

我们做个测试,往版本库里添加项目,看看svnserver是否正常工作。

$ cd /tmp$ mkdir svntest$ cd svntest$ mkdir {trunk,branches,tags}$ svn import . file:///usr/local/repository/svn/test/svntest /--message "first test project"Adding         trunkAdding         branchesAdding         tagsCommitted revision 1.$ svnlook tree /usr/local/repository/svn/test/ svntest/  trunk/  branches/  tags/$ cd ../$ rm -rf svntest$ svn checkout svn://localhost/test/svntestA    svntest/trunkA    svntest/branchesA    svntest/tagsChecked out revision 1.

OK,看来我们的svn已经能正确工作了。

(6) 整合svn和SSH

基本原理:当客户端通过svn命令连接 ssh+ssh://url时,svn客户端打开一个SSH客户进程连接到远程的SSH服务端,接着由远程的SSH服务端以管道模式开启svnserve进程。当SSH会话终止时,svnserve自动退出。

可见,负责网络监听的是sshd,svnserve和普通的程序没什么两样。svnserve的运行身份为当前通过ssh登录的用户身份,所以对于版本库的存取必须要有权限(可把用户加入svn用户组)。

客户端无法缓存口令,因此每次提交修改时都要输入口令,不过这可以通过ssh-agent解决。此外,还有一点比较麻烦,就是控制svnserve
的运行方式比较不便,比如指定-r参数说明版本库的绝对路径。不过这可以通过配置authorized_users文件解决。具体实现请参照svn的文
档,这里不作解释了。

做个试验。我们把xinetd中的svn服务关掉,如果有独立运行的服务svnserver,也请关掉。

$ cp /usr/local/svn/bin/svnserve /usr/bin$ usermod -G svn marchday$ chmod 02775 /usr/local/repository/svn/test/db$ su marchday$ cd /tmp$ svn checkout svn+ssh://localhost/usr/local/repository/svn/test/svntestmarchday@127.0.0.1's password:A    svntest/trunkA    svntest/branchesA    svntest/tagsChecked out revision 1.

首先,我们需要把svnserve拷贝到一个shell能找到的地方,比如/usr/bin。然后修改权限,使marchday对于svn db目录可写。最后,我们访问版本库的时候,要用全路径。

(7) 整合svn和Apache

激动人心的时刻终于到了,我们在这里将要配置一个具有安全保护且易于使用的svn版本控制系统。前提是,上述(2), (3), (4)步的工作必须要做到位了。

首先,修改httpd.conf,确保已经加载了必要的模块。

LoadModule dav_module         modules/mod_dav.soLoadModule dav_svn_module     modules/mod_dav_svn.so

接下来,需要暴露版本库所在的路径。

<Location /svn>  DAV svn  SVNPath /usr/local/repostiroy/svn/test</Location>

如果你有多个版本库可供访问,每个版本库的访问方式如http://my.server.com/svn/test,

http://my.server.com/svn/product1的形式,可做如下配置:

<Location /svn>  DAV svn  SVNParentPath /usr/local/repository/svn</Location>

修改User和Group选项,使其可访问版本库文件。

User svnGroup svn

此外,或许还需要配置ServerName,如果通过NameVirtualHost指示使用Apache的虚拟主机,或许需要ServerAlias来指定额外的名称。这里设置ServerName为127.0.0.1,不通过虚拟主机访问。且监听端口为8080。

如下,我们的webdav已经能work了。先喝口水,高兴一下。:-)

$ /usr/local/apache2/bin/apachectl start$ cd /tmp$ svn checkout http://localhost:8080/svn/test/svntestA    svntest/trunkA    svntest/branchesA    svntest/tagsChecked out revision 1.

下面我们给它加上认证的功能。

首先,加上ssl保护,没有保护的认证同样是很危险的。

生成自签署的证书:

$ cd /usr/local/apache2$ mkdir certs$ cd certs$ openssl genrsa -des3 -out ca.key 1024 # 生成根证书的私钥匙$ openssl req -new -x509 -days 365 -key ca.key -out ca.crt # 生成根证书$ openssl genrsa -des3 -out server.key 1024 # 生成服务器的私钥匙$ openssl req -new -key server.key -out server.csr  # 生成服务器的请求签证文件 $ ../bin/sign.sh server.csr # 签署服务器证书,结果生成server.crt文件

其中脚本sign.sh是从mod_ssl源码目录pkg.distrib下拿来的,它简化了证书签署步骤。如果你想建立自己的认证体系,可参考我的另一篇关于OpenSSL的文章。

配置conf/ssl.conf,启用SSL支持。

SSLCertificateFile /sinaad/apache2/certs/server.crtSSLCertificateKeyFile /sinaad/apache2/certs/server.key

然后启动apache。

$ /usr/local/apache2/bin/apachectl startssl

现在,应该可以通过https访问你的站点了。

有一个比较烦的地方是每次apachectl startssl都要求输入server.key的口令,你可以通过下面的方法去掉口令输入:

$ cp server.key server.key.org$ openssl rsa -in server.key.org -out server.key$ chmod 400 server.key

现在,给apache加上基本认证功能。

$ cd /usr/local/apache2/conf$ htpasswd -cm svnusers harryNew password: ***** Re-type new password: *****Adding password for user harry$ htpasswd -m /etc/svn-auth-file sallyNew password: *******Re-type new password: *******Adding password for user sally

口令文件svnusers创建后,再修改httpd.conf和ssl.conf。我们把以下段落从httpd.conf移动到ssl.conf的里面。

<Location /svn>  DAV svn  SVNParentPath /usr/local/repository/svn</Location>

然后加上基本认证配置,最终结果如下:

<Location /svn>  DAV svn  SVNParentPath /usr/local/repository/svn  AuthType Basic  AuthName "Subversion repository"  AuthUserFile conf/svnusers  Require valid-user</Location>

我们的安全有了初步的保障,至少密码不会以明文的形式在网络上传输了,很简单吧。美中不足的是权限控制的精度不够,如果你想精确控制访问,就得继续下面的步骤了。

首先,我们需要一个权限控制文件,比如下面这样子:

$ cd /usr/local/apache2/conf$ vi svnauthz[test:/svntest]harry = rw* = r

这里我们允许harry可读写test版本库的svntest项目,其他人(包括匿名用户)只能读。
然后修改httpd.conf,启用authz_svn_module,这个模块在编译subversion的时候就生成了。现在我们的httpd.conf如下面这样:

...LoadModule dav_module modules/mod_dav.soLoadModule rewrite_module modules/mod_rewrite.soLoadModule dav_svn_module     modules/mod_dav_svn.soLoadModule authz_svn_module   modules/mod_authz_svn.so...

修改ssl.conf,改成下面这样子:

<Location /svn>  DAV svn  SVNParentPath /usr/local/repository/svn  AuthzSVNAccessFile conf/svnauthz  # try anonymous access first, resort to real   # authentication if necessary.  Satisfy Any  Require valid-user  AuthType Basic  AuthName "Subversion repository"  AuthUserFile conf/svnusers  Require valid-user</Location>

Satisfy Any配置指明任何用户都可以访问,Require valid-user指明在必要的情况下才需要认证用户,其实这相当于把判断
权交给了authz_svn_module。关于Apache如何和模块进行用户认证信息交换,可参考O'Reilly的大作
《Writing Apache Modules with Perl and C》。现在,权限控制的功能已经非常强大了。

(8) WebDAV和自动化(auto versioning)

WebDAV的规范为RFC 2518,基本目标在于把Web变成一个读写的媒体。它没有版本控制,有版本控制的规范为RFC 3253,即DeltaV,不过很少有厂商实现它。

mod_dav_svn是对DeltaV的一种模拟,没有完全符合DeltaV的规范。它的身份是充当mod_dav请求的具体文件操作,带来的一个令人激动的特性就是自动版本化(auto versioning):当新版本提交的时候,自动升级版本号码。

svn 1.2的文档说为了开启auto versioning,必须在Apache配置项中设置 SVNAutoversioning on,同
时在钩子脚本中要防止某些客户端提交文件长度为0的请求。我安装的是svn 1.3,好像SVNAutoversioning默认就设置为on,而且能有
效避免重复提交的问题(第一次PUT长度为0的文件体,紧接着PUT是真正的文件),已经在网络邻居、Dreamweaver、
Microsoft Office 2000中测试过。其间遇到过一次Berkeley DB被锁的情况,运行下面的命令就解决了。

$ /usr/local/apache2/bin/apachectl stop$ svnadmin recover /usr/local/repository/svn/test$ chown -R svn.svn /usr/local/repository/svn/test$ /usr/local/apache2/bin/apachectl startssl

我们的svn配置旅程告一段落,如果你意犹未尽的话,就继续钻钻别的资料吧。

【上篇】
【下篇】

抱歉!评论已关闭.