All Products
Search
Document Center

Elastic Compute Service:Deploy and use SVN

Last Updated:Oct 16, 2024

Subversion (SVN) is an open source version control system that allows you to look at previous file versions and track their changes over time. You can use SVN to create branches to work on multiple versions of your files or data. This topic describes how to deploy and use SVN.

SVN

The data that SVN manages is stored in a repository. It maintains a complete history of every change ever made to your files. You can roll back to a previous version or retrieve the change history of files from the repository. The following terms or operations are commonly used in SVN:

  • Repository: stores source code.

  • Checkout: checks out source code from the repository to create a working copy on your on-premises device.

  • Commit: commits modified code to the repository.

  • Update: synchronizes source code from the repository to a working copy on your on-premises device.

Preparations

Create an Elastic Compute Service (ECS) instance. For more information, see Create an instance on the Custom Launch tab.

Make sure that the ECS instance meets the following requirements:

  • The instance is associated with a static public IP address (also called auto-assigned or system-assigned public IP address) or an elastic IP address (EIP). For information about how to associate an EIP with an instance, see Associate or disassociate an EIP.

  • The instance runs an Alibaba Cloud Linux 3, Alibaba Cloud Linux 2, or CentOS 7.x operating system.

  • The instance type of the instance meets the requirements for deploying SVN. Select an instance type during instance creation based on your project scale and your team size. We recommend that you use an instance type with four or more vCPUs and 4 GiB or more of memory.

  • An inbound rule is added to a security group of the instance to allow traffic on ports 22, 80, and 443. For information about how to add an inbound security group rule, see Add a security group rule.

    Note

    If you want to access SVN by using svnserve, add an inbound security group rule to open port 3690.

SVN access methods

You can access SVN over HTTP or by using svnserve based on your business requirements. The following table describes the differences between the access methods.

Item

SVN access over HTTP

SVN access by using svnserve

Protocol

HTTP.

Custom SVN protocol.

Access mode

Web browsers or clients.

Only clients.

Port

Port 80.

Port 3690.

Security

HTTPS for encrypted communication.

Plaintext communication by default. You can complete encryption settings to encrypt communication.

Configuration

Configurations on the web server.

Configurations on the SVN server.

Feature

More features, such as access control and log query.

Fewer and simpler features.

Deploy SVN with HTTP access

Step 1: Install SVN

  1. Connect to the Linux instance on which you want to install SVN.

    For more information, see Connect to a Linux instance by using a password or key.

  2. Run the following command to install SVN:

    sudo yum install -y subversion
  3. Run the following command to check the SVN version:

    svnserve --version

    The following command output indicates that SVN is installed.

    查看SVN版本

Step 2: Install the Apache HTTP Server (httpd)

  1. Run the following command to install httpd:

    sudo yum install httpd -y
  2. Run the following command to check the httpd version:

    httpd -version

    The following command output indicates that httpd is installed.

    image.png

Step 3: Install mod_dav_svn

mod_dav_svn is an Apache HTTP Server (httpd) module that provides web access to SVN.

Run the following command to install mod_dav_svn:

sudo yum install mod_dav_svn -y

