一、概述

SVN的全称是Subversion,是一个流行的开源的版本控制系统。Subversion可管理随时间改变的数据, 这些数据放置在一个中央资料档案库(repository) 中。 它就像一个普通的文件服务器, 不过它会记住每一次文件的变动。 这样当需要回退时,就能把档案恢复到旧的版本, 当然也就可浏览文件的变动历史。
相关概念:
repository(源代码库)::源代码统一存放的地方
Checkout(提取):从repository checkout源代码到本地调试
Commit(提交):当修改了代码,就需要Commit到repository以更新
Update (更新):当我们已经Checkout了一份源代码, Update一下就可以和Repository上的源代码同步,你手上的代码就会有最新的变更
系统版本:BCLinux 8.6(GNU/Linux 4.19.0-372.26.2.el8.bclinux.x86_64)
Subversion版本:version 1.10.2 (r1835932)
官网:http://subversion.apache.org/,下载:https://tortoisesvn.net/downloads.html,下载2;镜像站;文档
二、SVN环境部署

1)安装
rpm -ql subversion
yum install subversion -y   //联外网直接yum
Last metadata expiration check: 2:19:02 ago on Mon 03 Jul 2023 11:21:52 AM CST.
Dependencies resolved.
=====================================================================================================================================================
 Package                          Architecture            Version                                                   Repository                  Size
=====================================================================================================================================================
Installing:
 subversion                       x86_64                  1.10.2-5.module+an8.6.0+10794+181dc1ae                    AppStream                  1.1 M
Installing dependencies:
 apr                              x86_64                  1.6.3-12.0.1.an8                                          AppStream                  128 k
 apr-util                         x86_64                  1.6.1-6.el8                                               AppStream                  104 k
 libserf                          x86_64                  1.3.9-9.module+el8.2.0+10160+765beef7                     AppStream                   59 k
 subversion-libs                  x86_64                  1.10.2-5.module+an8.6.0+10794+181dc1ae                    AppStream                  1.5 M
 utf8proc                         x86_64                  2.1.1-5.module+el8.2.0+10160+765beef7                     AppStream                   66 k
Enabling module streams:
 subversion                                               1.10                                                                                      
Transaction Summary
=====================================================================================================================================================
Install  6 Packages
Total download size: 3.0 M
Installed size: 10 M
Downloading Packages:
(1/6): apr-1.6.3-12.0.1.an8.x86_64.rpm                                                                               5.6 MB/s | 128 kB     00:00    
(2/6): apr-util-1.6.1-6.el8.x86_64.rpm                                                                               3.8 MB/s | 104 kB     00:00    
(3/6): libserf-1.3.9-9.module+el8.2.0+10160+765beef7.x86_64.rpm                                                      2.0 MB/s |  59 kB     00:00    
(4/6): subversion-1.10.2-5.module+an8.6.0+10794+181dc1ae.x86_64.rpm                                                   18 MB/s | 1.1 MB     00:00    
(5/6): utf8proc-2.1.1-5.module+el8.2.0+10160+765beef7.x86_64.rpm                                                     1.1 MB/s |  66 kB     00:00    
(6/6): subversion-libs-1.10.2-5.module+an8.6.0+10794+181dc1ae.x86_64.rpm                                             4.2 MB/s | 1.5 MB     00:00    
-----------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                7.6 MB/s | 3.0 MB     00:00    
 

