Debian + subversion for Version Control

Source: Internet
Author: User

Source: Network

As a system administrator, I really have nothing to write, but the only thing that can be referenced is my little experience. The so-called experience: I also learned from other people's articles, and then turned my own operation practices into my own, Hoho ......

Two months ago, the company finally set up a Linux server in the WAN. At the beginning, it was the so-called HTTP service and FTP service ......, Do you want to write this? However, such service articles are searched on the Internet and are everywhere. How can they be written? Alas!

Finally, I thought of a version control server. Environment:

System: Debian-sarge3.1-rc1 tools: subversiong, apache2 ...... Let's get started now.

1. install necessary software packages

The most common method of SVN is to use apache2 (this document does not cover other methods, but I have never done it before). Therefore, you need to install apache2. In general, PHP will be installed on my server because I chose the Apache apache2-mpm-prefork package. Installation command:
Shell # apt-Get install apache2-mpm-prefork libapache2-svn Subversion
The Debian package management system automatically installs the missing package.

2. Configuration

As a module of apache2, SVN is located in/etc/apache2/mod-available/dav_svn.conf under Debian (other releases may be different ). First, let's look at a configuration file example:
<Location/SVN>
Dav SVN
Svnparentpath/data/svn_repos/
Authzsvnaccessfile/etc/apache2/Erya. authz
Authtype basic
Authname "Subversion repository"
Authuserfile/etc/apache2/dav_svn.passwd
Require valid-user
</Location>

Note:

A) The First line: <location/SVN> indicates that the svn repository is located under the/SVN virtual directory (location is similar to alias ). Of course, you can use directories, such as <location/src>. In this way, you can browse through the http: // hostname/SVN browser (if you have sufficient permissions ).

B) Row 2: Dav SVN indicates that Dav enables SVN support. If you want to learn more about what Dav is, visit Baidu or Google. There are a lot of online materials.

C) Row 3: svnparentpath/data/svn_repos indicates that svnparent is used, and the physical path of the repository is/data/svn_repos.svn. Two management methods are supported for the project. One is svnparent, the other is SVN (?). I generally prefer the svnparent method, because using this method to add a new project does not need to restart Apache, And the other method does. It is very important for a server to be restarted frequently. Here, the/data/svn_repos directory must exist and the owner of the directory should be Apache users (generally www-Data In Debian ). Mkdir
-P/data/svn_repos; chown-r www-data: www-data/svn_repos. Note: The default configuration file is svnpath, that is, the last method used.

D) Row 4: authzsvnaccessfile/etc/apache2/Erya. authz. Indicates that the user permission file is/etc/apache2/Erya. authz (the permission file is written later ). Files can be located anywhere else.

E) lines 5 to 8: Apache users are often configured. This is Apache configuration, which uses Apache user files for authentication, valid users are required to access the service. If you use other user management methods, such as Pam, LDAP, or MySQL, they are the same. In fact, the configuration file comment shows how to use htpasswd for user management. Note the configuration in the fourth row and the configuration in this section. In the authz permission file, configure only the permissions of the user, however, it is implemented by Apache user management to determine whether password verification has been passed. That is to say, for example, if I have a user named qsg, This completes the process of determining whether the user's password is correct, to determine which projects the user has the permissions, The authz file completes the process.

The above configuration example is the simplest configuration. In fact, you can also use this XLST file to change the effect of viewing through the browser (I tried several times, however, the configured results are more difficult than the default ones, so simply give up .)

After the configuration is complete, go to/etc/apache2/mods_enabled to check whether the file link pointing to dav_svn.conf and dav_svn.load exists (APACHE starts the module accordingly ).

3. Create a User File

The following describes how to create a user file in the comment of dav_svn.conf:
Htpasswd2-C/etc/apache2/dav_svn.passwd JSZ

Add the user JSZ to the/etc/apache2/dav_svn.passwd file. If the file does not exist, create it.

4. Create a project warehouse

Assume that the svnparentpath directory you configured is/data/svn_repos. Enter/data/svn_repos. The directory should be empty.

Create a project warehouse in three steps: a) create a directory B) Use svnadmin to initialize the new project directory c) change the directory owner to an Apache user (In this article, we assume that you use the default www-data user ).

I wrote a small script (assuming the file name is createnew ):
#! /Bin/bash

