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.

    查看SVN版本

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.

    image.png

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

      svn-4

    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

      image

    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.查看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.

    查看SVN版本

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 (=).

      svn-3

    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

      svn-4

    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

      image

    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.查看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....

    snv-1

  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.

    svn-2

    Note

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

    The following shows a successful checkout.svn-5

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.

image.png

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....

    image.png

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

    The local project overwrites the repository project.

    image.png

    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.显示删除文件

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....

      image.png

    • 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.

        image.png

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

        image.png

      4. Set the file name and click Save to restore the file to its original location.image.png

  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?

image

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

    Output similar to the following indicates the SVN service is running. If not, run sudo svnserve -d -r /var/svn/svnrepos/ to start it.查看SVN服务状态

  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