Deploy and use SVN on an ECS instance

更新时间:
复制 MD 格式

Deploy Subversion (SVN) on an ECS instance with HTTP or svnserve access to manage code through checkout, update, and commit.

Prerequisites

Create an ECS instance. See Create an instance using the custom launch tab.

The instance must meet these requirements:

  • The instance has a static public IP address or an Elastic IP Address (EIP). See Enable public bandwidth.

  • Operating system: Alibaba Cloud Linux 3, Alibaba Cloud Linux 2, or CentOS 7.x.

  • Instance type: At least 4 vCPUs and 4 GiB of memory. The exact specifications depend on your project size and team size.

  • An inbound security group rule allows traffic on ports 22, 80, and 443. See Add a security group rule.

    Note

    If you use the svnserve mode, you must also allow traffic on port 3690.

Note

This tutorial supports one-click SVN deployment. Run with one click

Deploy SVN

SVN supports two access modes: HTTP and svnserve.

Feature

HTTP mode

svnserve mode

Protocol

HTTP

Custom SVN protocol

Access method

Web browser or SVN client

SVN client only

Port

80

3690

Security

HTTPS encryption

Plaintext by default; encryption optional

Configuration

Web server configuration

SVN server configuration

Feature support

More features, such as permission management and log viewing

Fewer features

Deploy SVN using HTTP

Step 1: Install SVN

  1. Connect to the Linux instance.

    See Connect to a Linux instance using Workbench.

  2. Install SVN.

    sudo yum install -y subversion
  3. Check the SVN version.

    svnserve --version

    Output similar to the following indicates SVN is installed.

    [ecs-user@iZ2zeczc    ~]$ svnserve --version
    svnserve, version 1.14.1 (r1886195)
       compiled Sep 29 2022

Step 2: Install Apache

  1. Install httpd.

    sudo yum install httpd -y
  2. Check the httpd version.

    httpd -version

    Output similar to the following indicates httpd is installed.

    [ecs-user@iZ2zeczd    ~]$ httpd -version
    Server version: Apache/2.4.6 (AlibabaCloudLinux)
    Server built:   May 26 2023 16:19:35

Step 3: Install mod_dav_svn

mod_dav_svn is an Apache module that provides web access to SVN repositories.

Install mod_dav_svn.

sudo yum install mod_dav_svn -y

