Ubuntu部署SVN服务及HTTP访问

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 了解版本信息

repository_directory

conf --各种配置信息
db --存放svn转储后的数据
format --是一个文本文件,里面只放了一个整数,表示当前文件库配置的版本号
hooks --放置hook脚本文件
locks --用来放置svn的db锁文件和db_logs锁文件的目录,用来追踪存取文件库的客户端
README.txt

2.4 配置svn服务

cd conf

conf

authz --定义权限组
passwd --定义svn用户名和密码
svnserve.conf --配置svn服务

2.4.1 配置svn服务

sudo vi svnserve.conf

svnserve

去掉下面参数的注释,根据自己的需求更改参数的值

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

passwd

2.4.3 配置用户组

sudo vi authz

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.

# <Location URL> ... </Location>
# 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.
<Location /svn>  # 配置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 <Limit> and <LimitExcept>, 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):
  #<IfModule mod_authz_svn.c>
  #AuthzSVNAccessFile /etc/apache2/dav_svn.authz
  #</IfModule>

  # 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操作都需要授权用户才可以
  <LimitExcept GET PROPFIND OPTIONS REPORT>
    Require valid-user
  </LimitExcept>

</Location>

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  # 修改为其他端口

<IfModule ssl_module>
    Listen 443
</IfModule>

<IfModule mod_gnutls.c>
    Listen 443
</IfModule>

然后重启apache服务即可
脚本的话正在写,晚点传到GitHub上去😂

参考链接
svn安装
Ubuntu 14.04快速搭建SVN服务器及日常操作
Ubuntu下搭建http访问方式的SVN服务器

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,835评论 4 364
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,598评论 1 295
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,569评论 0 244
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,159评论 0 213
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,533评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,710评论 1 222
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,923评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,674评论 0 203
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,421评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,622评论 2 245
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,115评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,428评论 2 254
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,114评论 3 238
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,097评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,875评论 0 197
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,753评论 2 276
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,649评论 2 271

推荐阅读更多精彩内容

  • iOS 开发 SVN 版本控制器 更多技术交流请加群 iOS技术联盟 27512466 SVN是Subversio...
    Sunny_Fight阅读 8,631评论 7 63
  • 一. SVN简介 Subversion(SVN)是一个开源的版本控制系統,也就是说Subversion管理着随时间...
    天宇_阅读 534评论 0 0
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,100评论 18 139
  • 请看这件案例: 孩子出去旅游了十天,今天第一天在家。昨晚睡前我提醒他今天按照暑假作业的计划表去完成今天的作业。孩子...
    听雨聆声阅读 796评论 1 7
  • 我抱着太阳抱着月亮抱着一盆水他们没有被耽搁一秒幸福他们在水里映衬出的脸有时我不敢看一眼水里的汗垢污渍很浅很淡多年前...
    Amaorent阿毛的空瓶子阅读 215评论 11 13