Configure the svnlinux Server

Source: Internet
Author: User
Tags svn client svn update perl script

Configure the svnlinux Server

PS: Today, I set up a public-network SVN Server for my colleagues. google the SVN Server and I found the most detailed article below. I will record it and reprint it. By the way, based on your own experience, I have added several details and summarized them. The configuration in this article is based on CentOS 5.x, but the same applies to other Linux distributions!

SVN overview and working principles

Subversion (svn for short) is a version management software that has emerged in recent years and is the successor of cvs. Currently, most open-source software uses svn as the code version management software. Subversion supports linux and windows, but is mostly installed in linux.

Svn servers can run in two ways: independent servers and apache. Svn: // or http ://
Svn client tortoisesvn
Basic working principle of svn: Create a source code library on a server, and store the source code of many different projects in the library. The source code library administrator manages these source programs in a unified manner. Before using the source code library, each user must first download the project file from the source code library to the local device. Then, the developer can modify the file locally, and then use the svn command to submit the file, unified management and modification of the game source code library.
Version Control solves the following problems:
* Chaotic code management
* Solve code conflicts
* A bug occurs during code integration.
* You cannot control the permissions of the code owner.
* Difficult release of different project versions

How SVN works:

Subversion directory description:
* Dav Directory: Provides the directories used by apache and mod_dav_svn to store internal data.
* Db Directory: stores all version-controlled data files.
* Hooks Directory: directory for storing hook script files
* Locks Directory: used to place the subversion. See the directory for hard-locking data. It is used to track the client that accesses the file library.
* Format File: a text file with only one integer. Indicates the version number of the current file library configuration.
* Conf directory: it is the configuration file of this warehouse (the Warehouse's user access account, permissions, etc)

SVN Server detailed configuration Manual

 

System Environment
CentOS 5.8 minimal installation (disable iptables and selinux) + ssh + yum

1. install required software packages.
Yum install subversion mysql-server httpd mod_dav_svn mod_perl sendmail wget gcc-c ++ make unzip perl * ntsysv vim-enhanced

Note:
Subversion (SVN server)
Mysql-server (for codestriker)
Httpd mod_dav_svn mod_perl (used to manage SVN servers on the WEB)
Sendmail (used to configure the user to send an email notification after the code is submitted)
Wget gcc-c ++ make unzip perl * (Required Software Package)
Ntsysv vim-enhanced (optional)

Ii. Basic SVN Server Configuration
1. Create a directory to store all SVN files.
# Mkdir/home/svn

2. Create a version Repository
# Svnadmin create/home/svn/project

3. initialize the directory in the version repository.
# Mkdir project/server project/client project/test (create a temporary directory)
# Svn import project/file: // home/svn/project-m "initialize SVN directory"
# Rm-rf project (delete temporary directories)

4. Add a user
To add SVN users, you only need to add an entry in the format of "username = password" to the/home/svn/project/conf/passwd file. For testing, I added the following content:

[Users]
# Harry = harryssecret
# Sally = sallyssecret
Pm = pm_pw
Server_group = server_pw
Client_group = client_pw
Test_group = test_pw

5. Modify the User Access Policy
 

/Home/svn/project/conf/authz records users' access policies. For details, refer to [groups] project_p = pmproject_s = server1, server2, server3project_c = client1, client2, client3project_t = test1, test1, test1 [project:/] @ project_p = rw * = [project:/server] @ project_p = rw @ project_s = rw * = [project: /client] @ project_p = rw @ project_c = rw * = [project:/doc] @ project_p = rw @ project_s = r @ project_c = r @ project_t = r * =

Note: The preceding information indicates that only the project_p user group has the permission to read and write the root directory. R indicates that the directory has read permission, w indicates that the directory has write permission, and rw indicates that the directory has read and write permissions. * = In the last row indicates that no one except the user group with the preceding permissions is allowed to access this directory. This is very important and must be added!

6. Modify the svnserve. conf file to make the user and policy configuration more effective.
The content of svnserve. conf is as follows:

[General]
Anon-access = none
Auth-access = write
Password-db =/home/svn/project/conf/passwd
Authz-db =/home/svn/project/conf/authz

7. Start the server
# Svnserve-d-r/home/svn
Note: If the svn configuration is modified, restart the svn Service as follows:

# Ps-aux | grep svnserve
# Kill-9 ID
# Svnserve-d-r/home/svn

8. Test Server

 

# Svn co svn: // 192.168.60.10/projectAuthentication realm: <svn: // 192.168.60.10: 3690> Authentication for 'root': Authentication realm: <svn: // 192.168.60.10: 3690> Authorization: server_groupPassword for 'server _ group': svn: Authorization failed (server_group does not use root directory access) # svn co svn: // 192.168.60.10/projectAuthentication realm: <svn: // 192.168.6 0.10: 3690> 92731041-2dae-4c23-97fd-9e1ed7f0d18dPassword for 'root': Authentication realm: <svn: // 192.168.60.10: 3690> authorization: pmPassword for 'pm ': A project/testA project/serverA project/clientChecked out revision 1. (extracted successfully) # cd project/server # vim main. c # svn add main. c # svn commit main. c-m "test my C program. What do you think ??" Adding main. cTransmitting file data. Committed revision 2. (The test is submitted successfully)

3. Configure http support for the svn Server
1. Convert the SVN server password
Because the SVN server password is in plain text, the HTTP server does not support it, so you need to convert it to a format supported by HTTP. I wrote a Perl script to complete this job.
The script content is as follows:
# Cd/home/svn/project/conf/
# Vim PtoWP. pl

#!/usr/bin/perl# write by huabo, 2009-11-20use warnings;use strict;#open the svn passwd fileopen (FILE, "passwd") or die ("Cannot open the passwd file!!!n");#clear the apache passwd fileopen (OUT_FILE, ">webpasswd") or die ("Cannot open the webpasswd file!!!n");close (OUT_FILE);#beginforeach (<FILE>) {if($_ =~ m/^[^#].*=/) {$_ =~ s/=//;`htpasswd -b webpasswd $_`;}}
# chmod +x PtoWP.pl# ./PtoWP.plAdding password for user pmAdding password for user server_groupAdding password for user client_groupAdding password for user test_group


Now there will be one more webpasswd file in the directory.

2. Modify httpd. conf and add content about the SVN server.
Edit/etc/httpd/conf/httpd. conf and add the following information at the end:

 

<Location /project>DAV svnSVNPath /home/svn/project/AuthType BasicAuthName "svn for project"AuthUserFile /home/svn/project/conf/webpasswdAuthzSVNAccessFile /home/svn/project/conf/authzSatisfy allRequire valid-user</Location>

3. Change the svn directory owner to an apache account: chown-R apache. apache/home/svn/project/
(Note: If this step is missing in the original article, the permission issue may occur .)
4. Restart the Web Server:
#/Etc/init. d/httpd restart
Stopping httpd: [FAILED]
Starting httpd: [OK]

5. Use a browser to access http: // 192.168.60.10/project/server/test
Shows the test result:

(Test successful)

4. Configure email reminder support
1. Install the Perl Module: Build

# Wget http://search.cpan.org/CPAN/authors/id/D/DA/DAGOLDEN/Module-Build-0.36_11.tar.gz
# Tar xvf Module-Build-0.36_11.tar.gz
# Cd Module-Build-0.36_11
# Perl Build. PL
#./Build
#./Build test
#./Build install
# Cd ..

2. Install the Perl module Authen: SASL

# Wget http://search.cpan.org/CPAN/authors/id/G/GB/GBARR/Authen-SASL-2.15.tar.gz
# Tar xvf Authen-SASL-2.15.tar.gz
# Cd Authen-SASL-2.15
# Perl Makefile. PL
# Make test
# Make install
# Cd ..

3. Install the Perl module. Net: SMTP_auth.

# Wget http://search.cpan.org/CPAN/authors/id/A/AP/APLEINER/Net-SMTP_auth-0.08.tar.gz
# Tar xvf Net-SMTP_auth-0.08.tar.gz
# Cd Net-SMTP_auth-0.08
# Perl Makefile. PL
# Make test
# Make install
# Cd ..

4. Install the Perl module SVN: Running y

# Wget http://search.cpan.org/CPAN/authors/id/D/DW/DWHEELER/SVN-Notify-2.80.tar.gz
# Tar xvf SVN-Notify-2.80.tar.gz
# Cd SVN-Notify-2.80
# Perl Build. PL
#./Build
#./Build test
#./Build install
# Cd ..

5. Start the email server.
# Service sendmail restart
Shutting down sendmail: [FAILED]
Starting sendmail: [OK]
Starting sm-client: [OK]

6. Configure the automatic mail script
Modify the post-commit script to support email notification.
# Cd/home/svn/project/hooks/
# Vim post-commit
The content is as follows:

#! /Bin/sh
REPOS = "$1"
REV = "$2"

/Usr/bin/svnnotify-repos-path "$1"-revision "$2"-to caodaijun@pica.com-from caodaijun@feinno.com-handler "HTML :: colorDiff "-with-diff-smtp localhost-smtp-user root-smtp-pass 5201314318-c" UTF-8 "-g zh_CN-o raw-svnlook/usr/bin/svnlook-subject -prefix '[SVN Update]'

(The to parameter indicates the address of the email to be received. There can be multiple addresses. When you have multiple bosses, this is very important ,:). The from parameter is virtual and represents your sending Address. Generally, this parameter is not important. However, if the recipient's email server has the anti-spam function and needs to determine the source address, it is important to check whether this parameter is valid)
Add the executable permission to the script.
# Chmod + x post-commit

7. When you submit the email again, the email will be sent to the specified email address.
As shown in:

5. Other common configurations
1. Force write the log script
To configure the pre-commit file, you must write logs every time you update the file.
# Cd/home/svn/project/hooks/
# Vim pre-commit
The file content is as follows:

#! /Bin/sh
REPOS = "$1"
TXN = "$2"
SVNLOOK =/usr/bin/svnlook
LOGMSG = '$ SVNLOOK log-t "$ TXN" "$ REPOS" | grep "[a-zA-Z0-9]" | wc-C'
If ["$ LOGMSG"-lt 5 (the required log length must be modified as needed)];
Then
Echo-e "nEmpty log message not allowed. Commit aborted! "1> & 2
Exit 1
Fi

After the configuration is complete, add the executable permission to this file. When submitting code again, you must write comments as required ,:)

