Configure the svn server in ahjesus Ubuntu

Source: Internet
Author: User
Tags addgroup svn update

Reprinted from the http://www.cnblogs.com/ximu/articles/2119136.html test available, SVN Installation
1. Installation Package
$ Sudo apt-get install subversion

2. Add svn management users and subversion groups
$ Sudo adduser svnuser
$ Sudo addgroup subversion
$ Sudo addgroup svnuser subversion

3. Create a project directory
$ Sudo mkdir/home/svn
$ Cd/home/svn
$ Sudo mkdir fitness
$ Sudo chown-R root: subversion fitness
$ Sudo chmod-R g + rws fitness

4. Create an SVN File Repository
$ Sudo svnadmin create/home/svn/fitness

5. Access methods and project import:
$ Svn co file: // home/svn/fitness
Or
$ Svn co file: // localhost/home/svn/fitness
* Note:
If you are not sure about the host name, you must use three slashes (//). If you specify the Host Name, you must use two slashes (//).
//--
The following command is used to import a project to the SVN File Repository:
$ Svn import-m "New import"/home/svn/fitness file: // home/svnuser/src/fitness
Be sure to indicate the import information

//--------------------------//
6. access permission settings
Modify the/home/svn/fitness directory:
Svnserve. conf, passwd, and authz files. spaces are not allowed at the front end of the row.
//--
Edit the svnserve. conf file and uncomment the following two lines.
Password-db = password
Authz-db = authz

// Additional instructions
# [General]
Anon-access = read
Auth-access = write
Password-db = passwd
Here, anon-access and auth-access are respectively anonymous and permission granted to authorized users. By default, anonymous users are granted read-only permissions.

You only need to change read to none to achieve the purpose of user access.

//--
Edit/home/svnuser/etc/passwd as follows:
[Users]
Mirze= 123456
Test 1 = 123456
Test 2 = 123456
//--
Edit/home/svnuser/etc/authz as follows:
[Groups]
Admin = mirze, test1
Test = test2
[/]
@ Admin = rw
* = R
Here we have set up three users, mirze, test1, and test2, all of which are 123456 passwords.
Among them, mirze and test1 belong to the admin group and have the read and write permissions. test2 belongs to the test group and only has the read permission.

7. Start the SVN Service
Svnserve-d-r/home/svn
Description:
-D indicates that svnserver runs in "daemon" process mode
-R specifies the root location of the file system (the root directory of the version Library), so that the client can access the version library without entering the full path.
For example, svn: // 192.168.12.118/fitness

The SVN installation is complete.
LAN access method:
Example: svn checkout svn: // 192.168.12.118/fitness -- username mirze -- password 123456/var/www/fitness


-----------------------------------------------------------------------

Ii. HTTP: // [apache]
1. Installation Package [subversion installed]
$ Sudo apt-get install libapache2-svn

Create a version Repository:
Sudo svnadmin create/directory address
The directory address must exist. This is where the version repository is saved. You can create different folders for different version repositories. For example:
Sudo svnadmin create/home/svn/project
There is nothing in the/home/svn/project directory. Execute the following command and check again. There are more files and folders. We need to operate on the conf folder, there is a file named passwd in this folder to store the user name and password.
Then, authorize the repository directory of this version to read and write apache:
Sudo chown-R www-data: www-data/directory address
Then go to open the apache configuration file:
Sudo gedit/etc/apache2/mod-available/dav_svn.conf

Add the following content:
<Location/project>
DAV svn
SVNPath/home/svn/project
AuthType Basic
AuthName "myproject subversion repository"
AuthUserFile/home/svn/project/conf/passwd
# <Limitaskt get propfind options report>
Require valid-user
# </Limit10000t>
</Location>

Location refers to the access address, for example, the above address.
Http: // 127.0.0.1/project
Two lines are commented out to ensure that the user name and password are required each time.
The last step is to create an access user. We recommend that you store the user name and password file in the conf folder of the current version repository, so that the version repository is too messy when there are many versions.
Because the passwd file already exists in the conf folder, add the user directly:
Sudo htpasswd-c/home/svn/project/conf/passwd test
Enter the password twice and the user laoyang will be created.
Open the/home/svn/project/conf/passwd file and open the file in the following format:
Test: WEd.83H. gealA // is followed by the encrypted password.
After creation, you need to add this user to another version repository and copy the row directly.
Restart apache.
Sudo/etc/init. d/apache2 restart


-----------------------------------------------------------------------

3. Synchronously update [hooks]

Synchronization program idea: the user submits the program to SVN, SVN triggers hooks, and processes it according to different hooks. Here post-commit is used, use post-commit to check the code to the local hard disk directory of the SVN server, and then synchronize it to the remote WEB server through rsync.

Knowledge point:
1. SVN hooks
# Start-commit triggers a transaction before committing
# Pre-commit trigger the transaction before the commit is completed
# Post-commit triggers a transaction when the commit is complete
# Pre-revprop-change
# Post-revprop-change
The scripts written with these names can implement multiple functions, which are quite powerful.
2. Use specific parameters of the synchronization command rsync
3. bash python perl can be implemented with programming capabilities in a base language

Post-commit Implementation Details
Post-commit script

Edit the file: sudo vim/home/svn/fitness/hooks/post-commit

Note: after the post-commit is edited, run sudo chmod 755 post-commit.

Content:

#! /Bin/sh
Export LANG = zh_CN.UTF-8
Sudo/usr/bin/svn update/var/www -- username mirze -- password 123456

Or

# Set variable
SVN =/usr/bin/svn
WEB =/home/test_nokia/
RSYNC =/usr/bin/rsync
LOG =/tmp/rsync_test_nokia.log
WEBIP = "192.168.0.23"
Export LANG = en_US.UTF-8

# Update the code from the SVN
$ SVN update $ WEB -- username user -- password
# If the previous command completed successfully, to continue the following
If [$? = 0]
Then
Echo ""> $ LOG
Echo 'date'> $ LOG
Echo "###############################" >>> $ LOG
Chown-R nobody: nobody/home/test_nokia/
# Synchronization code from the SVN server to the WEB server, notes: by the key
$ RSYNC-vaztpH -- timeout = 90 -- exclude-from =/home/svn/exclude. list $ WEB root @ $ WEBIP:/www/> $ LOG
Fi

The above is the specific post-commit Program
Note:
1. variables must be defined, mainly the paths of used commands. Because of the security concerns of SVN, the system variables are not called. IF Manual execution is normal, but SVN Automatic Execution will fail.
2. Before SVN update, you must manually checkout it out, and here you must add users and passwords. If the password is only updated manually, it will not work automatically.
3. added the judgment on the previous command. If a problem occurs during update and the program does not exit, the code will continue to be synchronized to the WEB server, which may cause code problems.
4. Remember to set the owner, because rsync can synchronize file attributes, and our WEB server is generally not a root user. incorrect users may cause the WEB program to fail to work normally.
5. It is recommended that you record the log and quickly troubleshoot errors.
6. For the most critical data synchronization, the relevant parameters of rsync must be clear. Note the following scenarios:
The environment here is based on the SVN server and WEB server.
Define SVN server as the source server WEB server as the target server
Scenario 1: If the target WEB server is a comprehensive mix of resources, such as only one static WEB Resource, user-submitted resources are automatically generated under a WEB directory, we recommend that you do not use the-delete parameter.
The above code is used to update and add the source server to the target server without deleting it. The content of the WEB server is more than that of the source SVN server.
Scenario 2: implement the image, that is, the target WEB server has the same data as the source SVN server, and the-delete parameter is required for any changes on the svn web.
Scenario 3: Some subdirectories do not need to be synchronized. Some directories may be cached temporary junk directories, or specialized image directories (instead of style or typographical Directories) must use the exclude parameter.
Note: you do not need to write absolute paths for this parameter. As long as the directory name is used, aa indicates the file aa/indicates the directory, the disadvantage is that if multiple subdirectories share the same name, these names will not be synchronized.
We recommend that you use-exclude-from =/home/svn/exclude. list to conveniently add and delete objects.
Exclude. list

. Svn/
. DS_Store
Images/

SVN hooks can also be used to write many programs to control SVN. Before code submission, check whether there are logs, tabs, spaces, and files that cannot be uploaded, whether there are files that exceed the limit.

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.