1. svn命令
svn
The command-line client program
svnversion
A program for reporting the state (in terms of revisions of the items present) of a working copy
svnlook
A tool for directly inspecting a Subversion repository
svnadmin
A tool for creating, tweaking, or repairing a Subversion repository
mod_dav_svn
A plug-in module for the Apache HTTP Server, used to make your repository available to others over a network
svnserve
A custom standalone server program, runnable as a daemon process or invokable by SSH; another way to make your repository available to others over a network.
svndumpfilter
A program for filtering Subversion repository dump streams
svnsync
A program for incrementally mirroring one repository to another over a network
2. 部署SVN服务
2.1 安装SVN服务
sudo apt-get install subversion
2.2 创建版本库
找个地方放置仓库
sudo mkdir 目录路径
sudo svnadmin create 目录路径/repo(我这里叫repo,你们随便起什么名字)
如我配置的是:
sudo mkdir /home/svn
sudo svnadmin create /home/svn/repo
这里有个地方要注意的,如果你是用root登录主机的话,千万不要在root的home目录也就是/root目录下创建svn文件夹,这样虽然svn服务能部署起来,但是后面是用apache部署http访问时会因为没有权限而失败的。
2.3 了解版本信息
conf --各种配置信息
db --存放svn转储后的数据
format --是一个文本文件,里面只放了一个整数,表示当前文件库配置的版本号
hooks --放置hook脚本文件
locks --用来放置svn的db锁文件和db_logs锁文件的目录,用来追踪存取文件库的客户端
README.txt
2.4 配置svn服务
cd conf
authz --定义权限组
passwd --定义svn用户名和密码
svnserve.conf --配置svn服务
2.4.1 配置svn服务
sudo vi svnserve.conf
去掉下面参数的注释,根据自己的需求更改参数的值
anon-access = none #匿名访问权限,默认read,none为不允许访问
auth-access = write #认证用户权限
password-db = passwd #用户信息存放文件,默认在版本库/conf下面,也可以绝对路径指定文件位置
authz-db = authz #用户组信息存放文件,默认在版本库/conf下面,也可以绝对路径指定文件位置
2.4.2 配置svn用户及密码
sudo vi passwd
格式是用户名=密码,如chengj=123456
2.4.3 配置用户组
sudo vi authz
[groups] #定义组的用户
manager = chengxj,foo,bar #manager组
core_dev = alice #core_dev组
[repo:/] #以根目录起始的repo版本库,地址为svn://主机IP/repo
@manager = rw #manager组拥有读写权限
* = r #其他用户只有读权限
[repo:/media] #repo版本库下media目录,地址为svn://主机IP/repo/media
@core_dev = rw #core_dev对repos版本库下media目录为读写权限
2.5 启动服务
sudo svnserve -d -r 版本库父目录路径
如我配置的是:
sudo svnserve -d -r /home/svn
查看是否启动成功,可看的监听3690端口
sudo netstat -antp |grep svnserve
tcp 0 0 0.0.0.0:3690 0.0.0.0:* LISTEN 28967/svnserve
如果想关闭服务,可使用pkill svnserve
可以在客户机使用命令行或者svn客户端checkout仓库使用,这里就不展开了
3. 配置HTTP访问
在完成上面的配置后,就可以通过svn客户端访问仓库的内容了,但是仍然无法在浏览器中访问,我们可以通过配置apache服务器来使用HTTP访问svn库。
3.1 安装apache及其相关软件
sudo apt-get install apache2 libapache2-svn apache2-utils
3.2 修改版本库权限
sudo chmod -R 777 版本库路径
sudo chown -R www-data:www-data 版本库路径
注意:如果你要建多个库,每个库都要给他权限
3.3 配置apache2
sudo vi /etc/apache2/mods-available/dav_svn.conf
# dav_svn.conf - Example Subversion/Apache configuration
#
# For details and further options see the Apache user manual and
# the Subversion book.
#
# NOTE: for a setup with multiple vhosts, you will want to do this
# configuration in /etc/apache2/sites-available/*, not here.
# ...
# URL controls how the repository appears to the outside world.
# In this example clients access the repository as http://hostname/svn/
# Note, a literal /svn should NOT exist in your document root.
# 配置svn的http路径,如这里配置了svn后路径为http://hostname/svn/
# Uncomment this to enable the repository
DAV svn
# Set this to the path to your repository
#SVNPath /root/SVN/repo/
# Alternatively, use SVNParentPath if you have multiple repositories under
# under a single directory (/var/lib/svn/repo1, /var/lib/svn/repo2, ...).
# You need either SVNPath and SVNParentPath, but not both.
SVNParentPath /home/svn # 当在一个父目录中有多个库时使用SVNParentPath
SVNListParentPath On # 显示仓库根目录
# Access control is done at 3 levels: (1) Apache authentication, via
# any of several methods. A "Basic Auth" section is commented out
# below. (2) Apache and , also commented out
# below. (3) mod_authz_svn is a svn-specific authorization module
# which offers fine-grained read/write access control for paths
# within a repository. (The first two layers are coarse-grained; you
# can only enable/disable access to an entire repository.) Note that
# mod_authz_svn is noticeably slower than the other two layers, so if
# you don't need the fine-grained control, don't configure it.
# Basic Authentication is repository-wide. It is not secure unless
# you are using https. See the 'htpasswd' command to create and
# manage the password file - and the documentation for the
# 'auth_basic' and 'authn_file' modules, which you will need for this
# (enable them with 'a2enmod').
AuthType Basic # 基本权限验证功能
AuthName "Subversion Repository" # 权限名字,随便都行
AuthUserFile /etc/apache2/dav_svn.passwd # 保存授权用户的账户密码的文件路径
# To enable authorization via mod_authz_svn (enable that module separately):
#
#AuthzSVNAccessFile /etc/apache2/dav_svn.authz
#
# The following three lines allow anonymous read, but make
# committers authenticate themselves. It requires the 'authz_user'
# module (enable it with 'a2enmod').
# 除了以下描述的GET OPTIONS操作外,其他的HTTP操作都需要授权用户才可以
Require valid-user
3.4 创建在浏览器中使用的用户及密码
sudo htpasswd -c /etc/apache2/dav_svn.passwd 用户名
,根据提示输入密码
注意,-c仅仅在没有dav_svn.passwd文件的情况下使用,即创建第一个用户时使用,若创建之后的用户仍然使用-c,则会把之前创建的用户覆盖掉
3.5 启动Apache服务
sudo /etc/init.d/apache2 restart
然后就可以在浏览器中浏览了,http://服务器地址/域名/svn/库名
注意,如果80端口被其他程序占用,这里启动apache服务会失败,可以修改/etc/apache2下的ports.conf
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf
Listen 80 # 修改为其他端口
Listen 443
Listen 443
然后重启apache服务即可
脚本的话正在写,晚点传到GitHub上去
参考链接
svn安装
Ubuntu 14.04快速搭建SVN服务器及日常操作
Ubuntu下搭建http访问方式的SVN服务器