您的位置:首页 > 运维架构 > Linux

SVN服务的搭建和配置

2013-06-13 13:50 106 查看
先对svn(subversion)做个简单的介绍:运行方式独立服务器(例如:svn://xxx.com/xxx);借助apache (例如:http://svn.xxx.com/xxx);数据存储svn存储版本数据也有2种方式:BDB(一种事务安全型表类型)和FSFS(一种不需要数据库的存储系统)。因为BDB方式在服务器中断时,有可能锁住数据,所以还是FSFS方式更安全一点更详细的介绍(工作原理等)请点击http://baike.baidu.com/view/183128.htm我采用的是独立服务器的搭建,步骤如下:环境:centos5.6系统1.下载subversion -1.6.21.tar.gz和subversion-deps-1.6.21.tar.gz,要是相同的版本,否则安装过程中会报错(下载的软件都在/root/soft目录下)
[root@server ~]# cd/root/soft
[root@server soft]# ls
[root@server soft]# tar xfvz subversion-1.6.21.tar.gz
[root@server soft]# tar xfvz subversion-deps-1.6.21.tar.gz
[root@server soft]# cd subversion-1.6.21
[root@server subversion-1.6.21]#

2.编译svn
首先检测系统有没有安装SSL:
[root@serversubversion-1.6.21]# find / -name opensslv.h
[root@server subversion-1.6.21]#
找不到,就执行如下命令进行安装:(安装过程中若提示少依赖包,就使用yum安装或下载安装)
[root@serversubversion-1.6.21]# yum install openssl
[root@server subversion-1.6.21]# yum install openssl-devel
安装之后用find / -name opensslv.h命令找到opensslv.h所在的目录,即下列--with-openssl=后面的路径,编译:
[root@server subversion-1.6.21]# find / -name opensslv.h
/usr/include/openssl/opensslv.h
/root/soft/mysql-5.5.24/extra/yassl/include/openssl/opensslv.h
[root@server subversion-1.6.21]# ./configure --prefix=/usr/local/svn --with-openssl=/usr/include/openssl--without-berkeley-db
注:以svnserve方式运行,不加apache编译参数。以fsfs格式存储版本库,不编译berkeley-db。
此时编译报如下错误:
configure: WARNING: unrecognized options: --with-openssl
configure: Configuring Subversion 1.6.6
configure: creating config.nice
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/local/src/subversion-1.6.6':
configure: error: no acceptable Ccompiler found in $PATH
See `config.log' for more details.
说明没有安装gcc相关库,使用如下命令安装gcc后再编译:
[root@server subversion-1.6.21]# yum -y install gcc
[root@server subversion-1.6.21]# ./configure --prefix=/usr/local/svn--with-openssl=/usr/include/openssl --without-berkeley-db
最后出现下面WARNING,直接忽略即可,因为不使用BDB存储。configure: WARNING: we have configured without BDB filesystem support
You don't seem to have Berkeley DB version 4.0.14 or newer
installed and linked to APR-UTIL. We have created Makefiles which
will build without the Berkeley DB back-end; your repositories will
use FSFS as the default back-end. You can find the latest version of
Berkeley DB here: http://www.sleepycat.com/download/index.shtml
3.安装SVN
为避免出现以下错误
error while loading shared libraries: libiconv.so.2:cannot open shared object file: No such file or directory
先执行以下操作:
1)、编辑/etc/ld.so.conf文件,添加下面一行:
/usr/local/lib
2)、保存后运行ldconfig:
/sbin/ldconfig
注:ld.so.conf和ldconfig用于维护系统动态链接库。
安装
[root@server subversion-1.6.21]# make && make install
安装完成后执行以下命令测试:
[root@serversubversion-1.6.21]# /usr/local/svn/bin/svnserve --version
svnserve, version1.6.21 (r1462351)
compiled Jun9 2013, 14:25:58
Copyright (C)2000-2009 CollabNet.
Subversion is opensource software, see http://subversion.apache.org/ This productincludes software developed by CollabNet (http://www.Collab.Net/).
The followingrepository back-end (FS) modules are available:
* fs_fs : Modulefor working with a plain file (FSFS) repository.
为了方便下操作,下面将SVN的BIN添加到PATH,编辑/etc/profile,添加:
PATH=/usr/local/svn/bin:$PATH
保存后,使其立即生效:
source /etc/profile

4.配置SVN
建立版本库目录,可建多个:
[root@server ~]# mkdir -p /home/svndata/test #建立版本库
[root@server ~]# /usr/local/svn/bin/svnadmin create /home/svndata/test #修改版本库配置文件
编辑/home/svndata/test/conf/svnserve.conf,内容修改为:(注意:前面的注释符号和空格都要去掉,不然在连接时无法识别会报错
[general]
anon-access = none
auth-access = write
password-db = /usr/local/svn/conf/passwd.conf
authz-db = /usr/local/svn/conf/authz.conf
realm = test
注意:对用户配置文件的修改立即生效,不必重启svn。
在/usr/local/svn/下面新建conf目录,并在/usr/local/svn/conf内新建passwd.conf和authz.conf文件:
mkdir conf
cd conf/
touch passwd.conf
touch authz.conf
添加用户及密码:
[root@server ~]#useradd user
[root@server ~]# passwd user
编辑/usr/local/svn/conf/passwd.conf,添加如下代码并保存
[users]
user = pwd123!@#
配置svn用户访问权限,编辑usr/local/svn/conf/authz.conf,添加如下代码并保存:
[groups]
admin=user
[/]@admin = rw
[test:/]
@admin = rw
注意:
* 权限配置文件中出现的用户名必须已在用户配置文件中定义。
* 对权限配置文件的修改立即生效,不必重启svn。
用户组格式:
[groups]
= ,
其中,1个用户组可以包含1个或多个用户,用户间以逗号分隔。
版本库目录格式:
[<版本库>:/项目/目录]
@<用户组名> = <权限>
<用户名> = <权限>
其中,方框号内部分可以有多种写法:
[/],表示根目录及以下,根目录是svnserve启动时指定的,我们指定为/home/svndata,[/]就是表示对全部版本库设置权限。
[repos:/] 表示对版本库repos设置权限;
[repos:/abc] 表示对版本库repos中的abc项目设置权限;
[repos:/abc/aaa] 表示对版本库repos中的abc项目的aaa目录设置权限;
权限主体可以是用户组、用户或*,用户组在前面加@,*表示全部用户。
权限可以是w、r、wr和空,空表示没有任何权限。

5.启动svn
建立启动svn的用户:
[root@server ~]#useradd svn
[root@server ~]# passwd svn
允许用户svn访问版本库:
[root@server ~]#chown -R svn:svn /home/svndata
启动svn:[root@server ~]# su - svn -c "svnserve -d --listen-port 9999 -r /home/svndata"
其中:
su - svn :表示以用户svn的身份启动svn;
-d :表示以daemon方式(后台运行)运行;
--listen-port 9999 :表示使用9999端口,可以换成你需要的端口。但注意,使用1024以下的端口需要root权限;
-r /home/svndata :指定根目录是/home/svndata。

编辑/etc/rc.d/rc.local文件,加入如下启动命令:/usr/local/svn/bin/svnserve -d --listen-port9999 -r /home/svndata
如果想停止svn,则使用如下命令:
killall svnserve
查看是否启动:
[root@server~]#ps –ef| grep svn

6.连接SVN
安装TortoiseSVN,重启系统。
在资源管理器中空白处右键会出现SVNCheckout,则证明安装成功了
启动TortoiseSVN(右击选择SVN Checkout)并在地址栏中输入svn://ip:9999/test
根据提示输入用户名与密码后就可以
如果连接遇到以下报错:
Error:Authorization failed
则可能是passwd.conf或者authz.conf配置文件导致的权限问题
如果还有其他连接报错,请检查/home/svndata/test/conf下的svnserve.conf文件中在修改时前面的#或者空格是否删除

7.svn客户端和服务器端文件的导入导出
在通过客户端连接时默认创建了个本地存储目录(如E:/test)
[root@server~]#svn list file:///home/svndata/test //列出版本库中的文件列表
[root@server~]#svn checkout file:///home/svndata/test//将版本库中的文件拷贝到本地
默认会在服务器的根下创建test目录,里面存放了本机的文件
把文件上传到SVN版本库后,上传的文件不再以文件原来的格式存储,而是被svn以它自定义的格式压缩成版本库数据,存放在版本库中(/home/svndata/test/db/revs中)。

Svn的命令使用大全详情参考http://www.jb51.net/os/RedHat/2461.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息