SVN 是一个自由开源的版本管理系统,它可以按照时间的顺序去管理文件、目录以及对其进行的修改。于今,它被广泛的用于互联网公司的项目版本管理中

工作原理

它的工作原理如下图所示

它是由一个SVN服务器和许多的SVN客户端组成

数据统一存储在SVN服务器上

客户端 从服务器检出(checkout)指定路径上的版本文件到本地,修改了之后再提交(commit)到服务器上,当其他的客户端再次检出或更新的时候,就能获取得到之前客户端提交的修改

这样,多个客户端就可以互不干扰的工作,实现了多人的协作

SVN已经是一个非常成熟且能快速实现项目版本管理的工具了,很多中小团队中都在使用,下面介绍下SVN服务器的安装和配置

安装

yum install -y subversion

安装完成之后,执行 svn --version 查看是否安装成功,如果有类似下面的输出则表示安装成功

[root@cghost21 ~]# svn --version
svn, version 1.7.14 (r1542130)
compiled Sep 30 2020, 17:44:04 Copyright (C) 2013 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 access (RA) modules are available: * ra_neon : Module for accessing a repository via WebDAV protocol using Neon.
- handles 'http' scheme
- handles 'https' scheme
* ra_svn : Module for accessing a repository using the svn network protocol.
- with Cyrus SASL authentication
- handles 'svn' scheme
* ra_local : Module for accessing a repository on local disk.
- handles 'file' scheme [root@cghost21 ~]#

默认目录

  • svnserve 安装目录

svnserve 默认安装在 /usr/bin 目录下,可通过 which svnserve 命令查看

[root@ecs-centos-7 ~]# which svnserve
/usr/bin/svnserve
  • 仓库地址

svnserve 默认的仓库地址是 /var/svn , 通过 /etc/sysconfig/svnserve 配置文件可以修改

[root@ecs-centos-7 ~]# cat /etc/sysconfig/svnserve
# OPTIONS is used to pass command-line arguments to svnserve.
#
# Specify the repository location in -r parameter:
OPTIONS="-r /var/svn"
  • svnserve 端口

svnserve 启动之后,默认使用 3690 端口

[root@ecs-centos-7 test_a]# netstat -anpt | grep svnserve
tcp 0 0 0.0.0.0:3690 0.0.0.0:* LISTEN 28347/svnserve

配置

  • 创建仓库

安装完成之后,使用 svnadmin create 仓库目录 来创建一个新仓库

我们在 /home/tt 目录下建立一个名为svn的仓库,以后所有的项目文件都放在这个目录下,创建成功之后在svn目录下多了几个子目录

[root@ecs-centos-7 tt]# svnadmin create /home/tt/svn
[root@ecs-centos-7 tt]# ls svn/
conf db format hooks locks README.txt

conf 目录是存放配置文件的

[root@ecs-centos-7 tt]# cd svn/conf/
[root@ecs-centos-7 conf]# ls
authz passwd svnserve.conf

authz 是用户权限控制文件

passwd 是账号密码配置文件

svnserve.conf 是svnserve服务配置文件

  • 配置用户名密码

编辑 passwd 配置文件,添加ta用户名和123456密码、 tb用户名和12345密码以及tc用户名和123密码

[root@ecs-centos-7 conf]# vim passwd
### This file is an example password file for svnserve.
### Its format is similar to that of svnserve.conf. As shown in the
### example below it contains one section labelled [users].
### The name and password for each user follow, one account per line. [users]
# harry = harryssecret
# sally = sallyssecret
ta = 123456
tb = 12345
tc = 123
  • 配置用户权限

为 SVN 用户 ta 配置读写权限,为 SVN用户 tb 配置只读权限,为 SVN用户 tc 配置只读权限

上图中是配置仓库的根目录访问权限,如果想配置仓库中指定目录的访问权限,可以在末尾增加一个仓库目录,目录下面再配置用户的访问权限即可

比如:仓库根目录下有一个myproject的目录,用户ta有读写权限,用户tb无访问权限,用户tc有只读权限,则 myproject 目录的权限配置如下

[/myproject]
ta=rw
tc=r
*=
  • 配置 svnserve 服务

如上图所示,打开红框中的选项前的注释,注意:每个选项前都不能有空格

anon-access = none   # 匿名用户无法访问
auth-access = write #授权用户可写
password-db = passwd #用户密码验证文件
authz-db = authz #用户权限验证文件
realm = /home/tt/svn #svn版本库目录

启动、停止、重启

修改 /etc/sysconfig/svnserveOPTIONS 的值为我们新创建的仓库地址

