svn工作原理以及服务搭建和配置

来源:互联网 发布:ai软件好学吗 编辑:程序博客网 时间:2024/06/06 03:25
 

一·初步引入认识svn

如果一个项目是由多个开发人员共同开发的,但是这些个开发人员都不在个地方,那么如何来完成这个项目的开发呢?这个时候我们需要一款专门用于项目开发管理的软件了,可是如何解决开发过程中同步问题.安全问题以及管理问题呢?

subversion(简称svn)是今年崛起的版本管理软件,是cvs的接班人,目前绝大多数开源软件都使用svn作为代码版本管理软件

Subversion支持linux和windows,但较多安装在linux下

svn服务器有两种运行方式:独立服务器和借助于apache。 svn://    http://

svn客户端tortoisesvn

svn的基本工作思路: 在一台服务器上建立一个源代码库,库里可以存放许多不同项目的源程序。有源代码库管理员

                    统一管理这些源程序。每个用户在使用源代码库之前,首先要把源代码库里德项目文件下载到

                    本地,然后开发人员可以在本地修改,左后用svn命令进行提交,游源代码库统一管理修改。

版本控制解决了:

               *代码管理混乱

               *解决代码冲突困难

               *在代码整合期间引发bug

               *无法对代码的拥有者进行权限控制

               *项目不同版本的发布困难


配置subversion

*dav目录:是提供apache与mod_dav_svn使用的目录,让他们存储内部数据

*db目录:就是所有版本控制的数据存放文件

*hooks目录:放置hook脚本文件的目录

*locks目录:用来放置subversion见艰苦锁定数据的目录,用来追踪存取文件库的客户端

*format文件:是一个文本文件,里面只放了一个整数。表示当前文件库配置的版本号

*conf目录:是这个仓库的配置文件(仓库的用户访问账号.权限等)

SVN安装

1、所需软件包

httpd-2.2.4

apr-1.3.8.tar.gz、apr-util-1.3.9.tar.gz

sqlite-amalgamation-3.6.17.tar.gz

subversion-1.6.5.tar.bz2

expat-1.95.7-4、expat-devel-1.95.7-4

客户端:TortoiseSVN-1.6.5.16974-win32-svn-1.6.5.msi

2、安装SVN

安装apache

# ./configure --prefix=/usr/local/apache2

 --enable-dav 

--enable-so 

--enable-modules=most

//注:编译apache时要加上--enable-dav选项

# make

# make install

 

安装apr、apr-util

# tar -zxvf apr-1.3.8.tar.gz -C /usr/src

# cd /usr/src/apr-1.3.8

# ./buildconf     //验证系统是否有python、autoconf、libtool

# ./configure --prefix=/usr/local/apr

# make

# make install

 

# tar -zxvf apr-util-1.3.9.tar.gz -C /usr/src

# cd /usr/src/apr-util

# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

# make

# make install

 

安装sqlite

#./configure --prefix=/usr/local/sqlite

# make 

# make install

 

安装svn

# tar -jxvf subversion-1.6.5.tar.bz2 -C /usr/src

# cd /usr/src/subversion-1.6.5/

# ./configure --prefix=/usr/local/svn   --with-apxs=/usr/local/apache2/bin/apxs                          

 --with-apr=/usr/local/apr     

 --with-apr-util=/usr/local/apr-util

 --with-sqlite=/usr/local/sqlite/   --with-ssl   --with-zlib打开zlib库支持

--enable-maintainer-mode  打开调试和编译时警告,仅供开发人员使用

# make

# make install

 

 

修改APache配置文件

#vi /usr/local/apache/conf/httpd.conf

User www           修改apache默认启用用户为www

Group www

找到DocumentRoot “/usr/loca/apache/htdocs” 和</Directory “/usr/local/apache/htdocs”> 修改apache的主页到/WWW下

DocumentRoot “/www”

<Directory “/www”>

配置apache中svn认证

<Location /svn>                 //设置url,代表要访问的仓库的父目录

   DAV svn

   SVNParentPath /data/svn       //svn根目录

   AuthType Basic          

   AuthName "SVN Test"

   AuthzSVNAccessFile /data/svn/authz.conf //svn认证文件,创建一个authz.conf文件

   AuthUserFile /data/svn/authfile   //apache认证文件

   Require valid-user

</Location>

启动apache

/usr/local/apache/bin/apachectl start

创建svn项目仓库

# mkdir /data/svn                创建svn库

# svnadmin create /data/svn/drug  //创建项目仓库drug

# /usr/local/svn/bin/svn import /www/drug file:///data/svn/drug -m "initial import"  将/www/drug导入到svn库下

注:在导入仓库后,原来的目录树并没有转化成一个工作副本,需要使用checkout手动导出一个工作副本。

