Original article address:Install and configure the svn server in Ubuntu
Author:Mirze
I. 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 file: sudo Vim
/Home/SVN/fitness/hooks/post-commit
Note: after the post-commit is completed, run: 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
# 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
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.
From: http://blog.sina.com.cn/s/blog_6f4f66dc0100pjdf.html