阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Ubuntu 12.04 64位上搭建SVN服务器

127次阅读
没有评论

共计 6649 个字符,预计需要花费 17 分钟才能阅读完成。

前情提要:福无双至,祸不单行。这句话映射到程序员身上就是不但笔记本电脑进厂了,而且连电脑上近一个月写的代码也丢了。欲哭无泪之际,开始思量着给自己的代码找个安身之所。说起鄙人那堆可怜的代码。最开始的时候,是在台式机上装了本地的 SVN 服务器。代码不出门,全在家里住。那会毕业不久,写的东西少也不怎么实用。也没有代码库的概念。后来积累的东西多了,遇到的很多问题都属于重复编码。家里的代码库连不上网,那拷硬盘放着呗。老板看你整天用硬盘不爽不说,代码不同步搞到千疮百孔。再后来开始用 git 了。用着还不错,就是私有化项目这一块没弄,也没敢全往上面传。直到上星期笔记本挂了,丢了几份代码。思来想去,还是得自己开个代码仓库。存到服务器上提交方便,也多份保障吧。

Linux 中 Subversion 配置实例 http://www.linuxidc.com/Linux/2012-02/53109.htm

CentOS 6.2 SVN 搭建 (YUM 安装) http://www.linuxidc.com/Linux/2013-10/91903.htm

Apache+SVN 搭建 SVN 服务器 http://www.linuxidc.com/Linux/2013-03/81379.htm

Windows 下 SVN 服务器搭建和使用 + 客户端重新设置密码 http://www.linuxidc.com/Linux/2013-05/85189p5.htm

Ubuntu Server 12.04 安装 SVN 并迁移 Virtual SVN 数据 http://www.linuxidc.com/Linux/2013-05/84695.htm

Ubuntu Server 搭建 svn 服务以及迁移方法 http://www.linuxidc.com/Linux/2013-05/84693.htm

借助网盘搭建 SVN 服务器 http://www.linuxidc.com/Linux/2013-10/91271.htm

1  程序安装

1.1  sudo apt-get install apache2

安装 apache2。如果你已经装了 nginx 的话。先将 nginx 停掉。他使用的 80 端口和后面安装的 apache2 会冲突。如:/etc/init.d/nginx stop。

安装完之后,如无意外会出现如下报错:

apache2: Could not reliably determinethe server’s fully qualified domain name, using 127.0.0.1 for ServerName

在 /etc/apache2/httpd.conf(此文件此时为空,是正常的)中增加下面一行:

ServerName 127.0.0.1:80

重启 apache2,执行 /etc/init.d/apache2restart。出现如下字段表示重启成功。

    root@xxxxx:/etc/apache2#/etc/init.d/apache2 restart
      * Restarting web server apache2
    … waiting  …done.

1.2  sudoapt-get install subversion

安装 subversion。略过。

1.3  sudoapt-get install libapache2-svn

安装连接插件。略过。

2  权限

2.1  相关用户、组的设定

执行下面命令:

sudoaddgroup subversion
sudousermod -G subversion -a www-data

查看结果:

    cat /etc/group|grep subversion
    subversion:x:1001:www-data