#离线方式:将下载后的压缩包(共6个)依次解压,因下载限制,以网络上1.110版本描述
wget https://mirrors.cnnic.cn/apache/subversion/subversion-1.14.2.tar.gz
tar -zxvf subversion-1.14.2.tar.gz
cd subversion-1.14.2/
#解压后验证
ls subversion-1.14.2  //如下
aclocal.m4  BUGS   build.conf        CHANGES     configure     doc            gen-make.py  INSTALL  Makefile.in  README      tools
autogen.sh  build  build-outputs.mk  COMMITTERS  configure.ac  gen-make.opts  get-deps.sh  LICENSE  NOTICE       subversion  win-tests.py
#编译安装
./configure --with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr \
--with-serf=/usr/local/serf \
--with-openssl
#方式三:依赖
tar -zxvf subversion-1.11.0.tar.gz
tar -zxvf apr-1.6.5.tar.gz
tar -zxvf apr-util-1.6.1.tar.gz
tar -zxvf zlib-1.2.11.tar.xz
tar -zxvf expat_2.0.1.orig.tar.gz
tar -zxvf sqlite-autoconf-3260000.tar.gz
#安装Apr:http://apr.apache.org/
cd apr-1.6.5
#使用vi编辑configure文件,将其中的RM='$RM'改为RM='$RM -f';进入vi之后可以使用/RM='$RM'命令快速找到需要修改的位置
#完成后,预编译
./configure --prefix=/usr/local/apr
make 
make install
#安装apr-util
#进入apr-util安装包目录
cd apr-util-1.6.1
yum install expat-devel
#执行以下命令
./configure --prefix=/usr/local/apr --with-apr=/usr/local/apr --with-expat=/usr/local/apr/expat
make && make install
#安装expat:http://sourceforge.net/projects/expat/files/expat/2.1.0/
cd expat-2.0.1
./configure --prefix=/home/SVN/expat
make && make install
#安装zlib,http://www.zlib.net/
cd zlib-1.2.11
./configure --prefix=/home/SVN/zlib
make && make install
#安装sqlite-autoconf,http://www.sqlite.org/download.html
#unzip sqlite-amalgamation-3230100.zip -d ../subversion-1.8.15
#复制文件夹sqlite-autoconf至/home/SVN/目录下
mkdir -p  ./subversion-1.11.0/sqlite-amalgamation
 