2. You can modify the log script.
Configure the pre-revprop-change file. This file runs when the show log file is modified to obtain the modified permission. Otherwise, the following error occurs: DAV request failed; it's possible that the repository's pre-revprop-change hook either failed or is non-existent. at least one property change failed; repository is unchanged
# Cd/home/svn/project/hooks/
# Vim pre-revprop-change
The file content is as follows:

REPOS = "$1"
REV = "$2"
USER = "$3"
PROPNAME = "$4"
If ["$ PROPNAME" = "svn: log"]; then exit 0; fi
Exit 1

After configuration, add executable permissions to Improve the efficiency.

Vi. Backup management
Regular backup of the svn server is very important. The simplest method is regular backup of the Repository directory.
1. Create a backup directory.
# Mkdir/opt/project_backup

2. Write a backup script
# Cd/home/svn/
# Vim project_backup.sh

The content is as follows:

#! /Bin/bash
# Write by huabo, 2009-11-20

Cd/home/svn
Now = '/bin/date + % Y % m % d'
/Bin/tar czvf export project_backup_$now.tar.gz "project/& rm-rf/opt/project_backup/* &/bin/mv project_backup _ * .tar.gz/opt/project_backup/
If [$? = 0]
Then
Result = "OK !!"
Else
Result = "False !!"
Fi

