About SVN and how it works
Subversion is the version management software that has risen in recent years and is the successor to CVS, and most open source software uses SVN as the code version management software. Subversion supports Linux and Windows, but is more installed under Linux.
The SVN server operates in two ways: a standalone server and the help of Apache. svn://or HTTP//
SVN client TortoiseSVN
The basic work of SVN is to create a source code repository on a single server that can store many different project sources. There are source code library administrators who manage these source programs uniformly. Each user before using the source code library, the first to download the source code Courried project files to local, and then the developer can be modified locally, after left with the SVN command to submit, the source code library unified Management changes.
Version control resolves the following:
* Code Management Confusion
* Difficulty Resolving code conflicts
* Bugs are raised during code consolidation
* Permission control cannot be granted to the owner of the code
* Issues with different versions of the project are difficult to publish
How SVN works:
Subversion Directory Description:
*dav directory: is to provide Apache and MOD_DAV_SVN use of the directory, let them store internal data
*DB Directory: All version-controlled data storage files
*hooks directory: The directory where the hook script files are placed
*locks directory: Used to place subversion to see the hard lock data of the directory, used to track access to the vault client
*format file: is a text file with only an integer in it. Represents the version number of the current vault configuration
*conf directory: Is the configuration file of this warehouse (user access account, permissions, etc.) of the warehouse
SVN Server Detailed Configuration manual
System environment
CentOS 5.8 Minimized installation (off iptables and SELinux) + ssh + Yum
One, install the necessary packages.
yum install subversion mysql-server httpd mod_dav_svn mod_perl sendmail wget gcc-c++ make unzip perl* ntsysv vim-enhanced
Description
Subversion (SVN server)
Mysql-server (for Codestriker)
httpd mod_dav_svn mod_perl (for Web-enabled management of SVN servers)
SendMail (used to configure user-submitted code to send email reminders)
wget gcc-c++ make unzip perl* (prerequisite package)
NTSYSV vim-enhanced (optional)
Two, the basic SVN server configuration
1, create a new directory to store all SVN files
# MKDIR/HOME/SVN
2, create a new version of the warehouse
# svnadmin Create/home/svn/project
3, initialize the directory in the version repository
# mkdir Project Project/server project/client project/test (Create temp directory)
# SVN import project/file:///home/svn/project-m "Initialize SVN directory"
# RM-RF Project (delete the temporarily created directory)
4, add user
To add SVN users is very simple, just add a "Username=password" entry in the/home/svn/project/conf/passwd file. For testing, I added the following:
[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 record the user's access policy, the following is a reference:
[groups]
project_p = pm
project_s = server1,server2,server3
project_c = client1,client2,client3
project_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 above information indicates that only the Project_p user group has read and write access to the root directory. R indicates that the directory has Read permissions, W indicates that the directory has write permissions, and RW indicates that the directory has read and write permissions. The last line of * = indicates that no one else is allowed to access this directory except for the user group with the permissions set above. This is very important, be sure to add!
6. Modify the svnserve.conf file to allow user and policy configuration to be upgraded.
Svnserve.conf content 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 you have modified the SVN configuration, you will need to restart the SVN service with the following steps:
# ps -aux|grep svnserve
# kill -9 ID号
# svnserve -d -r /home/svn
8, test server
# svn co svn://192.168.60.10/project
Authentication realm: <svn://192.168.60.10:3690> 92731041-2dae-4c23-97fd-9e1ed7f0d18d
Password for ‘root‘:
Authentication realm: <svn://192.168.60.10:3690> 92731041-2dae-4c23-97fd-9e1ed7f0d18d
Username: server_group
Password for ‘server_group‘:
svn: Authorization failed ( server_group没用根目录的访问权 )
# SVN Co svn://192.168.60.10/project
Authentication Realm: <svn://192.168.60.10:3690> 92731041-2dae-4c23-97fd-9e1ed7f0d18d
Password for ' root ':
Authentication Realm: <svn://192.168.60.10:3690> 92731041-2dae-4c23-97fd-9e1ed7f0d18d
username:pm
Password for ' PM ':
A Project/test
A Project/server
A project/client
Checked out Revision 1. (Test extraction succeeded)
# CD Project/server
# Vim MAIN.C
# SVN Add main.c
# SVN commit main.c-m "Test my C program, what to look at, no ah??"
Adding MAIN.C
Transmitting file data.
Committed Revision 2. (Test submission succeeded)
Third, configure HTTP support for SVN server
1, convert SVN server's password
Because the password for the SVN server is plaintext, the HTTP server is not supported, so it needs to be converted to the HTTP supported format. I wrote a perl script to finish the job.
The script reads 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.pl
Adding Password for user pm
Adding Password for user Server_group
Adding Password for user Client_group
Adding Password for user Test_group
Now there will be one more webpasswd file in the directory.
2, modify httpd.conf, add content about SVN server
To edit/etc/httpd/conf/httpd.conf, add the following information at the end:
<Location /project>
DAV svn
SVNPath /home/svn/project/
AuthType Basic
AuthName "svn for project"
AuthUserFile /home/svn/project/conf/webpasswd
AuthzSVNAccessFile /home/svn/project/conf/authz
Satisfy all
Require valid-user
</Location>
3, modify the owner of the SVN directory to Apache account: Chown-r apache.apache/home/svn/project/
( Note: This step is missing from the original, which gives permission issues.) )
4. Restart the Web server:
#/etc/init.d/httpd Restart
stopping httpd: [FAILED]
Starting httpd: [OK]
5, Access http://192.168.60.10/project/server/test with browser
The test results are as follows:
(Test succeeded)
Four, configure email reminder support
1. Installing the Perl module 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. Installing 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. Installing 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. Installing the Perl module svn::notify
# 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 mail server
# Service SendMail Restart
Shutting down SendMail: [FAILED]
Starting sendmail: [OK]
Starting sm-client: [OK]
6. Configure Automatic Email script
Modify the Post-commit script to support the mail notification feature.
# cd/home/svn/project/hooks/
# Vim Post-commit
The contents are as follows:
#!/bin/sh
REPOS="$1"
REV="$2"
/usr/bin/svnnotify–repos-path "$1″–revision" $2″–to [email protected]–from [email Protected]–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 represents the address of the receiving message, there can be more than one, when you have more than one boss, this is very important,:). The From parameter is virtual, represents your sending address, in general, this parameter is not important, but if the recipient's mail server has anti-spam features, need to determine the source address, this parameter is very important.
Add executable permissions to the script
# chmod +x Post-commit
7, when it is submitted again, it will send a letter to the specified email address.
as shown in:
Five, other common configuration
1, Force write log script
Configure the Pre-commit file, requiring the user to write log every time the file is updated.
# cd/home/svn/project/hooks/
# vim pre-commit
file contents are as follows:
#!/bin/sh
repos= "$"
txn= "$"
Svnlook=/usr/bin/svnlook
logmsg= ' $SVNLOOK log-t "$TXN" "$REPOS" | grep "[a-za-z0-9]" | wc-c '
IF ["$LOGMSG"-lt 5 ( Required log length, modified as needed)];
then
echo-e "nempty log message is not allowed. Commit aborted! " 1>&2
Exit 1
Fi
After the configuration is complete, add executable permissions to this piece. When you commit the code again, you must write the comment as required:)
2, can modify log script
Configure the Pre-revprop-change file, this file will be run when the log is modified in show log, get modified permissions, otherwise it will error: DAV request failed; It's possible that the repository ' s Pre-revprop-change hooks either failed or is non-existent. At least one failed; Repository is unchanged
# cd/home/svn/project/hooks/
# Vim Pre-revprop-change
The contents of the file are as follows:
REPOS="$1"
REV="$2"
USER="$3"
PROPNAME="$4"
if ["$PROPNAME" = "svn:log"];then exit 0;fi
exit 1
After configuration, add executable permission to the effect.
Six, backup management
A regular backup of the SVN server is important, and the simplest way is to periodically back up the warehouse directory.
1, create a new backup directory
# Mkdir/opt/project_backup
2. Write Backup scripts
# cd/home/svn/
# Vim Project_backup.sh
The contents are as follows:
#!/bin/bash
#write by huabo, 2009-11-20
Cd/home/svn
now= '/bin/date +%y%m%d '
/bin/tar czvf "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 [email protected]-S "Project_backup_$now" <<message
Result: '/bin/echo $result '
MESSAGE
Add executable permissions to the script.
3. Set the script to execute on a daily schedule.
# CRONTAB-E
Enter the following content:
0 * * */home/svn/project_backup.sh
Indicates that the script runs every night 23 o'clock.
After the above three steps, you can automatically back up the SVN data, and regardless of whether the backup is successful, will send the user mail message.
Seven, analyze SVN data with Svnstat.
1, installing Java
Svnstat is a Java application that requires a Java environment to be installed first.
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 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 in with a browser to see a lot of statistics out of the chart. Roughly as shown:
Eight, analyze SVN data with STATSVN
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, using the browser test results such as:
Nine, configure Codestriker.
1. Install the Codestriker dependent Perl package.
# 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
Perform:
CREATE DATABASE codestrikerdb CHARACTER SET UTF8;
GRANT select,insert,update,delete,index,alter,create,drop,references on codestrikerdb.* to [email protected] Identified by ' cspasswd ';
FLUSH privileges;
Quit
4. Configure Codestriker
# CD codestriker-1.9.10/
# Vim Codestriker.conf
Note the following points (see the installation documentation for Codestriker for details)
A. Database username and password to pair
B.SVN Data Warehouse to pair, my following:
@valid_repositories =
(
' Svn:file:///home/svn/project ',
)
5. Execute the Codestriker installation script
# CD bin/
#./install.pl
6. Configuring HTTP Support
# vim/etc/httpd/conf/httpd.conf
At the very end, add the following:
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-script
Perlhandler Modperl::registry
Options +execcgi
</Directory>
<directory "/var/www/codestriker/codestriker-1.9.10/html/" >
AllowOverride None
Allow from all
</Directory>
7.重启Web服务
# service httpd restart
8. Enter http://192.168.60.10/codestriker/codestriker.pl in the browser to access, such as:
Reference: Http://wiki.centos.org/HowTos/Subversion
CentOS Linux Build SVN server configuration detailed