Echo "Create a New resposity ..."
Mkdir $1
Svnadmin create $1
Chown-r www-data: www-data $1

It's easy. There are three commands. Usage:./createnew test, a test project is created. The same applies to other projects, such as./createnew project1.

Check the directory after execution. We can go to the test directory to see what you can see, unlike CVs, because SVN uses the Berkeley database to store code.

5. Recommended permission file (authz)

SVN authorization granularity can be individual users or user groups.

SVN has three permissions: no permission, read permission, and read/write permission. If you do not have the permission, access is prohibited. If you have the read permission, you can view the Code but cannot submit the code. The read/write permission is of course the maximum permission. You can add or delete read/write permissions.

SVN's depth of authorization is its biggest feature. It can not only authorize the entire project, but even separately authorize a directory and a file under the project. I think this is a very useful feature.

Let's take a look at a file example:
[Groups]
Manager = JSZ

User = user1, user2

[Test:/]
@ Manager = RW

[Test:/file1]
@ Manager = RW
User1 =
User2 = RW
Let's explain it first:

A) The groups section is used to define user groups, as its name says. For example, two maanger groups and user groups are defined in the example file.

B) project section. Each section is an authorization unit. For example, there are two project segments: Test:/and test:/file1. For test:/, the root directory of the test project is authorized, and test:/file1 indicates that the/file1 file under the test project is authorized (the directory is the same ). If we need to authorize the dir1 directory of the test project, we need to add another test:/dir1 section.

C) Authorization. If you want to authorize a project team to a certain part of a project, add the @ symbol (such as @ manager) before the group name. If you want to authorize a separate user, use the user name directly. The equal sign (=) is followed by a permission. There are three methods: NULL (no permission), R (read permission), and RW (read/write permission ). The default value is null.

D) Permission priority. You may have seen that I have granted the read permission to user1 in the test:/section, but I have no permission to user2. for files under/file1, I grant no permission to user1 and read/write permission to user2. This is the priority of permissions. The deeper the directory, the higher the permission. For example, there is a directory/dir1/dir2/dir3/dir4/file5 under test. For user1, SVN first checks whether user1 is authorized to file5. If yes, use this authorization. If no, judge the permissions of user1 on dir4 to the/directory. If the root directory is still not set, use the default permission (no permission ).

6. Restart Apache

The configuration files to be written are all written. Restart the apache service. /Etc/init. d/apache2 restart

Then you can check it in the browser: http: // hostname/SVN/test

Now we haven't added anything to SVN, so what we see is "Revision 0 :/"

7. Simple SVN ※

SVN ※in addition to the command line, the corresponding client software is available on Windows and Linux graphical interfaces.

A) Import

After initialization, there is nothing in the library, so we need to import our content first.

As a demo:
Mkdir/tmp/SVN
CD/tmp/SVN
Touch file1

SVN import http: // hostname/SVN/test-M "init" # You will be prompted to enter the user name and password. The user is the current user by default. If not, press enter and enter the user name.
Now you can view http: // hostname/SVN/test in the browser. We can see that the file is now "Revision 1:/" and we can see that the file1 file also exists.

B) checkout

In the example of checkout, the code is obtained from the svn server.

Continue the above Demonstration:
CD ..
Rm-RF SVN
SVN Co http: // hostname/SVN/test # We can see that there is an additional test directory under the tmp directory.
C) Add and commit
CD Test
VI file1 # modify the file1 File
Touch file2 # Add a file2 File
SVN stat # Check the file changes in the current directory
We can see a question mark before file2, indicating that file2 has not been added to the repository. The front of file1 is m, which indicates modification.
SVN add file2 # Add file2. The difference between add and import is that add is not directly added to the svn server, while import is. Add adds a job item.
SVN ci-M "add file2 and modify file1" # submit

Now you can view http: // hostname/SVN/test in the browser. We can see that the file is now "Revision 2:/" and we can see that the file2 file also exists.

8. FAQs

A) After configuration, the browser prompts that the permission is forbidden.

Comment out the <limitaskt get PROPFIND Options Report> and </limit10000t> lines in/etc/apache2/mod-available/dav_svn.conf. This article is only a basic configuration. If you want to understand the meaning of the two lines, you can search for them over the Internet.

Finally, if you use the subversion in combination with viewvc, then Web-based version browsing will be more perfect. We recommend a Windows client for you to use tortoisesvn with a Chinese package, easy to use.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.