[root@ecs-centos-7 ~]# vim /etc/sysconfig/svnserve
# OPTIONS is used to pass command-line arguments to svnserve.
#
# Specify the repository location in -r parameter:
OPTIONS="-r /home/tt/svn"

svn安装完成之后,默认已经添加到systemctl中了,使用以下命令启动、停止、重启

[root@ecs-centos-7 ~]# systemctl start svnserve
[root@ecs-centos-7 ~]# systemctl stop svnserve
[root@ecs-centos-7 ~]# systemctl restart svnserve

在实际的部署中,为了重启机器时,不影响客户端的使用,svnserve通常会设置成开机启动

[root@ecs-centos-7 ~]# systemctl enable svnserve
Created symlink from /etc/systemd/system/multi-user.target.wants/svnserve.service to /usr/lib/systemd/system/svnserve.service.

客户端检出

配置好用户密码以及访问权限之后,重新启动 svnserve

新建test_a 目录,进入该目录,执行 svn co svn://192.168.0.9 --username ta --password 123456 命令检出svn仓库中的文件以及目录

[root@ecs-centos-7 tt]# mkdir test_a
[root@ecs-centos-7 tt]# cd test_a/
[root@ecs-centos-7 test_a]# svn co svn://192.168.0.9 --username ta --password 123456
[root@ecs-centos-7 test_a]# svn info
路径: .
工作副本根目录: /home/tt/test_a
URL: svn://192.168.0.9
版本库根: svn://192.168.0.9
版本库 UUID: c9730d20-968c-41c0-a224-4c6a967f8330
版本: 1
节点种类: 目录
调度: 正常
最后修改的作者: ta
最后修改的版本: 1
最后修改的时间: 2020-12-04 23:48:11 +0800 (五, 202-12-04)

适用的场景

每个工具都有其适用的场景,SVN也不例外

当你需要记录文件每一次的修改时间,查看随着时间变化的日志,追溯和回退到任意一次修改时间点时的版本,多人协作一起开发并追踪是谁进行了修改,那么是很适合使用SVN

对于一些比较大的或者后续不会有任何修改的文件、把SVN当做文件传输的中转站,这些都不适合用SVN,比如:从一个SVN客户端上传一部电影到SVN服务器上,然后在另一个SVN客户端更新这个电影文件,这是误用SVN这个工具了,上述文件的同步有专门的工具(rsync)来处理

小结

本章介绍了SVN服务器的工作原理、安装、配置、使用场景等,关于更多SVN相关的知识可以参考官方文档

对于中小创业团队,在事情多,人员少,时间紧的情况下,具有安装简单、使用方便、易上手(特别是对于非技术人员,稍微讲解下就能上手使用)等特点的SVN是非常好的选择

最新文章

  1. 【09-27】Spring 学习笔记
  2. Eclipse 开发 jsp
  3. 扫描二维码判断移动设备(Android/ios),以及判断是否微信端扫描
  4. Asp.Net Web API 2第十七课——Creating an OData Endpoint in ASP.NET Web API 2(OData终结点)
  5. CTest
  6. hdu 1850 Being a Good Boy in Spring Festival(Nimm Game)
  7. 用户 IIS APPPOOL\DefaultAppPool 登录失败的解决方法
  8. [iOS微博项目 - 2.1] - 获得新浪授权接口
  9. hdu2074java
  10. UVA 11214 Guarding the Chessboard
  11. Nexus远程Maven仓库索引下载教程
  12. Bash shell命令记录和CentOS的一些技巧
  13. Fiddler--Composer
  14. 第1次作业—— 熟悉 MoocTest环境
  15. NET(C#):关于正确读取中文编码文件
  16. 【Java每日一题】20170317
  17. Vim 中使用 vimim 来输入中文
  18. FlexRay笔记
  19. POJ 2337 Catenyms (欧拉回路)
  20. 美化VC界面(用户登录界面)

热门文章

  1. Linkerd 2.10(Step by Step)—控制平面调试端点
  2. Hexo搭建个人静态博客网站
  3. win10 uwp 通过 Win2d 完全控制笔迹绘制逻辑
  4. proto buffer
  5. APT组织跟踪与溯源
  6. Spring Boot 入门系列(二十五)读取配置文件的几种方式详解!
  7. 痞子衡嵌入式:MCUXpresso IDE下将关键函数重定向到RAM中执行的几种方法
  8. unity渲染篇:烘焙模型贴图
  9. BeanFactory和ApplicationContext对比
  10. Spring Boot 入门系列(二十七)使用Spring Data JPA 自定义查询如此简单,完全不需要写SQL!