在Ubuntu上通过Apache Web服务器和DAV启用Subversion访问

qcuzuvrc  于 2022-11-16  发布在  Apache
关注(0)|答案(1)|浏览(156)

我有一个Ubuntu 20运行在我的家庭网络上的PC上,我想把它作为我家里的本地网络上的Subversion服务器.我已经安装了Apache web服务器和Subversion,现在我想使用HTTP DAV协议通过Apache web服务器添加访问权限.
我打算在Windows PC上使用Visual Studio和Ankh插件,在Ubuntu服务器上使用Subversion来存储我的源代码库。
目前修改Apache配置以支持使用HTTP访问Subversion的方法是什么?到目前为止,我找到的指导似乎信息有点少,无非是一系列要使用的命令,而且出于某种原因,它们看起来很旧。
在我看来,由于我支持本地网络上的单个用户,我需要:

  • 创建Subversion资源库
  • 修改位于文件夹/etc/apache2/mods-enabled中的文件dav_svn.conf
  • 重新启动Apache

完成以上操作后,我应该能够使用Ankh插件通过诸如https://192.168.0.4/svn/的URL访问我的Subversion仓库,假设我的Ubuntu服务器位于本地家庭网络上的IP地址192.168.0.4
我目前所在的位置:

  • Apache已安装并正在运行和提供页面
  • Subversion与libapache 2-mod-svn沿着安装
  • 我尚未创建Subversion资源库

Apache和Subversion的版本为:

rick@rick-MS-7B98:/etc/apache2/mods-enabled$ apache2 -version
Server version: Apache/2.4.41 (Ubuntu)
Server built:   2020-08-12T19:46:17

rick@rick-MS-7B98:/etc/apache2/mods-enabled$ svn --version
svn, version 1.13.0 (r1867053)
   compiled Mar 24 2020, 12:33:36 on x86_64-pc-linux-gnu

我在文件夹/etc/apache2/mods-enabled中发现了一个文件dav_svn.conf,它似乎是一个通过Apache访问Subversion的DAV配置文件,该文件包含:

rick@rick-MS-7B98:/etc/apache2/mods-enabled$ cat 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>

  # Uncomment this to enable the repository
  #DAV svn

  # Set this to the path to your repository
  #SVNPath /var/lib/svn
  # 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 or SVNParentPath, but not both.
  #SVNParentPath /var/lib/svn

  # 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').
  #<LimitExcept GET PROPFIND OPTIONS REPORT>
    #Require valid-user
  #</LimitExcept>

#</Location>
6rqinv9w

6rqinv9w1#

要允许Subversion通过Apache Web服务器访问仓库,需要完成的任务列表如下:

  • 需要安装Apache的Subversion模块,
  • 必须修改文件/etc/apache2/mods-enabled/dav_svn.conf以将Subversion模块包含到Apache示例中,
  • Subversion仓库必须创建在Apache可以访问的目录中,并且
  • Apache Web服务器已重新启动。

首先,确保通过Apache启用Subversion所需的所有包都已安装,所需的库和模块都在libapache2-mod-svn包中,apt install包是随apt install一起安装的.
当Apache启动时,只有/etc/apache2/mods-enabled中列出的.conf.load文件会被处理。检查位于/etc/apache2/mods-available中的dav*文件(dav.loaddav_svn.loaddav_svn.conf)的必要符号链接是否位于/etc/apache2/mods-enabled目录中。
文件dav_svn.conf指定了Apache服务器查找正确目录所需的Subversion仓库的信息,以及如何执行用户验证。文件.load指示Apache需要加载哪些库才能以编程方式访问仓库。所需的库在随apt install一起安装的libapache2-mod-svn包中。

**注意:**在处理这个问题的时候,我曾经遇到过aptdpkg的错误,因为我试图删除和清理Subversion和Apache安装以便重新安装它们。请参见“未知的DAV提供程序:svn”在重新安装后用Subversion服务器启动Apache Web服务器时,这是我在askubuntu stackexchange上发布的一个帖子,我这样做是为了寻求帮助.

我使用的dav_svn.conf文件如下:

rick@rick-MS-7B98:/etc/apache2/mods-enabled$ cat 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>

  # Uncomment this to enable the repository
  DAV svn

  # Set this to the path to your repository
  SVNPath /srv/svn
  # 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 or SVNParentPath, but not both.
  #SVNParentPath /var/lib/svn

  # 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
  Require valid-user

  # 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').
  #<LimitExcept GET PROPFIND OPTIONS REPORT>
    #Require valid-user
  #</LimitExcept>

</Location>

一旦我修改了文件,我就使用命令sudo systemctl restart apache2重新启动Apache2 Web服务器,一切都很好。
我必须创建密码文件/etc/apache2/dav_svn.passwd,该文件在dav_svn.conf文件的AuthUserFile指令中指定。
我使用的是标准的Subversion仓库路径/srv/svn,它是在dav_svn.conf文件的SVNPath指令中指定的.我使用命令sudo svnadmin create /srv/svn来创建仓库.
接下来,我使用sudo svn mkdir命令创建了一个已有的Subversion仓库(trunkrelease,和branches)的目录树,我需要复制这个仓库,以便使用svnadmin load将一个Subversion转储文件加载到我的新仓库中.请参见How do I export (and then import) a Subversion repository?

安装新的SSD,以便通过桑巴舞和WebDAV使用

我想添加一个新的500GB三星固态硬盘到我的Ubuntu 20.04 PC的额外文件服务器空间,以允许共享文件在我的局域网使用桑巴舞,以允许一个Windows网络驱动器和一个WebDAV服务器访问通过Apache2 Web服务器运行在Ubuntu PC。
我做的第一件事就是把新的500GB三星EVO 860 SSD安装到盒子里,并给它通电。
接下来,我必须为Linux化驱动器,创建mount点,然后通过在/etc/fstab中添加一个条目来确保在Ubuntu启动时自动挂载它。
我选择的挂载点是/srv/ssda,桑巴舞和WebDAV之间共享的文件夹是public,因此共享区域的路径是/srv/ssda/public。我还决定在samba共享的名称Ssda和WebDAV路径ssdadav中使用ssda
我选择/srv而不是/mnt作为根目录,因为我已经在/srv中使用了一个文件夹作为桑巴舞共享。
接下来,我修改了桑巴舞配置文件/etc/samba/smb.conf,在我先前创建的现有samba文件共享下添加了新文件夹共享的定义,并重新启动了samba。

[Ssda]
path = /srv/ssda/public
browsable =yes
writable = yes
guest ok = yes
read only = no
create mask = 644

接下来,我修改了Apache2配置文件/etc/apache2/sites-enabled/000-default.conf,并在现有的WebDAV条目下面添加了AliasDirectory指令,使用与桑巴舞共享相同的路径。

Alias /ssdadav /srv/ssda/public

    <Directory /srv/ssda/public>
        DAV On
    </Directory>

此时,我可以坐在Windows 10 PC上,使用Map network drive...连接到新的SSD,并在那里创建一个简单的文本文件。然后在Ubuntu PC上使用http://192.168.0.4/ssdadav/的URL打开一个到Apache服务器的浏览器,在文件列表中看到该文本文件,并在浏览器中打开它。

相关问题