subversion1.6的安装与使用

简介:

出自:http://blog.csdn.net/yihui8/archive/2010/06/17/5676532.aspx

首先来一张subversion的架构图 
 
1.subversion的安装主要是要解决信赖的类库: 
1).libapr, libapr-util(apache portable runtime) layer that allows   suberversion client and server to run on different OS. 
2).zlib(libz) 
3).libneon or libserf (option for client to send http request) 
4).openssl (option for client and server) 
5).lexpat xml parser 
6).sqlite3 v-amalgamation

2.访问subversion repository 
从subversion的架构图我们可以看出,访问subversion repository(我们的数据所在地,也叫版本库), 可以有三种方式, 
1).第一种是如果客户端跟服务器的repository都在同一server下, 
    使用的协议是file:/// 
    如: svn import . file:///c:/rep/hello -m '' 
        svn list file:///home/rep/hello

2).第二种,也是比较多人使用的,采用的svn://协议,服务器端启动svnserve这个程序,通过它访问repository, 
如 svn import . svn://123.44.21.34/hello -m ''

3).第三种是通过apache这个http服务器访问repository,协议当然就是http://了

3.建立repository资源库 
从上面又可以看出,首先我们得先建立我们的repository,这样才能使用以上三种方式访问,这个repository是我们的关健资源库,所有的操作最后都是反映到这里来的. 
首先建立这个repository 
#svnadmin create /path/to/repository 
这样在/path/to/repository下就会生成几个关健的文件夹: 
比如conf, db,除了conf可以修改,其他文件,文件夹都不能随便修改删除等 
conf下有svnserve.conf, authz, passwd这三个文件 
这个文件夹下的配置文件是配置svnserve服务器的,跟其他另外两种访问方式无关. 
svnserve.conf主要配置[general]下的东东, 
比如 anon-access=none,auth-access=write 可以使匿名用户不能访问,而已验证的用户可以进行读写操作. 
验证用户可以在 password-db = passwd说明, 
这样在conf/passwd文件中定义的用户都是svnserve的用户. 
在conf/passwd文件中定义用户很简单: 在[users]下一个用户一行, 
格式 username = password(明文)

每个用户又有可能有不同的访问资源权限,比如小王不能访问buyshop这个项目的资源,而其他可以 
在svnserve.conf 中的[general]注释掉authz-db = authz 
这样conf/authz文件中定义的权限就会被应用. 
具体实例参照authz文件本身,它有詳細说明


4.启动svnserve 
repository(版本库)建好了,svnserve配置文件修改好了, 
现在是启动svnserve服务器的时候了 
#svnserve -d -r /path/to/repository 
这样就在后台启动了,从-r可以看出我们可以有不同的版本库,可以按需使用

5.subversion的命令 
subversion系统自带的工具有服务器端的如svnadmin,svnserve, 
也有客户端的如使用最多的svn 命令,svn下面还有很多子命令

6.上传项目 
现在应该将我们的项目上传到subversion的repository供他们管理 
项目的结构可以考虑trunk,branches,tags 
#svn import . svn://server-ip/hello -m 'initial' 
这样就将当前目录下的所有文件,文件夹上传到repository下的hello文件夹中

当我们需要使用由svn版本控制的项目文件,必须checkout到本地 
#svn checkout svn://serveer-ip/hello/trunk hello 
这样就将hello项目主线的文件下载到当前目录下的hello文件夹中

7.客户端操作 
当我们checkout出项目之后,进入到项目文件夹中,这个例子是当前目录下的hello文件夹 
#cd hello 
我们可以离线操作本地项目文件,修改,增加,删除等等. 
当确定修改完成,需要保留这些信息时,这才使用svn commit -m ''命令去跟服务器联系说我修改了哪些文件,给我这些改动状态一个版本号. 
客户端commit一次,就将版本号加1,最开始import 时版本号为1

当我们完成一个项目或其他原因想将项目拿出来而不带版本信息,这时可用 
#svn export svn://server-ip/hello/trunk hello_2 
或可以指定版本号,默认是最新版本号 如 -r 1234