2.2  Apache2 挂载 SVN 模块(通过 http:// 访问)

通过 WebDAV 协议访问 SVN 文件仓库,必须在 /etc/apache2/mods-available/dav_svn.conf 中加入下面的代码片段:

    <Location/svn/>
        DAV svn
        SVNParentPath /home/svn
        SVNListParentPath On
        AuthType Basic
        AuthName “Subversion Repository”
        AuthUserFile /home/svn/conf/dav_svn.passwd
        AuthzSVNAccessFile/home/svn/conf/dav_svn.authz
        Require valid-user
    </Location>
    RedirectMatch^(/svn)$ $1/

2.3  用户设置

新建 /home/svn/conf 目录。为用户设置密码,会以加密方式保存 (-c 是新建的意思,去掉就是追加)。后面会提示你输入对应密码的。

    htpasswd -c /home/svn/conf/dav_svn.passwd user_1
    htpasswd  /home/svn/conf/dav_svn.passwd user_2

新建 dav_svn.authz 文件,加入如下代码。

    [groups]
    admin=user_1
    user=user_2
    [/]
    @admin = rw
    @user = r

重启 apache2。/etc/init.d/apache2 restart

如无意外会出现如下报错

    Syntax error on line 65 of/etc/apache2/mods-enabled/dav_svn.conf:
    Invalid command’AuthzSVNAccessFile’, perhaps misspelled or defined by a module not included inthe server configuration
    Action ‘configtest’ failed.
    The Apache error log mayhave more information.
        …fail!

原因是没有载入模块。在 /etc/apache2/mods-available/dav_svn.load 加入下面代码。

LoadModule authz_svn_module/usr/lib/apache2/modules/mod_authz_svn.so

再执行重启 /etc/init.d/apache2restart 就正常了。

更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2014-06/102562p2.htm

2.4 创建仓库

在 /home/svn/ 目录下新建 test 目录:mkdir test。

sudochown -R root:subversion test

sudosvnadmin create /home/svn/test

目录授权

sudochmod -R g+rws test

执行查看命令 ls test 会发现下面出现如下文件。表示仓库已建好。

conf db format hooks locks README.txt

2.5 验证

重启 SVN 服务器:killall svnserve; svnserve -d -r/home/svn/

重启 apache2 服务器:/etc/init.d/apache2 restart

在浏览器打开 http://localhost/svn/test。输入用户密码就能看到目录结构了。

后记:

很大机会你会遇到 403 禁止访问页面。网上有很多解决方法。

如我主要参考的是:http://blog.csdn.net/Ivy_yayaxueyu/article/details/1779653。

You don’t have permission to access /svn/ on this server.

——————————————————————————–

Apache/2.2.22 (Ubuntu) Server at 127.0.0.1 Port80

但都不是我遇到的。我应该是被官方文档给坑了。

当时是按照官方的配置来配 /etc/apache2/mods-available/dav_svn.conf 文件如下。但是就是因为加上了 <LimitExcept GET PROPFIND OPTIONS REPORT></LimitExcept> 一直报 403。去掉就好了。后来看了一下说明应该还要加一个模块才能实现 module(enable it with ‘a2enmod’)。我就不加了,直接去掉。

</pre><p><pre name=”code” class=”html”><Location /svn/>
DAV svn
SVNParentPath /home/svn
SVNListParentPath On
AuthType Basic
AuthName “Subversion Repository”
AuthUserFile /home/svn/conf/dav_svn.passwd
AuthzSVNAccessFile /home/svn/conf/dav_svn.authz
<LimitExcept GET PROPFIND OPTIONS REPORT>
Require valid-user
</LimitExcept>
</Location>

如果出现报错

Can’t open‘/home/svn/test/txn-current-lock’:Permissiondenied

那就重新给他设置一下权限吧

sudo chown -R root:subversion test

更多 Ubuntu 相关信息见 Ubuntu 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=2

前情提要:福无双至,祸不单行。这句话映射到程序员身上就是不但笔记本电脑进厂了,而且连电脑上近一个月写的代码也丢了。欲哭无泪之际,开始思量着给自己的代码找个安身之所。说起鄙人那堆可怜的代码。最开始的时候,是在台式机上装了本地的 SVN 服务器。代码不出门,全在家里住。那会毕业不久,写的东西少也不怎么实用。也没有代码库的概念。后来积累的东西多了,遇到的很多问题都属于重复编码。家里的代码库连不上网,那拷硬盘放着呗。老板看你整天用硬盘不爽不说,代码不同步搞到千疮百孔。再后来开始用 git 了。用着还不错,就是私有化项目这一块没弄,也没敢全往上面传。直到上星期笔记本挂了,丢了几份代码。思来想去,还是得自己开个代码仓库。存到服务器上提交方便,也多份保障吧。

Linux 中 Subversion 配置实例 http://www.linuxidc.com/Linux/2012-02/53109.htm

CentOS 6.2 SVN 搭建 (YUM 安装) http://www.linuxidc.com/Linux/2013-10/91903.htm

Apache+SVN 搭建 SVN 服务器 http://www.linuxidc.com/Linux/2013-03/81379.htm

Windows 下 SVN 服务器搭建和使用 + 客户端重新设置密码 http://www.linuxidc.com/Linux/2013-05/85189p5.htm

Ubuntu Server 12.04 安装 SVN 并迁移 Virtual SVN 数据 http://www.linuxidc.com/Linux/2013-05/84695.htm

Ubuntu Server 搭建 svn 服务以及迁移方法 http://www.linuxidc.com/Linux/2013-05/84693.htm

借助网盘搭建 SVN 服务器 http://www.linuxidc.com/Linux/2013-10/91271.htm

1  程序安装

1.1  sudo apt-get install apache2

安装 apache2。如果你已经装了 nginx 的话。先将 nginx 停掉。他使用的 80 端口和后面安装的 apache2 会冲突。如:/etc/init.d/nginx stop。

安装完之后,如无意外会出现如下报错:

apache2: Could not reliably determinethe server’s fully qualified domain name, using 127.0.0.1 for ServerName

在 /etc/apache2/httpd.conf(此文件此时为空,是正常的)中增加下面一行:

ServerName 127.0.0.1:80

重启 apache2,执行 /etc/init.d/apache2restart。出现如下字段表示重启成功。

    root@xxxxx:/etc/apache2#/etc/init.d/apache2 restart
      * Restarting web server apache2
    … waiting  …done.

1.2  sudoapt-get install subversion

安装 subversion。略过。

1.3  sudoapt-get install libapache2-svn

安装连接插件。略过。

2  权限

2.1  相关用户、组的设定

执行下面命令:

sudoaddgroup subversion
sudousermod -G subversion -a www-data

查看结果:

    cat /etc/group|grep subversion
    subversion:x:1001:www-data

2.2  Apache2 挂载 SVN 模块(通过 http:// 访问)

通过 WebDAV 协议访问 SVN 文件仓库,必须在 /etc/apache2/mods-available/dav_svn.conf 中加入下面的代码片段:

    <Location/svn/>
        DAV svn
        SVNParentPath /home/svn
        SVNListParentPath On
        AuthType Basic
        AuthName “Subversion Repository”
        AuthUserFile /home/svn/conf/dav_svn.passwd
        AuthzSVNAccessFile/home/svn/conf/dav_svn.authz
        Require valid-user
    </Location>
    RedirectMatch^(/svn)$ $1/

2.3  用户设置

新建 /home/svn/conf 目录。为用户设置密码,会以加密方式保存 (-c 是新建的意思,去掉就是追加)。后面会提示你输入对应密码的。

    htpasswd -c /home/svn/conf/dav_svn.passwd user_1
    htpasswd  /home/svn/conf/dav_svn.passwd user_2

新建 dav_svn.authz 文件,加入如下代码。

    [groups]
    admin=user_1
    user=user_2
    [/]
    @admin = rw
    @user = r

重启 apache2。/etc/init.d/apache2 restart

如无意外会出现如下报错

    Syntax error on line 65 of/etc/apache2/mods-enabled/dav_svn.conf:
    Invalid command’AuthzSVNAccessFile’, perhaps misspelled or defined by a module not included inthe server configuration
    Action ‘configtest’ failed.
    The Apache error log mayhave more information.
        …fail!

原因是没有载入模块。在 /etc/apache2/mods-available/dav_svn.load 加入下面代码。

LoadModule authz_svn_module/usr/lib/apache2/modules/mod_authz_svn.so

再执行重启 /etc/init.d/apache2restart 就正常了。

更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2014-06/102562p2.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-20发表,共计6649字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中