您好,欢迎访问这里是深圳市硕远科技有限公司!
戴尔服务器价格_IBM联想配置_浪潮代理-深圳市硕远科技有限公司
联系我们
戴尔服务器价格_IBM联想配置_浪潮代理-深圳市硕远科技有限公司
邮箱:2324898850@qq.com
电话:400-080-6079
地址:深圳市龙华区河背工业区108创业园A301
当前位置:主页 > 新闻动态 > 行业新闻 >

行业新闻

Linux 下 SVN 的安装和配置

发布时间:2022-04-25 18:13:46浏览次数:

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/svnserve 中OPTIONS 的值为我们新创建的仓库地址

[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是非常好的选择

400-080-6079