8.当上传eclipse项目工程到subversion中时,必须加上.project .classpath文件,再加上.settings文件夹

9.暂时就写这么多,具体还有很多命令可以慢慢学习使用

10.relocate 
subversion的库是可复制的, 当要将库移到另外的机器上, 需要relocate 
cd到项目目录下 
#svn switch --relocate FROM TO 
如# svn switch --relocate svn://192.168.1.112/bidaround/trunk svn://192.168.1.223/bidaround/trunk
Linux下配置SUBVERSION SVN
apache源代码压缩包 httpd-2.2.9.tar.bz2 svn源代码压缩包 subversion-deps-1.5.0.tar.bz2 subversion-1.5.0.tar.gz

安装apache 解压httpd-2.2.9.tar.bz2,进入解压后的文件夹,执行configure,命令如下 ./configure --enable-dav --enable-so --prefix=/opt/apache2, 其中,--enable-dav允许Apache提供DAV协议支持;--enable-so允许运行时加载DSO模块,前两个参数是必须要加的,--prefix 是安装的位置如果configure通过,接着执行 make && make install ,数分钟后就完事了,通过 /opt/apache2/bin/apachectl -k start 来启动,在浏览器中访问127.0.0.1,如果出现 It's Works!,那么说明安装成功。

安装subversion 分别解压subversion-deps-1.5.0.tar.bz2和subversion-1.5.0.tar.gz,解压后他们都在subversion-1.5.0这个文件夹下,然后执行configure,命令如下 ./configure --with-apxs=/opt/apache2/bin/apxs --with-apr=/opt/apache2 --with-apr-util=/opt/apache2 --prefix=/opt/subversion-1.5.0 其中,--with-apxs 用于生成apache httpd的mod_dav_svn和mod_authz_svn模块;--with-apr 和 --with-apr-util=参数指向 Apache 的安装根目录,而不是使用缺省的 SVN 安装包中自带的 apr ,否则如果你安装的 Apache 版本不同有可能导致 APR 库不匹配,出现类似 Can't set position pointer in file '/svn/test/db/revs/1': Invalid argument 的错误,--prefix 是安装的位置。注意,在configure的时候可能回出现 configure: error: no XML parser was found: expat or libxml 2.x required和configure: error: We require OpenSSL; try --with-openssl这两个错误分别通过下面的apt-get来安装确实的库, apt-get install libxml2 libxml2-dev  expat apt-get install openSSL libssl-dev 也可以在configure前先检查一下本地是否已经存在上述所需要的lib,dpkg -l | grep libxml2和dpkg -l | grep openssl configure通过后进行make,似乎在make的时候会出现一个Error,信息如下 /usr/bin/ld: cannot find -lexpat,好像找不到libexpat.so这个库文件,但是/usr/lib下有/usr/lib/libexpat.so.1,于是做了一个link,命令如下 ln -s  /usr/lib/libexpat.so.1 /usr/lib/libexpat.so 再执行make,就通过了,使用make install安装。

创建的Subversion的版本库假设我们把版本库建立在/opt/svnroot 目录下,那么在/opt/svnroot目录下执行mkdir repository新建版本库文件夹,通过svnadmin create repository/test命令可创建名为test的版本库。若创建成功,则subversion的安装便已成功完成。使用mkdir –p import/{trunk,branches,tags} 命令在/opt/svnroot目录下建立一个名为import的新文件夹,包含trunk、branches、tags 三个子目录。下面这条语句将把路径/opt/svnroot/import下的目录和文件导入到你创建的Subversion 仓库中去,提交后的修订版为1。 svn import /opt/svnroot/import file:///opt/svnroot/repository/test –m "Init repository" 这里/opt/svnroot/import可以使用相对路径,但file:///opt/svnroot/repository/test必须以绝对路径表示。

使用htpasswd 生成身份认证文件,具体命令如下: htpasswd -m  -c /opt/svnroot/repository/pwdfile user1 (-c 是生成pwdfile文件,如果文件存在就不用带 -c 参数) htpasswd -m  /opt/svnroot/repository/pwdfile user2 htpasswd -m  /opt/svnroot/repository/pwdfile user3 这样就创建了3个用户

