前段时间给团队内部搭建了一个gitlab服务器,结果很多策划大牛觉得用不习惯,不想改变已有的使用习惯,对Git更是嗤之以鼻,作为小小码农的我不想跟他们争辩什么,顺着他们的需求给整了一套svn系统。庆幸的是配置的过程比较顺利,只花了不到一个小时的时间。写篇博客记录以下吧!
1.安装svn
- 比较简单一句话搞定.
sudo yum install -y svn
安装完毕之后可以看到如下几个工具:
[root@localhost branches]# ls /usr/bin/svn*
/usr/bin/svn /usr/bin/svndumpfilter /usr/bin/svnserve /usr/bin/svnversion
/usr/bin/svnadmin /usr/bin/svnlook /usr/bin/svnsync
svn 就是一个客户端管理工具,和
git类似,常用的命令:svn常用命令/usr/bin/svnadmin 相当于一个服务端管理工具,用来管理资源仓库本身。
/usr/bin/svnserve 这是一个 svn 后台程序(daemon) 类似
httpd之于http服务器。
总结以下,我们需要用到svnadmin工具来创建新的资源仓库,在配置完成资源仓库之后记得要启动svn这项服务,所以要运行svnserver。客户端要从服务器拉取资源就需要svn这个客户端命令行工具。
2. 查看版本
安装完毕看看版本号
//或者svn --version
[root@localhost branches]# svnserve --version
svnserve,版本 1.6.11 (r934486)
编译于 Aug 17 2015,08:37:43
版权所有 (C) 2000-2009 CollabNet。
Subversion 是开放源代码软件,请参阅 http://subversion.tigris.org/ 站点。
此产品包含由 CollabNet(http://www.Collab.Net/) 开发的软件。
下列版本库后端(FS) 模块可用:
* fs_base : 模块只能操作BDB版本库。
* fs_fs : 模块与文本文件(FSFS)版本库一起工作。
Cyrus SASL 认证可用。
3.新建版本仓库
svn需要一个仓库来放置所有的版本库,参照官网svnadmin create建立一个版本库:
mkdir -p /var/svn/
svnadmin create /var/svn/repo0
4.配置版本库
[root@localhost conf]# pwd
/var/svn/repo0/conf
[root@localhost conf]# ls
authz passwd svnserve.conf
[root@localhost conf]#
authz: 配置版本库的权限
passwd: 配置用户名和密码
svnserve.conf: 配置svnserve的一些信息
- passwd新增一个测试用户
[root@localhost conf]# cat 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
chen.lin = 123456
[root@localhost conf]#
- 配置授权信息
[root@localhost conf]# cat 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
demo=chen.lin
# [/foo/bar]
# harry = rw
# &joe = r
# * =
# [repo0:/MyProject/trunk]
# @demo=r
# @harry_and_sally = rw
# * = r
# [repo0:/MyProject/branches]
@demo=rw
按照svn的惯例一个标准的版本库应该有三个文件夹:
分支:branches
主干:trunk
标签:tag
注意事项:
- 在配置完成每个小项之后记得加上
*=选项,屏蔽其他用户的权限。 repo0:/MyProject/trunk与/MyProject/trunk指向的都是当前版本库下对应的文件夹。
5. 启动svn服务器
svnserve -d -r /var/svn
-d表示以daemon模式运行svnserve, -r 表示以/var/svn作为版本仓库的根路径。
也可以直接修改开机自启动脚本
/etc/rc.d/init.d/svnserve。
6. 牛刀小试
- 导入一个项目
$ mkdir MyProject
$ mkdir MyProject/trunk
$ mkdir MyProject/branches
$ mkdir MyProject/tags
svn import MyProject svn://192.168.1.109/repo0/MyProject -m "first commit
- 导出文件
测试版本库有一个测试用户默认对branches分支有读写权限
[luncher@localhost branches]$ pwd
/home/luncher/branches
[luncher@localhost branches]$ svn info
路径: .
工作副本根目录: /home/luncher/branches
URL: svn://192.168.0.51/repo0/MyProject/branches
正确的相对 URL: ^/MyProject/branches
版本库根: svn://192.168.0.51/repo0
版本库 UUID: 5bdf8db6-3cf2-45da-9c6d-8c4810c6c629
版本: 4
节点种类: 目录
调度: 正常
最后修改的作者: chen.lin
最后修改的版本: 4
最后修改的时间: 2015-09-10 10:29:45 +0800 (四, 2015-09-10)
- 去掉写权限再试一试
- 修改
authz文件@demo=r - 提交一个文件试一试
- 修改
[luncher@localhost branches]$ touch b.txt
[luncher@localhost branches]$ vim b.txt
[luncher@localhost branches]$ echo "hello world" >> b.txt
[luncher@localhost branches]$ vim b.txt
[luncher@localhost branches]$ svn add b.txt
A b.txt
[luncher@localhost branches]$ svn ci -m 'add b.txt'
svn: E170001: 提交失败(细节如下):
svn: E170001: 认证失败
测试验证我们的配置是没有问题的。
trouble shotting
- 服务器端口问题
svn 默认使用的端口是3690,防火墙需要开放该端口权限
参考文档:
svn官方文档
本文介绍了如何在服务器上安装并配置SVN版本控制系统,包括安装过程、版本库的创建与配置、用户权限管理等内容,并提供了实践案例。
718

被折叠的 条评论
为什么被折叠?