Step 4: Configure SVN

  1. Run the following commands in sequence to create an SVN repository:

    sudo mkdir /var/svn
    cd /var/svn
    sudo svnadmin create /var/svn/svnrepos
  2. Run the following command to change the user group of the SVN repository to apache:

    sudo chown -R apache:apache /var/svn/svnrepos
  3. Run the following commands in sequence to check the files that are automatically generated in the SVN repository:

    cd svnrepos
    ls

    查看版本库文件

    The following table describes the SVN directories and files.

    Directory or file

    Description

    db

    The directory that stores version-control data files.

    hooks

    The directory that stores hook scripts.

    locks

    The directory that stores the SVN repository lock files and can be used to track accesses to the repository.

    format

    The text file that contains a single integer value, which indicates the version number of the SVN repository.

    conf

    The SVN repository configuration file that stores the usernames and access permissions of the repository.

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

    Passwords for SVN are stored in plaintext, but HTTP does not support plaintext passwords. Therefore, you need to create a separate file named passwd. In this example, the username is userTest and the password is passWDTest. Run one of the following commands to create the passwd file.

    • The first time that you add a user for the SVN repository, run the following command with the -c parameter to create the passwd file:

      sudo htpasswd -c /var/svn/svnrepos/conf/passwd userTest
    • If this is not the first time that you add a user for the SVN repository, run the following command to create the passwd file:

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

    Configure the password of the user as prompted.

  5. Run the following command to go to the conf directory:

    cd /var/svn/svnrepos/conf/
  6. Configure the read and write permissions for the user.

    1. Run the following command to open the access control file:

      sudo vim authz
    2. Press the I key to enter Insert mode.

    3. Move the pointer over the end of the file and add the following code to grant the read (r) and write (w) permissions to the user (userTest):

      [/]
      userTest=rw

      svn-4

    4. Press the Esc key to exit Insert mode, enter :wq, and then enter the Enter key to save and close the file.

  7. Modify the configurations of SVN.

    1. Run the following command to open the configuration file of SVN:

      sudo vim svnserve.conf
    2. Press the I key to enter Insert mode.

    3. Move the pointer over the following lines and delete the number sign (#) and spaces from the beginning of each line.

      Note

      Lines cannot start with spaces. A space is required before and after each equal sign (=).

      anon-access = read
      auth-access = write
      password-db = passwd
      authz-db = authz
      realm = /var/svn/svnrepos

      修改svn服务配置

    4. Press the Esc key to exit Insert mode, enter :wq, and then enter the Enter key to save and close the file.

  8. Start the SVN repository.

    Run the following command that includes the absolute path to the SVN repository to start the repository:

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

    You can run the killall svnserve command to stop the SVN service.

  9. Run the following command to check whether the SVN service is started:

    ps -ef |grep svn

    The following command output indicates that the SVN service is started.查看SVN服务状态

Step 5: Configure Apache

  1. Run the following command to add and edit the httpd configuration file:

    sudo vim /etc/httpd/conf.d/subversion.conf
  2. Press the I key to enter Insert mode.

  3. Add the following information to 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 the Esc key to exit Insert mode, enter :wq, and then enter the Enter key to save and close the file.

  5. Run the following command to start the httpd service:

    sudo systemctl start httpd.service

Deploy SVN with svnserve-based access

Step 1: Install SVN

  1. Connect to the Linux instance on which you want to install SVN.

    For more information, see Connect to a Linux instance by using a password or key.

  2. Run the following command to install SVN:

    sudo yum install -y subversion
  3. Run the following command to check the SVN version:

    svnserve --version

    The following command output indicates that SVN is installed.

    查看SVN版本

Step 2: Configure SVN

  1. Run the following commands in sequence to create an SVN repository:

    sudo mkdir /var/svn
    cd /var/svn
    sudo svnadmin create /var/svn/svnrepos
  2. Run the following commands in sequence to check the files that are automatically generated in the SVN repository:

    cd svnrepos
    ls

    查看版本库文件

    The following table describes the SVN directories and files.

    Directory or file

    Description

    db

    The directory that stores version-control data files.

    hooks

    The directory that stores hook scripts.

    locks

    The directory that stores the SVN repository lock files and can be used to track accesses to the repository.

    format

    The text file that contains a single integer value, which indicates the version number of the SVN repository.

    conf

    The SVN repository configuration file that stores the usernames and access permissions of the repository.

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

    1. Run the following commands to open the user configuration file:

      cd conf/
      sudo vim passwd
    2. Press the I key to enter Insert mode.

    3. Move the pointer over [users] and add a username and a password.

      Note

      Set the username and password in the following format: username = password. Example: userTest = passWDTest, as shown in the following figure. A space is required before and after the equal sign (=).

      svn-3

    4. Press the Esc key to exit Insert mode, enter :wq, and then enter the Enter key to save and close the file.

  4. Configure the read and write permissions for the user.

    1. Run the following command to open the access control file:

      sudo vim authz
    2. Press the I key to enter Insert mode.

    3. Move the pointer over the end of the file and add the following code to grant the read (r) and write (w) permissions to the user (userTest):

      [/]
      userTest=rw

      svn-4

    4. Press the Esc key to exit Insert mode, enter :wq, and then enter the Enter key to save and close the file.

  5. Modify the configurations of SVN.

    1. Run the following command to open the configuration file of SVN:

      sudo vim svnserve.conf
    2. Press the I key to enter Insert mode.

    3. Move the pointer over the following lines and delete the number sign (#) and spaces from the beginning of each line.

      Note

      Lines cannot start with spaces. A space is required before and after each equal sign (=).

      anon-access = read
      auth-access = write
      password-db = passwd
      authz-db = authz
      realm = /var/svn/svnrepos

      修改svn服务配置

    4. Press the Esc key to exit Insert mode, enter :wq, and then enter the Enter key to save and close the file.

  6. Start the SVN repository.

    Run the following command that includes the absolute path to the SVN repository to start the repository:

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

    You can run the killall svnserve command to stop the SVN service.

  7. Run the following command to check whether the SVN service is started:

    ps -ef |grep svn

    The following command output indicates that the SVN service is started.查看SVN服务状态

Use SVN

This section describes the steps to manage code in SVN:

  1. Checkout: Check out source code to create a working copy on your on-premises device.

  2. Others modify the source code and commit the modifications to the repository.

  3. Update: Obtain the latest version of the source code from the repository.

  4. Change and debug the source code.

  5. Commit: Commit the modified source code to the repository. Other users can view your modifications.

Checkout: Check out source code to create an on-premises working copy

  1. Download and install the TortoiseSVN client on your on-premises Windows device.

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

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

  3. Select SVN Checkout...

    snv-1

  4. Configure the following parameters and click OK:

    • URL of repository: Enter the URL of the SVN repository.

      • If you access SVN over HTTP, enter the URL of the SVN repository in the following format: http://<Public IP address of the ECS instance>/svn/<SVN repository name>.

      • If you access SVN by using svnserve, enter the URL of the SVN repository in the following format: svn://<Public IP address of the ECS instance>/.

        Note

        When you start SVN from the parent directory of the SVN repository, the URL from which to check out source code must include the name of the SVN repository.

    • Checkout directory: Specify an on-premises directory in which to check out source code to create a working copy. In this example, the on-premises directory is C:\Test.

    svn-2

    Note

    The first time you log on to SVN, enter the username and password that you configured in the passwd file.

    The following message indicates that the checkout operation is complete.svn-5

Update: Obtain the latest version of the source code from the repository

After a project is updated in the SVN repository, you can right-click a blank area in the on-premises project folder, and then select SVN Update to pull all modifications to the project from the repository and download the latest version of the project.

image.png

Note

When you right-click a blank area in the on-premises project folder and select SVN Update, all files in the project folder are overwritten. To prevent content loss caused by the overwrite process, we recommend that you back up the original content in the project folder before performing the update operation.

Commit: Commit the modified source code to the repository

To commit on-premises modifications to the repository, perform the following steps:

  1. Right-click a blank area in the on-premises project folder and then select SVN Commit...

    image.png

  2. Enter a commit message, select the objects that you want to commit, and then click OK.

    The changes that you make on premises to the project are committed to the SVN repository and applied to the project in the repository.

    Note
    • A conflict occurs if you attempt to commit a file that already has a newer repository version. Your commit fails. To resolve the issue, back up your on-premises project, check out the latest project files from the SVN repository, change the latest project files on premises, and then commit the changed project files to the repository.

    • If a file is deleted from the project that you commit, the message shown in the following figure appears, indicating that the file is missing.显示删除文件

Restore a deleted file

After you delete a file, you can restore the file in SVN.

  1. Open the on-premises project folder, right-click a blank area in the folder, and then select SVN Checkout... to check out the latest version of the project.

  2. Delete a file.

  3. Use one of the following methods to restore the deleted file based on whether you commit the delete operation to the SVN repository:

    • If the delete operation is not committed, right-click a blank area in the on-premises project folder and choose TortoiseSVN > Revert...

      image.png

    • If the delete operation is committed, the change is synchronized to the repository and the file is deleted from the repository. Perform the following steps to restore the deleted file:

      1. Right-click a blank area and choose TortoiseSVN > Show log to view operation logs.

      2. In the logs, click the deletion log entry for the deleted file. The information about the deleted file is displayed.

        image.png

      3. Right-click the deleted file and select Save revision to...

        image.png

      4. In the Save revision to... dialog box, enter a file name and click Save to save the file to the directory from which the file was deleted.image.png

  4. Open the on-premises project folder, right-click a blank area in the folder, and then select SVN Commit... The on-premises project data is synchronized to the SVN repository.

FAQ

Why does an error message indicating that the host does not respond appear when TortoiseSVN is used to access the SVN server?

image

Cause:

  • The SVN server is not started.

  • The ports required by the SVN server are not opened in the related security group.

  • The firewalld service is started for the ECS instance, but traffic on the ports required by the SVN server is not allowed.

Solution:

  1. Check the status of SVN.

    ps -ef |grep svn

    The command output shown in the following figure indicates that the SVN service is started. If the following command output is not returned, run thesudo svnserve -d -r /var/svn/svnrepos/ command to start SVN. 查看SVN服务状态

  2. Check whether the rule of the security group to which the ECS instance belongs meet the requirements of the SVN server.

    1. SVN access over HTTP: Ports 22, 80, and 443 must be opened.

    2. SVN access by using svnserve: Ports 22, 80, 443, and 3690 must be opened.

  3. Query the firewalld service.

    1. Query the status of the firewalld service.

      sudo firewall-cmd --state 
      • If the firewalld service is in the not running state, the firewalld service is not started and has no impacts on the SVN server.

      • If the firewalld service is in the running state, the firewalld service is started. Perform the next step.

    2. Open ports such as port 3690 in the firewalld rule for SVN.

      sudo firewall-cmd --add-port=3690/tcp --per
    3. Reload the firewalld service configuration to make the modification take effect.

      sudo systemctl reload firewalld