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

enabling Subversion access via Apache web server and DAV on Ubuntu

我在家庭网络上的 PC 上有一个 Ubuntu 20 运行,我想将其用作我家中本地网络上的 Subversion 服务器。我安装了 Apache Web 服务器和 Subversion,现在我想使用 HTTP DAV 协议通过 Apache Web 服务器添加访问权限。

我打算在 Windows PC 上使用 Visual Studio 和 Ankh 插件,在 Ubuntu 服务器上使用 Subversion 来存储我的源代码库。

当前 mod 化 Apache 配置以启用使用 HTTP 访问 Subversion 的方法是什么?到目前为止,我发现的说明在信息上似乎有点简单,只不过是一系列要使用的命令,而且由于某种原因它们看起来很旧。

在我看来,由于我在本地网络上支持单个用户,因此我需要:

完成上述操作后,我应该能够使用 Visual Studio 的 Ankh 插件访问我的 Subversion 存储库,使用 URL 例如 https://192.168.0.4/svn/,假设我的 Ubuntu 服务器位于我本地家庭网络上的 IP 地址 192.168.0.4

我现在所在的位置:

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,它似乎是 DAV 通过 Apache 访问 Subversion 的配置文件。该文件包含:

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>

需要修改文件 /etc/apache2/mods-enabled/dav_svn.conf,创建 Subversion 存储库,并重新启动 Apache 网络服务器,以便允许通过 Apache 网络服务器访问 Subversion 存储库。

首先检查位于 /etc/apache2/mods-availabledav* 文件(dav.loaddav_svn.loaddav_svn.conf)的必要符号链接是否在目录 /etc/apache2/mods-enabled,因为只有 .conf.load 中列出的文件会在 Apache 启动时被处理。

文件dav_svn.conf 指定了有关 Apache 服务器找到正确目录所需的 Subversion 存储库以及如何执行用户身份验证的信息。 .load 文件指示 Apache 需要加载哪些库才能以编程方式访问存储库。所需的库位于随 apt install.

一起安装的 libapache2-mod-svn 软件包中

注意: 在处理这个问题时,我 运行 遇到 aptdpkg 错误的问题删除并清理 Subversion 和 Apache 安装以便重新安装它们。请参阅 “Unknown DAV provider: svn” when starting up Apache web server with Subversion server after reinstall 这是我为了寻求帮助而在 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 网络服务器,一切正常。

我必须创建密码文件 /etc/apache2/dav_svn.passwd,它在 dav_svn.conf 文件的 AuthUserFile 指令中指定。

我正在使用 /srv/svn 的标准 Subversion 存储库路径,如 dav_svn.conf 文件的 SVNPath 指令中指定的那样。我使用命令 sudo svnadmin create /srv/svn 创建存储库。

接下来,我使用 sudo svn mkdir 命令创建了我需要复制的现有 Subversion 存储库(trunkreleasebranches)的目录树为了使用 svnadmin load 将 Subversion 转储文件加载到我的新存储库中。参见 How do I export (and then import) a Subversion repository?

安装新的 SSD 以通过 samba 和 webDAV 使用

我想在我的 Ubuntu 20.04 PC 上添加一个新的 500GB 三星 SSD 作为额外的文件服务器 space 以允许使用两个 samba 在我的 LAN 上共享文件以允许 Windows 网络驱动器和通过 Ubuntu PC 上的 Apache2 Web 服务器 运行 访问的 webDAV 服务器。

我做的第一件事是将新的 500GB Samsung EVO 860 SSD 安装到盒子中并启动它。

接下来我必须为 Linux 格式化驱动器,创建 mount 点,然后通过添加条目确保它在 Ubuntu 启动时自动挂载进入 /etc/fstab.

我选择的挂载点是/srv/ssda,samba和webDAV共享的文件夹是public,所以共享区的路径是/srv/ssda/public。我还决定在 samba 共享 Ssda 和 webDAV 路径 ssdadav.

的名称中使用 ssda

我选择 /srv 作为根而不是 /mnt,因为我已经在 /srv 中使用一个文件夹作为 samba 共享。

接下来我修改了 samba 配置文件 /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 条目下添加了额外的 webDAV 条目以及 AliasDirectory 指令,使用与我用于桑巴分享。我重新启动了 Apache。

    Alias /ssdadav /srv/ssda/public

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

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