An in-depth introduction to SVN configuration methods in Linux systems

Source: Internet
Author: User
Tags addgroup anonymous auth chmod commit svn svn update rsync


One, SVN installation
1. Installation package
$ sudo apt-get install subversion

2. Add SVN Admin user and Subversion Group
$ 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 SVN file Warehouse
$ sudo svnadmin create/home/svn/fitness

5. Access mode and Project import:
$ SVN Co file:///home/svn/fitness
Or
$ SVN Co file://localhost/home/svn/fitness
Attention
If you are unsure of the host's name, you must use three slashes (///), and if you specify the name of the host, you must use two slashes (//).

The following command is used to import the project into the SVN file warehouse:
$ 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, Authz three files, the line is not allowed to the front of a space

Edit the svnserve.conf file and uncomment the following two lines
password-db = password
Authz-db = Authz

Supplementary notes
# [General]
Anon-access = Read
auth-access = Write
Password-db = passwd
Where anon-access and auth-access are anonymous and privileged, and default to anonymous users read-only permissions, but if you want to deny

Users, you can achieve the goal simply by changing read to none.


Edit/home/svnuser/etc/passwd as follows:
[Users]
Mirze = 123456
Test1 = 123456
Test2 = 123456

Edit/home/svnuser/etc/authz as follows
[Groups]
admin = Mirze,test1
Test = Test2
[/]
@admin =RW
*=r
Three users are set up here, mirze,test1,test2 passwords are 123456.
where Mirze and test1 belong to the admin group, have read and write permission, test2 belong to the test group only Read permission
Different users assign different directory permissions
[svn:/]
@g_vip = R
@g_admin = RW
* = R
[svn:/ezhmi1.0]
@g_pm = RW
@g_coder = RW
@g_tester = R

[Svn:/ezhmi1.0/test]
@g_tester = RW
[Svn:/ezhmi1.0/trunk]
@g_tester = RW

[Svn:/document/development]
@g_pm = RW
@g_coder = RW
@g_tester = R

[Svn:/document/test]
@g_pm = R
@g_coder = R
@g_tester = RW

[Svn:/workfolder]
@g_pm = RW
@g_coder = R
@g_tester = R

7. Start SVN service
Svnserve-d-R/HOME/SVN
Description Description:
-D indicates that Svnserver is running in "daemon" process mode
-r Specifies the root location of the file system (the root of the version library) so that the client can access the version library without entering the full path
such as: svn://192.168.12.118/fitness

The SVN installation is complete.
LAN access mode:
For example: SVN checkout svn://192.168.12.118/fitness–username Mirze–password 123456/var/www/fitness

———————————————————————–

Second, http://[Apache]
1. installation package [Subversion installed]
$ sudo apt-get install LIBAPACHE2-SVN

To create a version warehouse:
sudo svnadmin Create/directory Address
The directory address must exist, this is the place to save the version warehouse, different versions of the warehouse to create different folders, such as:
sudo svnadmin create/home/svn/project
Originally/home/svn/project This directory under Nothing, execute the following command to look again, more than a few files and folders, we need to operate the Conf folder, this folder has a file, called passwd, used to store user name and password.
Then authorize this version of the warehouse directory to Apache Read and write:
sudo chown-r www-data:www-data/directory Address
Then come to open the Apache configuration file:
sudo gedit/etc/apache2/mods-available/dav_svn.conf

Add the following content:

DAV SVN
Svnpath/home/svn/project
AuthType Basic
AuthName "MyProject Subversion repository"
authuserfile/home/svn/project/conf/passwd
# Require Valid-user
#

Location said the address, such as the address above, when the visit is

Http://127.0.0.1/project

Two of these lines are commented out to ensure that the username password is required each time.
The last step is to create access to the user, we recommend that the user name password file stored in the current version of the warehouse under the Conf folder, such a version of the warehouse when there is no more chaos.
Since the passwd file already exists under the Conf folder, add the user directly:
sudo htpasswd-c/home/svn/project/conf/passwd test
Then enter the password two times, Laoyang the user is created.
Opening/HOME/SVN/PROJECT/CONF/PASSWD This file will open to text in the form as follows:
Test:wed.83h.geala//followed by the encrypted password.
Once created, you will need to add the user to another version of the warehouse and copy the line directly.
Restart Apache. Www.111Cn.net
Sudo/etc/init.d/apache2 restart

———————————————————————–

Third, synchronization update [hook]
Synchronization program idea: The user submits the program to the SVN,SVN trigger hooks, according to the different hooks processing, here uses is the Post-commit, uses the Post-commit to the code to check out to the SVN server's local hard disk directory, then passes Rsync synchronizes to a remote Web server.

Knowledge Points:
1, SVN's hooks
# triggers transaction before Start-commit commit
# Trigger Transaction before Pre-commit commit complete
# Trigger Transaction when Post-commit commit completes
# Pre-revprop-change a transaction before a version attribute is modified
# Post-revprop-change version attribute triggers transaction
Scripts written with these names can achieve a variety of functions, quite powerful.
2, synchronization command rsync specific parameters to use
3, with a basic language programming capabilities Bash Python Perl can be implemented

Post-commit Specific Implementation Details
Post-commit Script

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

Note: After editing completes Post-commit, execute: sudo chmod 755 post-commit

Content:

#!/bin/sh
Export LANG=ZH_CN. UTF-8
SUDO/USR/BIN/SVN update/var/www/www–username Mirze–password 123456

Or

Www.111cn.net

#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 password
#If the previous command compl Eted 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 procedure
Note:
1, be sure to define variables, mainly the use of the path of the command. Because SVN considers security issues, no system variables are invoked, and if manual execution is no problem, SVN automatic execution will not be able to execute.
2, SVN update must first manually checkout a copy out, and here must add the user and password if only manual will update, but automatically the same.
3, plus the previous command of the judgment, if the update when the problem, the program does not quit will continue to synchronize the code to the Web server, which will cause code problems
4, remember to set the user, because rsync can sync file properties, and our web server is not generally a root user, incorrect user will cause the Web program does not work correctly.
5, suggest the best record log, when the error can be quickly wrong
6, the final most critical data synchronization, rsync related parameters must be clear, this is not said. Notice a few scenes:
The environment here is the SVN server and the Web server are open
Define the SVN server as the destination server for the source server Web server
Scenario one, if the destination Web server is mixed, like only a Web static resource, the user submits, automatically generated in a directory of the Web, it is recommended not to use –delete this parameter
This is the case above, the implementation of the source server to the destination server updates and additions, without deletion, the content of the Web server more than the source SVN server
Scene two, the realization of mirroring, that is, the destination Web server with the same data as the source SVN server, SVN on any changes in the web on the same change, you need to –delete parameters
Scene three, do not need to sync some subdirectories, may be some directories are cached temporary garbage directory, or a dedicated picture directory (rather than style or typesetting) to use the exclude this parameter
Note: The use of this parameter does not need to write an absolute path, as long as the directory name on the line AA representative file aa/representative directory, the disadvantage is that if more than one subdirectory is the same name then these names will not be synchronized
It is suggested that the form of –exclude-from=/home/svn/exclude.list file can be easily added and deleted.
Exclude.list

. svn/
. Ds_store
images/

Using SVN hooks You can also write a number of programs to control SVN, such as checking for logs before submitting the code, whether there is a tab, if there will be a space, whether there are files that are not allowed to be uploaded, whether there are files that exceed the size of the limit, and so on.

Related Article

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.