cp -r sqlite-autoconf-3260000/*  ./subversion-1.11.0/sqlite-amalgamation
#openssl安装,http://www.openssl.org/
tar zxvf openssl-1.0.1h.tar.gz
cd openssl-1.0.1h
./config
make &&make  install
#serf模块(1.2.1),http://serf.googlecode.com/files/serf-1.2.1.tar.bz2;1.8版本之前的需要加neon,1.8版本之后弃用neon而改使用serf;另据subversion 1.8版本使用serf-1.3.0会有异常
tar xjvf serf-1.2.1.tar.bz2
cd serf-1.2.1
./configure
make && make install
#最后安装subversion
cd subversion-1.11.0
#执行以下命令
./configure --prefix=/home/SVN/subversion --with-apr=/home/SVN/apr --with-apr-util=/home/SVN/apr-util --with-zlib=/home/SVN/zlib --with-lz4=internal --with-utf8proc=internal
make
make install
 
2)验证
vi /etc/profile 	#修改如下行为:
export PATH=$PATH:/home/svn/subversion-1.12.0/bin
#保存退出后,立即生效
source /etc/profile
svnserve --version  //验证,输出如下
svnserve, version 1.10.2 (r1835932)
   compiled Jun  2 2022, 14:53:28 on x86_64-Anolis-linux-gnu
Copyright (C) 2018 The Apache Software Foundation.
This software consists of contributions made by many people;
see the NOTICE file for more information.
Subversion is open source software, see http://subversion.apache.org/
The following repository back-end (FS) modules are available:
* fs_fs : Module for working with a plain file (FSFS) repository.
* fs_x : Module for working with an experimental (FSX) repository.
Cyrus SASL authentication is available.
 
3)配置
#创建svn目录
mkdir /svn
#创建版本库目录
svnadmin create version_repo
#验证:
ls  //如下所示,其中,authz为版本库用户权限管理;passwd为版本库使用用户信息配置,包括用户名和密码;svnserve.conf用于版本库信息配置,db目录:就是所有版本控制的数据存放文件;hooks目录:放置hook脚本文件的目录;locks目录:用来放置subversion监控锁定数据的目录,用来追踪存取文件库的客户端;format文件:是一个文本文件,里面只放了一个整数。表示当前文件库配置的版本号;conf目录:是这个仓库的配置文件(仓库的用户访问账号、权限等),也是我们要关注的配置文件
conf  db  format  hooks  locks  README.txt
#svnserve配置
cd ./conf
vim svnserve.conf  //默认基本都是注释的,需要我们解注释如下项
[general]
auth-access = write   //认证用户访问权限,默认为write
password-db = passwd	//用户信息文件,默认即可
authz-db = authz         //版本库用户访问权限配置,默认即可
realm = My First Repository  //指定版本库认证域,如果两个仓库拥有相同的认证域,则需要使用相同的authz和password文件
#配置验证:
cat svnserve.conf |grep -Ev '^#|^$'
#创建SVN仓库用户
vim passwd  //配置登录访问SVN用户,格式:用户名 = 密码
[users]
xiaowang = 123456
#修改用户访问权限
vim authz  //在 [groups]下建立用户组yanfa,后面的值是要添加进本组的用户名,以逗号分隔
[groups]
yanfa = xiaowang  
[/svn]
@yanfa = rw  //@ 指向用户组,单个用户无需添加,还可配* = r,*代表上述未提到的用户和用户组的权限配置。
 
4)启动服务
svnserve -d -r /svn // -d 表示以后台模式启动, -r 指定svn服务的根目录
 svnserve -d -r /svn/ --listen-port 13690 --log-file /var/log/vncserver.log //修改服务端口
 svnserve -r /svn/ --listen-port 13690 --foreground //debug调试
netstat -antp|grep svn   //Subversion默认使用的端口为3690
tcp        0      0 0.0.0.0:3690            0.0.0.0:*               LISTEN      3409822/svnserve
#本地验证
svn co svn://svn_ip:port/version_repo
svn checkout svn://127.0.0.1/version_repo    #将文件checkout到本地目录
svn add file		#往版本库中添加新的文件
#查看当前版本库的状态
svn status 或 svn status -v
#库变化比较
svn diff
 
5)客户端验证
开通3690的访问策略后(firewall-cmd --zone=public --add-port=13690/tcp --permanent),使用TortoiseSVN客户端连接验证;svn://ip地址:3690/xxxx,其中:xxxx为前文创建的版本库名称
 
 
三、附录
1)版本库新增
若要在/svn目录下添加新的版本库,直接新建相应的目录,然后设置为版本库,最后配置即可,不需要重新运行svnserve -d -r /svn,也不需要把该命令应用到/svn目录下你所新建的目录,如果因为误操作执行了以上命令,会导致资源库不可用,再次运行svnserve -d -r /home/svn也会报:“不能绑定服务器套接字 地址已在使用”的错误字样“(若已至此,删掉新建的资源库,并用ps -ef | grep svnserve查看进程,kill -9 [进程号] 杀掉,重新执行svnserve -d -r /svn,再次新建资源库,直接配置即可使用)
2)产品优缺点
 
优点:
1.对于某些项目的核心代码或者是一些重要的保密性要求较高的项目,svn比git更适合。
2.svn支持空目录
3.svn有更好的windows平台支持
4.svn可以check out/clone一个子树(sub-tree)
5.svn支持特权访问控制svn lock,在处理很难合并的文件时非常有用
6.svn支持二进制文件,更容易处理大文件(不需要把老版本拷来拷去)
7.学习简单、使用简单
缺点:
1.无网的情况下:无法提交代码,无法查看代码的历史版本、无法同步代码
2.代码要定期做备份(所有的代码数据及版本变更记录)
3.分支切换缓慢
4.由于每次提交都会保留一个原始副本,因此SVN的数据库容量会暴增。尤其是在开发人员非常多的情况下。


