Step 4: Configure SVN

  1. Create an SVN repository.

    sudo mkdir /var/svn
    cd /var/svn
    sudo svnadmin create /var/svn/svnrepos
  2. Change the user group of the SVN repository to apache.

    sudo chown -R apache:apache /var/svn/svnrepos
  3. View the automatically generated repository files.

    cd svnrepos
    ls

    The following table describes the directories in Subversion.

    Contents

    Description

    db

    Stores all version control data files.

    hooks

    Stores hook script files.

    locks

    Tracks clients that access the repository.

    format

    A text file containing an integer that indicates the repository configuration version.

    conf

    The SVN repository configuration file, containing access accounts and permissions.

  4. Run a command to add a user and password for the SVN repository.

    By default, SVN uses plaintext passwords, but HTTP requires hashed passwords. Generate a separate passwd file. In this example, a user named userTest with password passWDTest is added. Run one of the following commands:

    • To add the first user, use the -c parameter to create the file.

      sudo htpasswd -c /var/svn/svnrepos/conf/passwd userTest
    • To add more users after the first, omit -c.

      sudo htpasswd /var/svn/svnrepos/conf/passwd userTest

    Set the password as prompted.

  5. Go to the conf directory.

    cd /var/svn/svnrepos/conf/
  6. Set read and write permissions for the account.

    1. Open the access control file.

      sudo vim authz
    2. Press i to enter edit mode.

    3. Add the following code at the end of the file. userTest is the account, r is read permission, and w is write permission.

      [/]
      userTest=rw
      [aliases]
      # joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average
      [groups]
      # harry_and_sally = harry,sally
      # harry_sally_and_joe = harry,sally,&joe
      
      # [/foo/bar]
      # harry = rw
      # &joe = r
      # * =
      
      # [repository:/baz/fuz]
      # @harry_and_sally = rw
      # * = r
      
      [/]
      userTest=rw
    4. Press Esc, enter :wq, and press Enter to save and exit.

  7. Modify the SVN service configuration.

    1. Open the SVN service configuration file.

      sudo vim svnserve.conf
    2. Press i to enter edit mode.

    3. Find the following lines and remove the comment symbol (#) and leading space.

      Note

      Each line must not start with a space, and a space must exist on both sides of the equal sign (=).

      anon-access = read
      auth-access = write
      password-db = passwd
      authz-db = authz
      realm = /var/svn/svnrepos
      [general]
      ### The anon-access and auth-access options control access to the
      ### repository for unauthenticated (a.k.a. anonymous) users and
      ### authenticated users, respectively.
      ### Valid values are "write", "read", and "none".
      ### Setting the value to "none" prohibits both reading and writing;
      ### "read" allows read-only access, and "write" allows complete
      ### read/write access to the repository.
      ### The sample settings below are the defaults and specify that anonymous
      ### users have read-only access to the repository, while authenticated
      ### users have read and write access to the repository.
      anon-access = read
      auth-access = write
      ### The password-db option controls the location of the password
      ### database file.  Unless you specify a path starting with a /,
      ### the file's location is relative to the directory containing
      ### this configuration file.
      ### If SASL is enabled (see below), this file will NOT be used.
      ### Uncomment the line below to use the default password file.
      password-db = passwd
      ### The authz-db option controls the location of the authorization
      ### rules for path-based access control.  Unless you specify a path
      ### starting with a /, the file's location is relative to the
      ### directory containing this file.  The specified path may be a
      ### repository relative URL (^/) or an absolute file:// URL to a text
      ### file in a Subversion repository.  If you don't specify an authz-db,
      ### no path-based access control is done.
      ### Uncomment the line below to use the default authorization file.
      authz-db = authz
      ### The groups-db option controls the location of the file with the
      ### group definitions and allows maintaining groups separately from the
      ### authorization rules.  The groups-db file is of the same format as the
      ### authz-db file and should contain a single [groups] section with the
      ### group definitions.  If the option is enabled, the authz-db file cannot
      ### contain a [groups] section.  Unless you specify a path starting with
      ### a /, the file's location is relative to the directory containing this
      ### file.  The specified path may be a repository relative URL (^/) or an
      ### absolute file:// URL to a text file in a Subversion repository.
      ### This option is not being used by default.
      # groups-db = groups
      ### This option specifies the authentication realm of the repository.
      ### If two repositories have the same authentication realm, they should
      ### have the same password database, and vice versa.  The default realm
      ### is repository's uuid.
      realm = /var/svn/svnrepos
      ### The force-username-case option causes svnserve to case-normalize
      ### usernames before comparing them against the authorization rules in the
      ### authz-db file configured above.  Valid values are "upper" (to upper-
    4. Press Esc, enter :wq, and press Enter to save and exit.

  8. Start the SVN repository.

    This command directly specifies the repository.

    sudo svnserve -d -r /var/svn/svnrepos/
    Note

    To stop the SVN service, run the killall svnserve command.

  9. Check whether the SVN service is started.

    ps -ef |grep svn

    Output similar to the following indicates the SVN service is running.

    [ecs-user@iZ2zeczdpa5xxx conf]$ ps -ef |grep svn
    ecs-user  2767     1  0 16:50 ?        00:00:00 svnserve -d -r /var/svn/svnrepos/
    ecs-user  2808  2568  1  0 16:50 pts/0    00:00:00 grep --color=auto svn

Step 5: Configure Apache

  1. Create and edit the httpd configuration file.

    sudo vim /etc/httpd/conf.d/subversion.conf
  2. Press i to enter edit mode.

  3. Enter the following configuration in the subversion.conf file.

    <Location /svn>
    DAV svn
    SVNParentPath /var/svn
    AuthType Basic
    AuthName "Authorization SVN"
    AuthzSVNAccessFile /var/svn/svnrepos/conf/authz
    AuthUserFile /var/svn/svnrepos/conf/passwd
    Require valid-user
    </Location>
  4. Press Esc, enter :wq, and press Enter to save and exit.

  5. Start the Apache service.

    sudo systemctl start httpd.service

Deploy SVN using svnserve

Step 1: Install SVN

  1. Connect to the Linux instance.

    See Connect to a Linux instance using Workbench.

  2. Install SVN.

    sudo yum install -y subversion
  3. Check the SVN version.

    svnserve --version

    Output similar to the following indicates SVN is installed.

    [ecs-user@iZ2zeczc    ~]$ svnserve --version
    svnserve, version 1.14.1 (r1886195)
       compiled Sep 29 2022

Step 2: Configure SVN

  1. Create an SVN repository.

    sudo mkdir /var/svn
    cd /var/svn
    sudo svnadmin create /var/svn/svnrepos
  2. View the automatically generated repository files.

    cd svnrepos
    ls

    The following table describes the directories in Subversion.

    Contents

    Description

    db

    Stores all version control data files.

    hooks

    Stores hook script files.

    locks

    Tracks clients that access the repository.

    format

    A text file containing an integer that indicates the repository configuration version.

    conf

    The SVN repository configuration file, containing access accounts and permissions.

  3. Set a username and password for the SVN repository.

    1. Open the user configuration file.

      cd conf/
      sudo vim passwd
    2. Press i to enter edit mode.

    3. Go to the [users] section and add a username and password.

      Note

      Format: username = password. For example, userTest = passWDTest, as shown below. A space must exist on both sides of the equal sign (=).

      ### This file is an example password file for svnserve.
      ### Its format is similar to that of svnserve.conf. As shown in the
      ### example below it contains one section labelled [users].
      ### The name and password for each user follow, one account per line.
      
      [users]
      # harry = harrysecret
      # sally = sallyssecret
      userTest = passWDTest
    4. Press Esc, enter :wq, and press Enter to save and exit.

  4. Set read and write permissions for the account.

    1. Open the access control file.

      sudo vim authz
    2. Press i to enter edit mode.

    3. Add the following code at the end of the file. userTest is the account, r is read permission, and w is write permission.

      [/]
      userTest=rw
      [aliases]
      # joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average
      [groups]
      # harry_and_sally = harry,sally
      # harry_sally_and_joe = harry,sally,&joe
      
      # [/foo/bar]
      # harry = rw
      # &joe = r
      # * =
      
      # [repository:/baz/fuz]
      # @harry_and_sally = rw
      # * = r
      
      [/]
      userTest=rw
    4. Press Esc, enter :wq, and press Enter to save and exit.

  5. Modify the SVN service configuration.

    1. Open the SVN service configuration file.

      sudo vim svnserve.conf
    2. Press i to enter edit mode.

    3. Find the following lines and remove the comment symbol (#) and leading space.

      Note

      Each line must not start with a space, and a space must exist on both sides of the equal sign (=).

      anon-access = read
      auth-access = write
      password-db = passwd
      authz-db = authz
      realm = /var/svn/svnrepos
      [general]
      ### The anon-access and auth-access options control access to the
      ### repository for unauthenticated (a.k.a. anonymous) users and
      ### authenticated users, respectively.
      ### Valid values are "write", "read", and "none".
      ### Setting the value to "none" prohibits both reading and writing;
      ### "read" allows read-only access, and "write" allows complete
      ### read/write access to the repository.
      ### The sample settings below are the defaults and specify that anonymous
      ### users have read-only access to the repository, while authenticated
      ### users have read and write access to the repository.
      anon-access = read
      auth-access = write
      ### The password-db option controls the location of the password
      ### database file.  Unless you specify a path starting with a /,
      ### the file's location is relative to the directory containing
      ### this configuration file.
      ### If SASL is enabled (see below), this file will NOT be used.
      ### Uncomment the line below to use the default password file.
      password-db = passwd
      ### The authz-db option controls the location of the authorization
      ### rules for path-based access control.  Unless you specify a path
      ### starting with a /, the file's location is relative to the
      ### directory containing this file.  The specified path may be a
      ### repository relative URL (^/) or an absolute file:// URL to a text
      ### file in a Subversion repository.  If you don't specify an authz-db,
      ### no path-based access control is done.
      ### Uncomment the line below to use the default authorization file.
      authz-db = authz
      ### The groups-db option controls the location of the file with the
      ### group definitions and allows maintaining groups separately from the
      ### authorization rules.  The groups-db file is of the same format as the
      ### authz-db file and should contain a single [groups] section with the
      ### group definitions.  If the option is enabled, the authz-db file cannot
      ### contain a [groups] section.  Unless you specify a path starting with
      ### a /, the file's location is relative to the directory containing this
      ### file.  The specified path may be a repository relative URL (^/) or an
      ### absolute file:// URL to a text file in a Subversion repository.
      ### This option is not being used by default.
      # groups-db = groups
      ### This option specifies the authentication realm of the repository.
      ### If two repositories have the same authentication realm, they should
      ### have the same password database, and vice versa.  The default realm
      ### is repository's uuid.
      realm = /var/svn/svnrepos
      ### The force-username-case option causes svnserve to case-normalize
      ### usernames before comparing them against the authorization rules in the
      ### authz-db file configured above.  Valid values are "upper" (to upper-
    4. Press Esc, enter :wq, and press Enter to save and exit.

  6. Start the SVN repository.

    This command directly specifies the repository.

    sudo svnserve -d -r /var/svn/svnrepos/
    Note

    To stop the SVN service, run the killall svnserve command.

  7. Check whether the SVN service is started.

    ps -ef |grep svn

    Output similar to the following indicates the SVN service is running.

    [ecs-user@iZ2zeczdpa5xxx conf]$ ps -ef |grep svn
    ecs-user  2767     1  0 16:50 ?        00:00:00 svnserve -d -r /var/svn/svnrepos/
    ecs-user  2808  2568  1  0 16:50 pts/0    00:00:00 grep --color=auto svn

Use SVN

The typical SVN code management workflow:

  1. Checkout: Check out source code to your local computer.

  2. Other users modify and commit source code to the repository.

  3. Update: Get the latest code.

  4. You modify and debug the source code.

  5. Commit: Commit modified code to the repository. Other programmers can then see your changes.

Check out source code to a local directory (Checkout)

  1. Download and install the TortoiseSVN client on your local Windows computer.

  2. Right-click a blank area in the local project folder.

    In this example, the folder is C:\Test.

  3. In the pop-up menu, select SVN Checkout....

  4. Enter the following information and click OK:

    • URL of repository: The URL where the source code is stored.

      • HTTP access mode: The URL is in the format of http://<Public IP address of the ECS instance>/svn/<SVN repository name>.

      • svnserve access mode: The URL is in the format of svn://<Public IP address of the instance>/<SVN repository name>.

        Note

        If the SVN service was started in the parent directory of the repository, append the repository name to the SVN checkout URL.

    • Checkout directory: The local directory for the source code. In this example, C:\Test.

    Note

    On first login, enter the username and password set in the passwd file.

    After the checkout is complete, a Checkout Finished! dialog box appears, displaying At revision: 0, indicating the source code has been checked out successfully.

Obtain updates (Update)

After the server-side repository is updated, right-click a blank area in the local project folder and select SVN Update to download the latest version.

Note

SVN Update overwrites existing content in the project folder. Back up your project before updating.

Commit modifications (Commit)

Commit local modifications to the server-side repository:

  1. Right-click a blank area in the project file and select SVN Commit....

  2. Enter a version update comment, select the content to commit, and click OK.

    The local project overwrites the repository project.

    Note
    • If two users commit modifications, the later commit fails because the version is outdated. Back up your project, download the latest version from the server, overwrite the local folder with your changes, and then click SVN Commit.

    • If you delete a file in the committed project, a message similar to the following is displayed. In the Commit dialog box, enter a commit message in the Message area. The Changes made area lists the files to commit and their status (for example, test1.txt with status missing, indicating the file has been deleted from the working copy). Click OK to commit.

Revert a file

Revert a deleted file in SVN:

  1. Open the local project folder, right-click, and select SVN Checkout... to check out data.

  2. Delete one of the files.

  3. Choose the appropriate operation based on whether you have committed the modification:

    • If not yet committed, right-click a blank area and select TortoiseSVN > Revert....

    • If already committed, the server-side repository is synchronized and the file is deleted there too. Revert with the following steps:

      1. Right-click a blank area and select TortoiseSVN > Show log.

      2. Click the log entry for the deletion. The deleted data appears below.

        The Changed Paths area displays the path of the deleted file (for example, /test2.txt) and the operation type Deleted.

      3. Right-click the deleted data and click Save revision to....

      4. Set the file name and click Save to restore the file to its original location. In the save dialog box, select a save path (for example, C:\Test), enter test2.txt in the file name field, and then click Save.

  4. Open the original folder and click SVN Commit... to synchronize with the repository.

FAQ

Why am I prompted with "The host did not respond" when I use TortoiseSVN to access the SVN server?

Possible causes:

  • The SVN server is not started.

  • The required ports are not opened in the security group.

  • The firewalld firewall is enabled but the required ports are not allowed.

Troubleshoot as follows:

  1. Check the SVN service status.

    ps -ef |grep svn

    If the output includes an svnserve process, the SVN service is running. If not, run sudo svnserve -d -r /var/svn/svnrepos/ to start it.

  2. Check whether the security group rules meet the SVN server requirements.

    1. HTTP mode: ports 22, 80, and 443.

    2. svnserve mode: ports 22, 80, 443, and 3690.

  3. Check the firewalld firewall.

    1. Check the firewalld status.

      sudo firewall-cmd --state 
      • If not running is returned, the firewall is disabled and does not affect SVN.

      • If running is returned, the firewall is enabled. Proceed to the next step.

    2. Allow traffic on the required SVN port, such as port 3690.

      sudo firewall-cmd --add-port=3690/tcp --permanent
    3. Reload the firewalld configuration.

      sudo systemct