一、SVN介绍
SVN的全称是Subversion,即版本控制系统。它是最流行的一个开放源代码的版本控制系统。作为一个开源的版本控制系统,Subversion管理着随时间改变的数据。这些数据放置在一个中央资料档案库(Repository)中。这个档案库很像一个普通的文件服务器,不过它会记住每一次文件的变动。这样就可以把档案恢复到旧的版本,或是浏览文件的变动历史。Subversion是一个通用的系统,可用来管理任何类型的文件,其中包括程序源码。
SVN采用客户端/服务器体系,项目的各种版本都存储在服务器上,程序开发人员首先将从服务器上获得一份项目的最新版本,并将其复制到本机,然后在此基础上,每个开发人员可以在自己的客户端进行独立的开发工作,并且可以随时将新代码提交给服务器。当然也可以通过更新操作获取服务器上的最新代码,从而保持与其他开发者所使用版本的一致性。 [3]
SVN的客户端有两类,一类是基于Web的WebSVN等,另一类是以Tortoise SVN为代表的客户端软件。前者需要Web服务器的支持,后者需要用户在本地安装客户端,两种都有免费的开源软件供使用。SVN存储版本数据也两种方式:BDB(一种事务安全型表类型)和FSFS(一种不需要数据库的存储系统)。因为BDB方式在服务器中断时,有可能锁住数据,所以还是FSFS方式更安全一点。
(一)SVN工作机制
SVN系统具体是如何实现对项目软件的版本控制,一方面通过实现历史操作记录查阅。在任意一台服务器中都可以添加一个SVN版本库,而相应的版本库中存放大量的程序和文档,而这些项目资源主要通过配置管理员依据不同的配置管理计划对不同项目的组员分配与之相符合的访问权限,进而实现对资源的统一管理;只有SVN标本过版本库中的资源,项目组成员可以对版本资源库中的资源进行访问。
一次简单的访问过程包括:相关项目组员首先在客户操作端建立一个从版本库检索出来的项目文件,而后就可以对拷贝的档案进行修改,最后通过SVN提交命令将其修改后的项目文件提交到终端服务器,终端服务器最终会对修改后的项目文件做最后的综合更新记录。
修改过的文件在修改未被提交到服务器前,SVN服务器只会对已经提交到网络端服务器的项目文档进行更新审核,并与其他人的合并,在此之前修改过的文档是保密的,提交之后SVN络端服务器会将修改后与修改之前的数据进行比较,并在后台对修改内容就行标注显示,进而实现对历史操作记录的更新记载。最终实现项目组组员既能检索出旧版本,又能通过SVN实现新旧版本的对比,另一方面SVN通过进行组员间的协同开发实现对项目软件的版本控制。协同开发一般是指版本控制系统间接受并处理不同用户提交的各种不同性质版本的资源代码,同时允许各个用户之间在遵循相应规则范围内实现合作开发。如何处理好有矛盾的版本控制系统才是能够协同开发的关键,像是多个程序编码员同时对同一份资源代码进行修改、提交到SVN版本库,就有可能发生提交后的版本意见想法相冲等问题。
(二)SVN优势
1.存储
SVN服务器既具有CVS所具有数据储存的优点,像是信息资源存储后会形成资源树结构,便于存储的同时,数据一般不会丢失,同时又拥有自己的特色。SVN是通过关系数据库及二进制的存储方式,同时解决了既往不能同时读写同一文件等问题,同时增添了自己特有的“零或一”原则。
2.速度
与人们初始的CVS相比,SVN在速度运行方面有很大提升。因为SVN服务器只支持少量的信息、资源传输,与其他系统相比,更支持的是离线模式,因此避免了网络拥挤现象的出现。
3.安全性
SVN是一种技术性更加安全的产品,实现了系统和控制两方面的结合。一方面可以将系统整体的安全功能有效地分布在分支系统中,进而保证分支系统能正常运行,从而使各分支系统能够互补,最终在系统整体性的安全性得以保障,通过均衡原则实现最终追求安全的目的。
二、安装SVN
1、安装(Fedora发行版)
//服务端[mate@localhost ~]$ sudo dnf install subversion//GUI客户端[mate@localhost ~]$ sudo dnf install rabbitvcs*
三、配置SVN
1、新建仓库
创建仓库时会根据创建的仓库名称创建一个文件夹
#创建仓库mate@matelearn:~/SVN$ svnadmin create JAC-Project#根据仓库名自动生成一个文件夹mate@matelearn:~/SVN$ lsJAC-Project#进入文件夹查看仓库树mate@matelearn:~/SVN$ cd JAC-Projectmate@matelearn:~/SVN/JAC-Project$ lsconf db format hooks locks README.txtmate@matelearn:~/SVN/JAC-Project$ tree.├── conf│ ├── authz│ ├── hooks-env.tmpl│ ├── passwd│ └── svnserve.conf├── db│ ├── current│ ├── format│ ├── fsfs.conf│ ├── fs-type│ ├── min-unpacked-rev│ ├── revprops│ │ └── 0│ │ └── 0│ ├── revs│ │ └── 0│ │ └── 0│ ├── transactions│ ├── txn-current│ ├── txn-current-lock│ ├── txn-protorevs│ ├── uuid│ └── write-lock├── format├── hooks│ ├── post-commit.tmpl│ ├── post-lock.tmpl│ ├── post-revprop-change.tmpl│ ├── post-unlock.tmpl│ ├── pre-commit.tmpl│ ├── pre-lock.tmpl│ ├── pre-revprop-change.tmpl│ ├── pre-unlock.tmpl│ └── start-commit.tmpl├── locks│ ├── db.lock│ └── db-logs.lock└── README.txt
2、配置仓库
(1)添加用户及权限:authz文件
### This file is an example authorization file for svnserve.### Its format is identical to that of mod_authz_svn authorization### files.### As shown below each section defines authorizations for the path and### (optional) repository specified by the section name.### The authorizations follow. An authorization line can refer to:### - a single user,### - a group of users defined in a special [groups] section,### - an alias defined in a special [aliases] section,### - all authenticated users, using the '$authenticated' token,### - only anonymous users, using the '$anonymous' token,### - anyone, using the '*' wildcard.###### A match can be inverted by prefixing the rule with '~'. Rules can### grant read ('r') access, read-write ('rw') access, or no access### ('').[aliases]# joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average[groups]# harry_and_sally = harry,sally# harry_sally_and_joe = harry,sally,&joe# [/foo/bar]# harry = rw# &joe = r# * =# [repository:/baz/fuz]# @harry_and_sally = rw# * = r##[/]mate = wr
(2)设置密码: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#mate = zmy20141321
(3)服务配置:svnserve.conf
### This file controls the configuration of the svnserve daemon, if you### use it to allow access to this repository. (If you only allow### access through http: and/or file: URLs, then this file is### irrelevant.)### Visit http://subversion.apache.org/ for more information.[general]### The anon-access and auth-access options control access to the### repository for unauthenticated (a.k.a. anonymous) users and### authenticated users, respectively.### Valid values are "write", "read", and "none".### Setting the value to "none" prohibits both reading and writing;### "read" allows read-only access, and "write" allows complete### read/write access to the repository.### The sample settings below are the defaults and specify that anonymous### users have read-only access to the repository, while authenticated### users have read and write access to the repository.anon-access = noneauth-access = write### The password-db option controls the location of the password### database file. Unless you specify a path starting with a /,### the file's location is relative to the directory containing### this configuration file.### If SASL is enabled (see below), this file will NOT be used.### Uncomment the line below to use the default password file.password-db = passwd### The authz-db option controls the location of the authorization### rules for path-based access control. Unless you specify a path### starting with a /, the file's location is relative to the### directory containing this file. The specified path may be a### repository relative URL (^/) or an absolute file:// URL to a text### file in a Subversion repository. If you don't specify an authz-db,### no path-based access control is done.### Uncomment the line below to use the default authorization file.authz-db = authz### The groups-db option controls the location of the groups file.### Unless you specify a path starting with a /, the file's location is### relative to the directory containing this file. The specified path### may be a repository relative URL (^/) or an absolute file:// URL to a### text file in a Subversion repository.# groups-db = groups### This option specifies the authentication realm of the repository.### If two repositories have the same authentication realm, they should### have the same password database, and vice versa. The default realm### is repository's uuid.realm = JAC-Project### The force-username-case option causes svnserve to case-normalize### usernames before comparing them against the authorization rules in the### authz-db file configured above. Valid values are "upper" (to upper-### case the usernames), "lower" (to lowercase the usernames), and### "none" (to compare usernames as-is without case conversion, which### is the default behavior).# force-username-case = none### The hooks-env options specifies a path to the hook script environment### configuration file. This option overrides the per-repository default### and can be used to configure the hook script environment for multiple### repositories in a single file, if an absolute path is specified.### Unless you specify an absolute path, the file's location is relative### to the directory containing this file.# hooks-env = hooks-env[sasl]### This option specifies whether you want to use the Cyrus SASL### library for authentication. Default is false.### This section will be ignored if svnserve is not built with Cyrus### SASL support; to check, run 'svnserve --version' and look for a line### reading 'Cyrus SASL authentication is available.'# use-sasl = true### These options specify the desired strength of the security layer### that you want SASL to provide. 0 means no encryption, 1 means### integrity-checking only, values larger than 1 are correlated### to the effective key length for encryption (e.g. 128 means 128-bit### encryption). The values below are the defaults.# min-encryption = 0# max-encryption = 256
四、启动仓库
1、启动单个仓库
方式一:-r直接指定到版本库(称之为单库svnserve方式)
svnserve -d -r /home/mate/SVN/JAC-Project
在这种情况下,一个svnserve只能为一个版本库工作。
authz配置文件中对版本库权限的配置应这样写:
[/]
@admin=rw
user2=r
使用类似这样的URL:svn://192.168.0.1/ 即可访问JAC-Project版本库
2、多库启动
SVN目录下有Documents、JAC-Project两个仓库
方式二:指定到版本库的上级目录(称之为多库svnserve方式)
svnserve -d -r /home/mate/SVN
这种情况,一个svnserve可以为多个版本库工作
svnserve会检查目录下的所有库的配置文件,
使用类似这样的URL:svn://192.168.0.1/Documents 即可访问 Documents 版本库。
3、添加系统自启
(1)创建自启脚本
[Unit]
Description=SVN service
After=network.target mount_toshiba.service
[Service]
Type=forking
WorkingDirectory=/home/pi/toshiba/SVN
ExecStart=svnserve -d -r ./
TimeoutSec=0
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
(2)复制脚本至目录:/etc/systemd/system/
##将这个文件用 root 用户保存到 /etc/systemd/system 目录:
sudo cp myscript.service /etc/systemd/system/
##然后就可以用下面的命令尝试启动服务了:
sudo systemctl start myscript.service
##停止服务:
sudo systemctl stop myscript.service
##设置开机时自动运行:
sudo systemctl enable myscript.service
##systemctl 命令还可以用来重启或禁用它。
五、常见问题及解决方案
(一)文件被锁定
用SVN经常出现被锁定而无法提交的问题,选择解锁又提示没有文件被锁定,很是头疼。这里整理了一下SVN 被锁定的几种解决方法:
- 出现这个问题后使用“清理”即”Clean up“功能,如果还不行,就直接到上一级目录,再执行“清理”,然后再“更新”。
- 有时候如果看到某个包里面的文件夹没有SVN的标志,直接用“Ctrl+Delete”手工删除,然后“清理”,最后“更新”或“提交”。
- 有时候有的文件死活无法提交和更新,有lock字样的提示,:首先点击该文件,然后getLock,再选中stealLock,然后release lock即可
- 教大家最狠的一招,在项目中如果是出现某个文件死锁的情况无法解决的情况下,叫开发中所有的人把文件上传了解锁了,清空版本库地址:安装目录:SvnTracsvnprojectsdblocks这个文件夹路径里面的全部内容。一切ok!