创建授权文件授权文件用于确定每个用户对特定目录的操作权限,格式可参考版本库下的conf/authz(conf目录下的authz文件用于svnserve的授权,与我们所使用的mod_authz_svn的授权文件具有相同的格式)。因而我们可以直接把conf下的authz复制到我们想要的/opt/svnroot/repository目录下,然后加以修改。修改后的文件大概是如下: [groups] g_pm=user1 g_dev=user2 g_dev=user3

[test:/] @g_pm=rw @g_dev=r

[test:/trunk] @g_pm=rw @g_dev=r

[test:/branches] @g_pm=rw @g_dev=rw

[test:/tags] @g_pm=rw @g_dev=rw

修改目录的owner及权限 chown -R apache:apache /opt/svnroot chmod 700 /opt/svnroot chmod -R 700 /opt/svnroot/repository

修改apache的httpd.conf文件修改User和Group都为apache

在文件的最后加上 <location /svn>         DAV svn         SVNParentPath /opt/svnroot/repository/         AuthType Basic         AuthName "Subversion Repository"         AuthUserFile /opt/svnroot/repository/pwdfile         AuthzSVNAccessFile /opt/svnroot/repository/authz         Satisfy Any         Require valid-user </Location> 其中/svn表示一个url的模式,匹配形如http://host/svn的url;SVNParentPath 指定的目录下的所有项目都被subversion 认为是合法的版本库;AuthzSVNAccessFile为授权文件 ;AuthType 则制定了客户端身份认证机制,Basic表示http基本认证机制;AuthUserFile就是先前创建的密码文件;Satisfy Any 和Require valid-user告诉apache所有用户先使用匿名方式访问版本库,只有当访问控制策略要求一个真实的用户名时,apache才会对客户端进行身份验证,这是使用得最多的一种授权方式。

至此,subverion加apache2 安装配置就完成了!


一.安装apr跟apr-util 
1.下载apr跟apr-util 
apr-1.3.3.tar.gz   apr-util-1.3.4.tar.gz 
2.解压 
  tar zvxf apr-1.3.3.tar.gz 
  tar zvxf apr-util-1.3.4.tar.gz 
3.安装 
  cd apr-1.3.3 
  ./configure --prefix=/usr/local/apr 
  make && make install

  cd apr-util-1.3.4 
  ./configure  --with-apr=/usr/local/apr 
  Make && make install

二.安装apache服务器: 
1. 下载最新的apache 2.2.9 
    httpd-2.2.9.tar.gz 
2.解压 
tar zvxf htt-2.2.9.tar.gz 
3. 安装 
  ./configure \ 
“--prefix=/usr/local/apache2” \ 
“ --enable-so” \ 
“--enable-dav” \ 
“--with-apr=/usr/local/apr/bin/apr-1-config” \ 
“--with-apr-util=/usr/local/apr/bin/apu-1-config” 
  make 
  make install

注意:--prefix指定安装目录,注意一定要加--enable-so是核心能够装载DSO和--enable-dav是安装mod_dav_svn.so跟mod_authz_svn.so这两个模块 
4.测试 
  打开浏览器输入http://服务器ip  如果出现 
   It Works! 
  Apache安装成功 
三. 安装subversion 
1. 下载最新的subversion-1.5.2 
subversion-1.5.2.tar.gz 
2. 安装 
  ./configure \ 
“--prefix=/usr/local/subversion” \ 
“ --with-apxs=/usr/local/apache2/bin/apxs” \ 
“--with-apr=/usr/local/apr/bin/apr-1-config” \ 
“--with-apr-util=/usr/local/apr/bin/apu-1-config” \ 
“--with-ssl” \ 
“--with-zlib” \ 
“--enable-maintainer-mode” 
make 
make install

3. 为了方便使用subversion的命令,将subversion安装目录下的bin目录加入到Path中

