设为首页 收藏本站
查看: 652|回复: 0

[经验分享] windows下架设subversion服务器(完整版)

[复制链接]

尚未签到

发表于 2016-5-21 11:21:01 | 显示全部楼层 |阅读模式
  

SVN 全名是 Subversion,它是一个开源的版本控制软件,与它类似的软件有CVS,VSS,ClearCase。而 SVN 作为一个跨平台的开源软件,具有很强的活力,目前也已经相当成熟,很多开源项目都用它来管理文档或是代码,以及项目文件的版本控制。
更为重要的是,不仅仅是团队开发,作为个人独立开发的项目(或者个人想维护的文档)也可以用 SVN 进行管理,而不需要另外一台服务器。以下为在windows环境下架设subversion服务器,实例在windows xp sp2/sp1 以及windows server 2003等win版本的系统架设成功。
一、安装SVN:
1、下载:目前最新的稳定定版,win32 1.6.0版,在官方下载地址下载,注意区分各版本适用环境,尤其是apache版本。
官方各版本下载地址:http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=91

天空青年本次架设的SVN选择版本,1.6.0版(apache 2.2.x),安装包下载地址为
http://subversion.tigris.org/files/documents/15/47866/svn-win32-1.6.0.zip

SVN架设环境:Nginx 1.0.0+Apache 2.2.13+PHP 5.2.8(稳定版)+MySQL 5.05+ZendOptimizer 3.3.0+SVN 1.6.0
2、安装:下载完后,将安装包解压到 D:\deploy\Subversion
3、建立Repository:如在D:\svnsrc目录下新建sky54.net程序代码仓库,CMD打开命令控制台,输入以下命令,即可完成代码仓库sky54.net的创建
D:\deploy\Subversion\bin\svnadmin.exe create --fs-type fsfs D:\svnsrc\sky54.net

4、配置Repository:进入Repository目录,在本文实例是 D:\svnsrc\sky54.net,进入后看到sky54.net下有conf目录,进入该目录,将可发现svnserve.conf和passwd两个文件,对此分别修改和配置如下:
1)、打开svnserve.conf,配置svn用户权限
下载: svnserve.conf

  • ### This file controls the configuration of the svnserve daemonif you
  • ### use it to allow access to this repository.  (If you only allow
  • ### access through httpand/or fileURLsthen 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.
  • ###去掉前面#号,配置用户权限
  • ###配置参数none:无任何权限; read: 只读; write:读和写
  • ###anon-access 配置匿名用户的权限为只读
  • anon-access = read
  • ###auth-access 配置授权用户的权限为可读写
  • auth-access = write
  • ### The password-db option controls the location of the password
  • ### database file.  Unless you specify a path starting with a /,
  • ### the file's location is relative to the directory containing
  • ### this configuration file.
  • ### If SASL is enabled (see below)this file will NOT be used.
  • ### Uncomment the line below to use the default password file.
  • ### 去掉前面的#号,在password文件中增加相关的用户名和密码
  • password-db = passwd
  • ### The authz-db option controls the location of the authorization
  • ### rules for path-based access control.  Unless you specify a path
  • ### starting with a /, the file's location is relative to the the
  • ### directory containing this file.  If you don't specify an
  • ### authz-dbno path-based access control is done.
  • ### Uncomment the line below to use the default authorization file.
  • # authz-db = authz
  • ### This option specifies the authentication realm of the repository.
  • ### If two repositories have the same authentication realmthey should
  • ### have the same password databaseand vice versa.  The default realm
  • ### is repository's uuid.
  • # realm = My First Repository
  •  
  • [sasl]
  • ### This option specifies whether you want to use the Cyrus SASL
  • ### library for authenticationDefault is false.
  • ### This section will be ignored if svnserve is not built with Cyrus
  • ### SASL supportto checkrun 'svnserve --versionand look for a line
  • ### reading 'Cyrus SASL authentication is available.'
  • # use-sasl = true
  • ### These options specify the desired strength of the security layer
  • ### that you want SASL to provide0 means no encryption1 means
  • ### integrity-checking onlyvalues larger than 1 are correlated
  • ### to the effective key length for encryption (e.g128 means 128-bit
  • ### encryption)The values below are the defaults.
  • # min-encryption = 0
  • # max-encryption = 256

2)、打开passwd文件,配置授权用户,实例配置用户名www.sky54.net 密码123456
注意: svnserve.conf中的[general] 和 passwd 中的 [users]配置项前不能有空格, “=” 后面只能有一个空格
下载: passwd

  • ### This file is an example password file for svnserve.
  • ### Its format is similar to that of svnserve.confAs shown in the
  • ### example below it contains one section labelled [users].
  • ### The name and password for each user followone account per line.
  •  
  • [users]
  • # harry = harryssecret
  • # sally = sallyssecret
  • www.sky54.net=123456