#chown –R www:www /data/svn/drug

#svn checkout file:///data/svn/drug /www/drug_new

   修改目录的属主为www

#chown –R www:www /www/drug_new

#chmod –R 700 /data/svn/

编写svn与apache同步脚本

#vi /data/svn/drug/hooks/post_commit

#!/bin/sh

export LC_CTYPE=zh_CN.GB18030  语言支持

SVN=/usr/local/svn/bin/svn         指定svn路径

WEB=/www/drug                 指定apache虚拟主机路径

$SVN update $WEB –username www –password xywyxywy

赋予脚本执行权限

#chmod 700 post-commit

#chown www:www post-commit

创建apache认证用户

# /usr/local/apache2/bin/htpasswd -(c)m /data/svn/authfile sum

输入密码:sum123

# /usr/local/apache/bin/htpasswd /data/svn/authfile wyj

//再添加一个用户

Svn权限配置文件

# vi /data/svndata/authz.conf

[drug:/] //表示仓库drug根目录

sum = rw //用户sum对drug库有读写权限

wyj = r //用户wyj对drug库有读写权限

[/]

* = r //这个表示对所有的用户都具有读权限

[groups]        //这个表示群组设置

developers = sum, wyj //developers组中的用户

[pro1:/]

@svn1-developers = rw  //对这个组有读写权限

 

 

 

启动svn服务

svnserver -d -r /data/svndata

设置svn和apache服务开机自动启用

#vi /etc/rc.local   

/usr/local/apache/bin/apachectl start

svnserve –d –r /data/svn

SVN管理命令1svn命令

导入数据到版本库

# svnadmin create /data/svndata/pro1

# svn import /www/shop file:///data/svndata/pro1 -m import

查看版本库下的内容

# svn list file:///data/svndata/pro1

注:在导入仓库后,原来的目录树并没有转化成一个工作副本,需要使用checkout手动导出一个工作副本。

 

从版本库导出数据

# svn checkout file:///data/svndata/pro1

取出任意深度的数据

# svn checkout file:///data/svndata/pro1/ad/html

将数据放到新目录

svn checkout file:///data/svndata/pro1 testweb

//pro1工作副本放到testweb中,而不是默认生成的pro1目录

svn co file:///data/svn/my_xywy_com/ /www/other/my.xywy.com

// 导出my_xywy_com全部文件,到/www/other/my.xywy.com

它可以显示工作副本中的所有项目

svn status -u -v

 

18       16 sum          fff.txt

18        1 root          index2.php

18       10 sum          index20090416.html

18       17 sum          111/fff.txt

18       17 sum          111/index2.php

18       17 sum          111/index20090416.html

18       17 sum          111/index.jsp

 

2svnlook命令

查看当前的版本仓库内容

# svnlook info 版本仓库

 

Sum//作者

2009-09-10 11:51:17 +0800 (Thu, 10 Sep 2009)//提交时间

0//最后一次提交参数信息

 

查看最近一次更新的修订号

# svnlook youngest 版本仓库

 

显示一个版本仓库中文件和目录的树形结构图

svnlook tree /data/svndata/pro2/ --show-ids

 

jytk.html <0-1.0.r1/232049>

 gallery.php <3-1.0.r1/232223>

 gywm.html <5-1.0.r1/232402>

 database.php <7-1.0.r1/232579>

lxyp.html <b-1.0.r1/232979>

 

查看仓库中某一个文件内容

# svnlook cat /data/svndata/pro2/ index.html   //查看pro2项目的index.html文件中的内容

 

显示被修改的文件

svnlook diff /data/svndata/pro2/

 

Added: 11.txt //显示增加了11.txt文件

3导出svn版本库中的文件夹

若要彻底删除SVN版本库某文件夹,可以使用下面的方法。

查看项目sumitest中的列表

svn list file:///data/svn/sumitest

 

fxywy/

fxywy/src

jxywy/

jxywy/src

src/

要把fxywy/src文件夹删除,重新导入到新的项目sumitest2中,方法如下:

svnadmin dump /data/svn/sumitest > sumi1.dump

// 导出sumitest整个项目到sumi1.dump

cat sumi1.dump | /usr/local/svn/bin/svndumpfilter exclude /fxywy/src > sumi2.dump

// sumi1.dump过滤出/fxywy/src目录。Windowscat换成type

svnadmin create /data/svn/sumitest2

// 创建新的项目库

svnadmin load /data/svn/sumitest2 < sumi2.dump

//导出/fxywy/src 到sumitest2

4删除svn版本库中的文件夹

svn delete 可以从工作拷贝或版本库删除一个项目。

svn delete -m Deleting filefile:///data/svn/sumitest2/fxywy/

// 删除sumitest2下的/fxywy目录