四. 配置subversion 
1.        创建账号密码文件 
htpasswd –c /data/svn/passwd.conf apache 
   输入密码,两次确认 
  注意:第一次设置用户密码要加入 –c 这个参数 
2.        创建资料库 
首先要创建一个资料库(我使用单资料库的方式),使用svnadmin增加资料库 
cd /usr/local/subversion/bin 
     ./svnadmin create /data/svn/svnroot 
到svnroot下看是不是多了文件,多了就是说明创建成功 
五. 配置apache的httpd.conf 
打开apache的conf/httpd.conf,安装subversion后,apache的conf/httpd.conf文件会自动增加了模块 
LoadModule dav_svn_module     modules/mod_dav_svn.so 
LoadModule authz_svn_module   modules/mod_authz_svn.so

相应的so文件也自动copy到了apache/modules。这些工作就不用自己动手了。

需要自己动手修改apache下的httpd.conf最后增加以下内容 
<Location /svn> 
DAV svn 
SVNPath /data/svn/svnroot #版本库的目录 
AuthType Basic 
AuthName "Subversion repository" #欢迎语言 
AuthUserFile /data/svn/passwd.conf  #密码文件 
Require valid-user 
</Location>

注意: 
(1)        SVNPath一定要跟./svnadmin create /data/svn/svnroot的目录一样,要不晕死你 
(2)        目录svnroot的权限设置成755 
   
六. 验证安装 
打开浏览器,输入地址为http://服务器ip/svn 
出现登陆窗口,输入用户名跟密码, 见图一

如果可以正常打开如上页面则说明安装配置正常,可以正常使用了,在页面上可以看到由于目前资料库中没有内容,因此看到的内容为空。

七.导入数据到资料库 
Cd /usr/local/subversion/bin 
./svn import /要导入的目录 file:///data/svn/svnroot -m “说明文字” 
重新打开浏览器,输入地址http://服务器ip/svn,输入用户名密码,出现

好了,成功! 
附:安装过程中遇到的问题 
1.        编译subversion时出现少expat库 
解决:下载expat-2.0.0.tar.gz安装皆可 
2.        安装subversion时,编译到最后会出现一段 
configure: WARNING: we have configured without BDB filesystem support 
大概是不能创建db格式的版本库 
解决:这个没什么关系,一般不会有多大影响 
3.        安装subversion时,make没问题,make install时出现 
/usr/local/src/subversion-1.5.2/subversion/svnversion/.libs/lt-svnversion: error while loading shared libraries: libexpat.so.1: cannot open shared object file: No such file or directory 
意思是找不到libexpat.so.1这个文件 
运行 whereis libexpat.so.1 
libexpat.so: /lib/libexpat.so.0 /usr/local/lib/libexpat.so /usr/local/lib/libexpat.so.1 
解决:vi  /etc/ld.so.conf 
加入libexpat.so.1的目录 /usr/local/lib/ 保存退出 
运行ldconfig 
4.        安装好了后,浏览器打开http://服务器ip/svn,登陆出现不了页面,出现: 
<D:error> <C:error/> <m:human-readable errcode="2"> Could not open the requested SVN filesystem </m:human-readable> </D:error> 
解决:这是httpd.conf里的<Locate svn>中的SVNPath指向错误没指到创建的资料库 
     第四步的最后我强调的东西 
5.        这是开始安装时会出现的错误,安装subversion时会出现找不到arp的问题 
解决:在编译subversion时加入 
     --with-apr=/usr/local/apr/bin/apr-1-config 
--with-apr-util=/usr/local/apr/bin/apu-1-config

 


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/yihui8/archive/2010/06/17/5676532.aspx


本文转自holy2009 51CTO博客,原文链接:http://blog.51cto.com/holy2010/442612


相关文章
|
网络协议 Ubuntu Linux
|
网络协议 Ubuntu Linux
|
Java 数据安全/隐私保护 开发工具
|
存储 监控 网络安全
|
Linux 网络安全 Apache
|
存储 Windows 数据安全/隐私保护
|
Android开发 数据安全/隐私保护

相关实验场景

更多