5、启动SVN:打开命令窗口,键入下面启动命令,如果你安装路径与本文实例不同的话,注意修改svn安装路径和Repository路径,运行命令后,发现进程管理器中有svnserve.exe,说明配置成功。
D:\deploy\Subversion\bin\svnserve.exe -d -r D:\svnsrc

SVN默认端口是3690,如果不幸这个端口被别的程序暂用,可以通过选项 –listen-port=绑定端口
SVN配置测试:
url格式为 svn://ip地址//Repository 名,在本文实例url是svn://127.0.0.1/sky54.net
至此,SVN的配置基本上可以使用,如果需要SVN跟随windows系统一起启动话,下面将进一步介绍将SVN注册到windows系统服务中。
二、配置SVN启动服务:
将SVN加入win系统启动服务项中,让subversion在windows自动启动,不用每次开机都要键入启动命令,尤其是生产环境中加入系统服务就显得很有必要。
以前的svnserve要想成为windows服务,必须依赖于svnservice或其他工具。从Subversion1.4开始,Subversion本身就集成Windows服务的工具。
1,注册svn系统服务:
在Windows NT中(包括Windows XP, Windows 2000, Windows 2003 Server)本身包含了一个安装服务的工具,叫做”Service Control”,也就是sc.exe。
例如我的Subversion安装在”D:\deploy\Subversion”,版本库在”D:\svnsrc”,而我希望对应的Subversion服务名为svn,安装这个svn服务的命令就可以这样写:

  • sc create svn
  •       binpath"D:\deploy\Subversion\bin\svnserve.exe --service -r D:\svnsrc"
  •       displayname"Subversion Server"
  •       dependTcpip
  •       startauto

请注意,因为便于察看,上面的命令分为多行,但在实际执行时应该在一行里。另外,在以前启动svnserve时会使用”-d”选项,也就是守护进程模式,在这里不能使用,会导致服务无法启动。同样,”-i”和”-t”选项也不能使用。
实际配置中,在windows命令窗口运行下面这一行的注册系统服务命令的即可,注意修改SVN安装路径和库路径

  • sc create svn binpath"\"D:\deploy\Subversion\bin\svnserve.exe\" --service -r D:\svnsrc" displayname="Subversion Server" dependTcpip startauto

然后即可通过命令行窗口执行net启动/停止svn服务命令,对SVN服务启动、停止管理。
2、删除服务
如果服务安装的有问题,你可能需要删除服务。要删除前面添加的服务,只需要运行删除Subversion Server服务命令即可,”Subversion Server”就是我们创建服务时使用的名字。
删除Subversion Server服务命令

  • sc delete svn binpath"\"D:\deploy\Subversion\bin\svnserve.exe\" --service -r D:\svnsrc" displayname="Subversion Server" dependTcpip startauto

当然你也可以使用图形化的工具修改服务的属性,你可以在“开始->运行”中执行”services.msc”,然后在界面中修改。
3、启动/停止svn服务
启动svn服务命令

  • net start svn

停止svn服务命令

  • net stop svn

4、SVN访问:在SVN安装部分提到过,最后再次重复一下
url格式为 svn://ip地址//Repository名,在本文实例url是svn://127.0.0.1/sky54.net
三、SVN应用实例:
1、代码库同步生产环境:利用SVN的钩子Hook,实现Repository代码库与生产环境目录同步。
方法其实很简单,有过在服务器上架设SVN服务端的朋友都能大概摸到这样一个流程,无非就是启用一个POST-COMMIT钩子脚本,commit后自动部署脚本,并将代码库更新到生产环境目录中。
本文实例中生产环境目录为D:\WWWROOT\sky54.net,我们打开windows命令窗口,键入如下命令,svn命令将空库checkout到生产环境目录中。
带SVN授权用户和密码命令:

  • D:\deploy\Subversion\bin\svn.exe checkout svn://127.0.0.1/sky54.net "D:\WWWROOT\sky54.net" --username www.sky54.net --password 123456

简化命令:

  • D:\deploy\Subversion\bin\svn.exe co svn://127.0.0.1/sky54.net "D:\WWWROOT\sky54.net"

