一、概述
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的数据库容量会暴增。尤其是在开发人员非常多的情况下。
3)SVN使用http或https访问
1、有公网IP的,可利用Nginx的proxy方式,实现外网对内网的连接访问,也就实现http或https。
2、无公网IP网络环境,可通过内网NAT映射方案,将本地内网的3690端口映射成到带外的主机ip删,然后该主机nginx代理实现在外网通过域名来访问内网SVN(http或https的web服务)。
wget http://nginx.org/download/nginx-1.24.0.tar.gz
tar -xzf nginx-1.24.0.tar.gz
pcre-config --version #现场为7.8
cd nginx-1.24.0
useradd -s /bin/false nginx
vim scr/core/nginx.conf #隐藏版本
1 #define NGINX_VERSION “1.2X”
2 #define NGINX_VER “nginx/” NGINX_VERSION
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-openssl=/home/software/openssl-1.1.1k --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
#--prefix=/usr/local/nginx后不要写/;/home/software/openssl-1.1.1k
make -j4
cd objs
ls #如下
autoconf.err nginx ngx_auto_config.h ngx_modules.c src
Makefile nginx.8 ngx_auto_headers.h ngx_modules.o
which nginx #再次确认
/usr/sbin/nginx
mv /usr/sbin/nginx /usr/sbin/nginx.20230709
cp ./nginx /usr/sbin/ #复制新的文件夹替换原二进制目录
nginx -v
#配置Nginx反向代理,修改/etc/nginx/nginx.conf //如下
server {
listen 80;
server_name svn.local.com;
location /svn/repo {
alias root /opt/;
proxy_pass http://127.0.0.1/svn/repo;
add_header backendIP $upstream_addr;
access_log off;
proxy_redirect off;
client_max_body_size 5000m;
autoindex off;
}
location / {
return 404;
}
}
#启动
/sbin/nginx
#验证,浏览器访问
http://svn.local.com/svn/repo #即访问svn库
##httpd转发
yum install -y httpd
yum install -y mod_dav_svn #安装Apache SVN模块
#建立SVN库
mkdir -p /opt/svn/
cd /opt/svn/
svnadmin create repo
chown -R apache.apache repo
#添加Subversion账号
htpasswd -c /opt/svn/work/conf/passwdfile xiaowang
#
vim /etc/httpd/conf.d/subversion.conf //内容如下
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so
<Location /svn/repo>
DAV svn
SVNPath /opt/svn/repo
# Limit write permission to list of valid users.
<LimitExcept GET PROPFIND OPTIONS REPORT>
# Require SSL connection for password protection.
# SSLRequireSSL
AuthType Basic ## 使用基本认证方式,即用户名、密码认证
AuthName "Authorization Realm" ## 在认证对话框中出现的提示信息
AuthUserFile /opt/svn/repo/conf/passwdfile #定存放用户名信息的文件路径
AuthzSVNAccessFile /opt/svn/repo/conf/authz #指定存放用户访问路径信息的文件路径
Require valid-user #限定只有用户输入正确的用户名和密码后才能访问该标签所指向的路径
</LimitExcept>
</Location>
#启动
/etc/init.d/httpd start
bin\svn.exe" update "/svn/repo" --quiet --username 用户名 --password 密码
#Docker中安装SVN服务端并用正确姿势配置iF.SVNAdmin后台权限管理页面以及用Nginx代理实现https(配SSL)访问;更多参考:
https://www.xubingtao.cn/2020/02/07/install_svn/
#这里我们使用elleflorio/svn-server:latest镜像,因其支持http://和svn://访问。
docker run --privileged=true -d --name svn-server -p 8000:80 -p 8080:3690 -v /opt/SVNServer:/opt/svn elleflorio/svn-server
#将容器中的svn配置文件 cp 至宿主机
docker cp svn-server:/etc/subversion /opt/SVNServer/svnconfig
docker stop svn-server
docker rm svn-server
#安装 SVN 服务器并挂载配置文件
docker run --privileged=true -d --name svn-server -p 8000:80 -p 8080:3690 \
-v /opt/SVNServer:/opt/svn \
-v /opt/SVNServer/svnconfig/subversion-access-control:/etc/subversion/subversion-access-control \
-v /opt/SVNServer/svnconfig/passwd:/etc/subversion/passwd \
elleflorio/svn-server
#配置 svnadmin,访问http://ip:8000设置 svnadmin
Subversion authorization file: /etc/subversion/subversion-access-control
User authentication file (SVNUserFile):/etc/subversion/passwd
Parent directory of the repositories (SVNParentPath):/home/svn
Subversion client executable:/usr/bin/svn
Subversion admin executable:/usr/bin/svnadmin
##创建SVN仓库用户
vim passwd //配置登录访问SVN用户,格式:用户名 = 密码
[users]
xiaowang = 123456
#修改用户访问权限
vim authz //在 [groups]下建立用户组yanfa,后面的值是要添加进本组的用户名,以逗号分隔
[groups]
yanfa = xiaowang
[/svn]
@yanfa = rw //@ 指向用户组,单个用户无需添加,还可配* = r,*代表上述未提到的用户和用户组的权限配置。
vim svnserve.conf //出现authorization failed异常,一般都是authz文件或者svnserve.conf里,用户组或者用户权限没有配置好,只要设置[/]就可以,代表根目录下所有的资源,如果要限定资源,可以加上 子目录即可
[general]
anon-access = read
auth-access = write
password-db = passwd
authz-db = authz