本文共 11135 字,大约阅读时间需要 37 分钟。
转自:
系统环境
RHEL5.4最小化安装(关iptables,关selinux) + ssh + yum 一,安装必须的软件包. yum install subversion (SVN服务器) mysql-server (用于codestriker) httpd mod_dav_svn mod_perl (用于支持WEB方式管理SVN服务器) sendmail (用于配置用户提交代码后发邮件提醒) wget gcc-c++ make unzip perl* (必备软件包) ntsysv vim-enhanced (可选) 二,基本的SVN服务器配置 1,新建一个目录用于存储SVN所有文件 # mkdir /home/svn 2,新建一个版本仓库 # svnadmin create /home/svn/project 3,初始化版本仓库中的目录 # mkdir project project/server project/client project/test (建立临时目录) # svn import project/ file:///home/svn/project -m "初始化SVN目录" # rm -rf project (删除临时建立的目录) 4,添加用户 要添加SVN用户非常简单,只需在/home/svn/project/conf/passwd文件添加一个形如“username=password"的条目就可以了.为了测试,我添加了如下内容: [users] # harry = harryssecret # sally = sallyssecret pm = pm_pw server_group = server_pw client_group = client_pw test_group = test_pw 5,修改用户访问策略 /home/svn/project/conf/authz记录用户的访问策略,以下是参考: [groups] project_p = pm project_s = server_group project_c = client_group project_t = test_group [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 = rw @project_c = rw @project_t = rw * = 以上信息表示,只有pm有根目录的读写权,server_group能访问server目录,client_group能访问client目录,所有人都可以访问doc目录. 6,修改svnserve.conf文件,让用户和策略配置升效. svnserve.conf内容如下: [general] anon-access = none auth-access = write password-db = /home/svn/project/conf/passwd authz-db = /home/svn/project/conf/authz 7,启动服务器 # svnserve -d -r /home/svn 8,测试服务器 # 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. ( 测试提取成功 ) # cd project/server # vim main.c # svn add main.c # svn commit main.c -m "测试一下我的C程序,看什么看,不行啊??" Adding main.c Transmitting file data . Committed revision 2. ( 测试提交成功 ) 三,配置SVN服务器的HTTP支持 1,转换SVN服务器的密码 由于SVN服务器的密码是明文的,HTTP服务器不与支持,所以需要转换成HTTP支持的格式。我写了一个Perl脚本完成这个工作. 脚本内容如下: # cd /home/svn/project/conf/ # cat PtoWP.pl #!/usr/bin/perl # write by huabo, 2009-11-20 use warnings; use strict; #open the svn passwd file open (FILE, "passwd") or die ("Cannot open the passwd file!!!\n"); #clear the apache passwd file open (OUT_FILE, ">webpasswd") or die ("Cannot open the webpasswd file!!!\n"); close (OUT_FILE); #begin foreach (<FILE>) { if(_ =~ m/^[^#].*=/) { _ =~ m/^[^#].*=/) { _ =~ s/=//; `htpasswd -b webpasswd $_`; } } # ./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 现在目录下会多一个webpasswd文件。 2,修改httpd.conf,添加关于SVN服务器的内容 编辑/etc/httpd/conf/httpd.conf,在最后添加如下信息: <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,启动HTTPD服务器 # service httpd restart Stopping httpd: [FAILED] Starting httpd: [ OK ] 4,用浏览器访问http://192.168.60.10/project/server/测试 测试结果如下图所示:( 测试成功 )
四,配置邮件提醒支持 1,安装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,安装Perl模块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,安装Perl模块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,安装Perl模块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,启动邮件服务器 # service sendmail restart Shutting down sendmail: [FAILED] Starting sendmail: [ OK ] Starting sm-client: [ OK ] 6,配置自动发邮件脚本 修改post-commit脚本,以支持邮件通知功能. # cd /home/svn/project/hooks/ # vim post-commit 内容如下: #!/bin/sh REPOS="1"REV="1"REV="2" /usr/bin/svnnotify --repos-path "1"−−revision"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]' (to参数代表接收邮件的地址,可以有多个,当你有多个老大的时候,这就很重要了,:)。from参数是虚拟的,代表你的发送地址,一般情况下,这个参数 不重要,但如果接收者的邮件服务器有反垃圾邮件的功能,需要判定源地址的话,这个参数是否合法就显得很重要了) 再给该脚本添加可执行权限 # chmod +x post-commit 7,再次提交时,就会给指定邮件地址发信了。 如下图所示:总结个CC。
搭建的时候出现如下问题与其解决:
一、
如果出现,这样的错误信息,“svnserve: 不能绑定服务器套接字: 地址已经被使用”
那先把svnserve进程干掉。 具体做法是ps−aux#查看进程,svnserve的pid为XXXXps−aux#查看进程,svnserve的pid为XXXX kill -9 XXX #干掉svnserve 再次运行$ svnserve -d -r /var/www/svn二、Error Unable to connect to a repository at URL ‘https://xxxxxxxxxxxx/svn/xxxxxxx’
Error Access to ‘https://xxxxxxxxxxx/svn/xxxxxxxx‘ forbidden
搞了半天,如果你也出现这样的问题,不妨试试:
右键点击本地副本,TortoiseSVN -> Settings -> Saved Data,
三、不能打开文件 '/home/svn/ishare/db/txn-current-lock': 权限不够
直接 $:cd /home/svn/ishare/ ishare为你的项目名称 sudo chmod -r 777 db
四、在客户端访问subversion版本库时出现这个错误:
svnserve.conf:12: Option expected 为什么会出现这个错误呢,就是因为subversion读取配置文件svnserve.conf时,无法识别有前置空格的配置文件,如 ### This file controls the configuration of the svnserve daemon, if you ### use it to allow access to this repository. (If you only allow ### access through http: and/or file: URLs, then this file is ### irrelevant.) ### Visit http://subversion.tigris.org/ for more information. [general] ### These options control access to the repository for unauthenticated ### and authenticated users. Valid values are "write", "read", ### and "none". The sample settings below are the defaults. anon-access = read auth-access = write 像上面的配置文件中,anon-access是顶行的,没问题,而auth-access就存在前置空格,会导致这个错误。 要避免出现这个错误,应该在去掉这些行前的#时,也要顺手去掉前面的空格,这一点,在郑新星老早的文章就提到过。五、
本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/sky-heaven/p/5657818.html,如需转载请自行联系原作者