命令键入运行后,系统会提示,”Checked out revision 23“或者”取出版本 23“,说明check out成功!
注意,以上名只用键入任一条即可,完成代码库的Checkout,天空青年反复测试的结果,告诉我必须先checkout一次,否则后面post-commit.bat与生产环境代码无法同步。
在实例仓库D:\svnsrc\sky54.net\hooks目录下,复制post-commit.tmpl,并改名成post-commit.bat,将文件内容替换成以下命令:
下载: post-commit.bat

  • @ECHO ON
  • REM POST-COMMIT HOOK
  •  
  • set repo=%1 
  • set rev=%2 
  • rem post-commit日志记录目录
  • set log="D:\svnsrc\sky54.net\post-commit_log.txt" 
  • rem post-commit错误日志记录目录
  • set err="D:\svnsrc\sky54.net\post-commit_err-log.txt" 
  • rem svn.exe文件的目录
  • set svn="D:\deploy\Subversion\bin\svn.exe" 
  • rem svn安装目录
  • set svnpath="D:\deploy\Subversion\bin"
  • rem 生产环境目录
  • set wwwroot="D:\WWWROOT\sky54.net"
  • ( echo ==================================================
  • echo Start commit %repor%rev%
  • date /t  time /t ) >> %log%
  • rem 带授权用户名和密码命令update命令
  • rem set cmd=%svnupdate %wwwroot% --quiet --username www.sky54.net --password 123456
  • rem 简化update命令(测试post-commit中无法同步到生产环境,请带上用户名和密码)
  • set cmd=%svnupdate %wwwroot%
  • (start "start-title" /D%svnpath% /BELOWNORMAL /B %cmd% >> %log%)

提示:你也可以下载本文的post-commit.bat,然后将文件中目录路径改成自己的,上传到项目代码库hooks目录(实例D:\svnsrc\sky54.net\hooks)下即可。
2、其它配置:commit强制写日志记录,以及用户只能修改自己提交文件的日志
SVN的每次commit是不需要日志log信息,为了便于管理,项目组通常会要求增加填写log习惯,可通过配置SVN的hook实现功能管理,通常的Windows下的强制log的hook脚本如下:
下载: pre-commit.bat

  • @ECHO ON
  • rem pre-commit HOOK
  • setlocal
  • set REPOS=%1
  • set TXN=%2
  • rem svnlook.exe目录路径
  • set svnlook="D:\deploy\Subversion\bin\svnlook.exe" 
  • rem 日志保证输入10个字符
  • rem check that logmessage contains at least 5 characters
  • %svnlooklog "%REPOS%" -t "%TXN%" | findstr ".........." > nul
  • if %errorlevelgtr 0 goto err
  •  
  • rem 过滤空格字符
  • %svnlooklog "%REPOS%" -t "%TXN%" | findstr /ic:"        " > nul
  • if %errorlevelgtr 0 goto success
  •  
  • goto err_empty
  •  
  • :err
  • echo 本次版本提交,必须写日志说明信息!>&2
  • echo 请补充日志说明信息后,再提交代码,例如:功能说明等!>&2
  • echo 输入的日志信息不少于10个字符说明(5个汉字),谢谢!>&2
  •  
  • :err_empty
  • echo 本次版本提交,必须写日志说明信息!>&2
  • echo ***********禁止空格数据***********!>&2
  • exit 1
  •  
  • :success
  • exit 0

使用说明:svn强制性写日志,字符不得小于10,汉字不少于4个,以及实现了空格过滤功能,pre-commit.bat文件目录与post-commit.bat均在项目代码库hooks目录下,实际应用时,注意修改实例中svnlook.exe路径。
pre-revprop-change.bat
便于代码库管理,防止项目组成员修改他人日志,实现SVN用户只能修改自己提交的文件日志,脚本如下:
下载: pre-revprop-change.bat

  • @ECHO ON
  • rem pre-revprop-change HOOK
  • set repos=%1
  • set rev=%2
  • set user=%3
  • set propname=%4
  • set action=%5
  • rem svnlook.exe目录路径
  • set svnlook="D:\deploy\Subversion\bin\svnlook.exe" 
  • for /f  "usebackq"   %%k in   (`%svnlookauthor %repos% -r %rev%`)   do   @set  var=%%k
  •  
  • set rightUser=0
  • if "%3" == "%superUser%"  set rightUser=1
  • if "%3" == "%var%" set rightUser=1
  •  
  • if %rightUser% == 0 goto ERROR_USER
  •  
  • goto :SUCCESS_EXIT
  •  
  • :ERROR_USER
  • echo 只允许用户修改自己的日志 >&2
  • goto ERROR_EXIT
  •  
  • :ERROR_EXIT
  • exit 1
  •  
  • :SUCCESS_EXIT
  • exit 0

实际应用提示:pre-revprop-change.bat文件上传目录,与pre-commit.bat、post-commit.bat等文件均在项目代码库hooks目录下。
固定链接: windows下架设subversion服务器(完整版) | 天空青年 +复制链接
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-219877-1-1.html 上篇帖子: windows下PHP APC拓展的安装和配置 下篇帖子: 优化Windows服务器网络性能
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表