# Send mail to administrator
/Bin/mail caodaijun@pica.com-s "project_backup _ $ now" <MESSAGE
Result: '/bin/echo $ result'
MESSAGE

Add executable permissions to the script.

3. Set the daily scheduled execution of the script.
# Crontab-e
Enter the following content:
0 23 ***/home/svn/project_backup.sh
Indicates that the script is run at every night.

After the preceding three steps, the SVN data can be automatically backed up, and no matter whether the backup is successful or not, emails will be sent to the user.

7. Use svnstat to analyze SVN data.
1. install JAVA
Svnstat is a JAVA application. You must first install the JAVA environment.
Download jre, URL: http://javadl.sun.com/webapps/download/AutoDL? BundleId = 39484.
Installation:
# Chmod + x jre-6u20-linux-i586-rpm.bin
#./Jre-6u20-linux-i586-rpm.bin

2. Download svnstat
# Wget http://downloads.sourceforge.net/project/svnstat/svnstat/Release-1.0/SvnStat-1.0.zip? Use_mirror = jaist
# Unzip SvnStat-1.0.zip

3. Update the code.
# Pwd
/Root

# Svn co svn: // 192.168.60.10/project
A project/test
A project/server
A project/server/main. c
A project/client
Checked out revision 5.

4. Generate svnstat data
# Svn log project-v-xml-non-interactive> project. log
# Cd SvnStat-1.0
# Java-classpath SvnStat-all.jar de. agentlab. svnstat. SvnStat-jar SvnStat-all.jar-r/root/project. log-d/var/www/html/

5. log on to the browser and you will see many statistical charts. Roughly as shown in:

8. Use statsvn to analyze SVN data
1. Download statsvn
# Wget http://downloads.sourceforge.net/project/statsvn/statsvn/0.7.0/statsvn-0.7.0.zip? Use_mirror = jaist
# Unzip statsvn-0.7.0.zip
# Cd statsvn-0.7.0

2. Generate statsvn data
# Mkdir/var/www/html/statsvn
# Java-jar statsvn. jar-verbose-output-dir/var/www/html/statsvn // root/project. log/root/project

3. Use a browser to test the effect, for example:

9. Configure codestriker.
1. Install the perl package on which codestriker depends.
# Perl-MCPAN-e 'Install "Template "'

2. Download codestriker
# Wget http://downloads.sourceforge.net/project/codestriker/codestriker/1.9.10/codestriker-1.9.10.tar.gz? Use_mirror = jaist & ts = 1279246587
# Mkdir/var/www/codestriker
# Cd/var/www/codestriker
# Tar xvf/path/codestriker-1.9.10.tar.gz
# Chown-R apache. apache codestriker-1.9.10

3. Configure the database
# Service mysqld restart
# Mysql-uroot mysql
Run:
Create database codestrikerdb character set utf8;
Grant select, INSERT, UPDATE, DELETE, INDEX, ALTER, CREATE, DROP, references on codestrikerdb. * TO codestriker @ localhost identified by 'cspasswd ';
Flush privileges;
Quit

4. Configure codestriker
# Cd codestriker-1.9.10/
# Vim codestriker. conf
Pay attention to the following points (For details, refer to the codestriker installation Documentation)
A. the username and password of the database must be paired
B. The svn data warehouse should be paired. My items are as follows:
@ Valid_repositories =
(
'Svn: file: // home/svn/Project ',
)

5. Run the codestriker installation script.
# Cd bin/
#./Install. pl

6. Configure http support
# Vim/etc/httpd/conf/httpd. conf
Add the following content at the end:

Alias /codestriker/ /var/www/codestriker/codestriker-1.9.10/cgi-bin/Alias /codestrikerhtml/ /var/www/codestriker/codestriker-1.9.10/html/<Directory “/var/www/codestriker/codestriker-1.9.10/cgi-bin/”>SetHandler perl-scriptPerlHandler ModPerl::RegistryOptions +ExecCGI</Directory><Directory “/var/www/codestriker/codestriker-1.9.10/html/”>AllowOverride NoneAllow from all</Directory>


7. Restart the Web Service
# Service httpd restart

8. Enter http: // 192.168.60.10/codestriker. pl in the browser to access the service, for example:

 

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.