Linux下Apache完美集成SVN(Yum安装版)

svn(subversion)是目前最流行的开源版本控制工具。使用apache集成svn比svn服务独立运行好处多多,最大的优点是使svn使用http80端口检出,防火墙可以少开放一个端口,减少服务器安全风险和降低维护成本。下面在CentOS6.0系统下通过yum安装的方式,介绍在linuxapache完美集成svn。

一、规划目录:

网站地址 http://www.aiezu.com
网站根目录 /storage/web/aiezu
SVN地址 http://www.aiezu.com/svn/aiezu
SVN数据仓库目录 /storage/svn/aiezu
二、安装apache:

安装apache包:

  1. yum -y install httpd #必须
  2. yum -y install mysql mysql-server php php-mbstring php-gd #可选安装

创建站点根目录:

  1. mkdir -p /storage/web/aiezu

建立基于域名的虚拟主机,vim /etc/httpd/conf.d/www.aiezu.com.conf添加以下内容:

  1. NameVirtualHost *:80
  2. <Directory "/storage/web/aiezu">
  3.     Options -Indexes FollowSymLinks
  4.     AllowOverride None
  5.     Order allow,deny
  6.     Allow from all
  7. </Directory>
  8. <VirtualHost *:80>
  9.     ServerAdmin admin@aiezu.com
  10.     DocumentRoot /storage/web/aiezu
  11.     ServerName www.aiezu.com
  12.     ErrorLog logs/www.aiezu.com-error_log
  13.     CustomLog logs/www.aiezu.com-access_log common
  14. </VirtualHost>

启动apache和mysql服务:

  1. service mysqld start
  2. service httpd start
三、安装和配置apache SVN模块:

安装apache服务SVN模块mod_dav_svn:

  1. yum -y install mod_dav_svn
  2. #会自动安装mod_dav_svn及其依赖包:mod_dav_svn-1.6.11-9,neon-0.29.3-2,pakchois-0.4-3.2,subversion-1.6.11-9

建立svn数据仓库:

  1. mkdir -p /storage/svn/aiezu
  2. svnadmin create /storage/svn/aiezu

建立svn帐号并设置密码:

  1. htpasswd -c /storage/svn/aiezu/conf/passwd svnuser

分配svn帐号权限:

  1. [aiezu:/]
  2. svnuser = rw #设置aiezu数据仓库svnuser用户有读写权限

配置svn数据仓库文件系统权限:

  1. chown -R apache.apache /storage/svn/aiezu
  2. chcon -R -t httpd_sys_content_t /storage/svn/aiezu #selinux权限

配置svn数据仓库checkout地址:
vim /etc/httpd/conf.d/subversion.conf,添加如下内容:

  1. LoadModule dav_svn_module modules/mod_dav_svn.so
  2. LoadModule authz_svn_module modules/mod_authz_svn.so
  3. <Location /svn>
  4.     DAV svn
  5.     SVNListParentPath on
  6.     SVNParentPath /storage/svn
  7.     AuthType Basic
  8.     AuthName "Authorization"
  9.     AuthUserFile /storage/svn/aiezu/conf/passwd
  10.     AuthzSVNAccessFile /storage/svn/aiezu/conf/authz
  11.     Require valid-user
  12. </Location>

重新加载apache配置:

  1. service httpd reload
四、配置svn post-commit钩子:

当我们希望在像svn数据仓库提交新版本时,自动将更新同步到我们的网站,这时我们可以使用svn钩子,svn钩子必须放在svn数据仓库的hooks目录下,这里我们要添加是svn commit(svn提交)钩子post-commit:
vim /storage/svn/aiezu/hooks/post-commit,添加如下内容:

  1. #!/bin/bash
  2. export LANG="zh_CN.UTF-8"
  3. export LANG="zh_CN.UTF-8"
  4. export LC_CTYPE="zh_CN.UTF-8"
  5. svn update /storage/web/aiezu/ --username=svnuser --password=svnpass --non-interactive

授予可执行权限:

  1. chmod a+x /storage/svn/aiezu/hooks/post-commit

检出版本库:

  1. svn checkout http://www.aiezu.com/svn/aiezu /storage/web/aiezu/
五、常见错误及其解答:

1、svn checkout(svn检出)时错误一:

  1. The URI does not contain the name of a repository. [403, #190001]

解答:这是由于subversion.conf文件中SVNParentPath路径设置不正确引起的,SVNParentPath路径必须为svnadmin create生成数据仓库路劲的父目录,如上面建立数据仓库的命令为svnadmin create /storage/svn/aiezu,则SVNParentPath为/storage/svn。
2、svn checkout时错误二:

  1. Unable to connect to a repository at URL 'http://www.aiezu.com/svn'
  2. Access to 'http://www.aiezu.com/svn' forbidden

解答:svn数据仓库的SVN URL地址不正确,当subversion.conf中设置SVNListParentPath on时,SVN URL地址为SVNParentPath下的具体数据仓库,而不是SVNParentPath指定的目录。
3、svn checkout时错误三:

  1. Unable to connect to a repository at URL http://www.aiezu.com/svn/test'
  2. Could not open the requested SVN filesystem

解答:svn数据仓库的SVN URL地址不正确,在SVNParentPath下找不到SVN URL指定的数据仓库。
4、svn提交(svn commit)时出现如下错误:

  1. post-commit hook failed (exit code 1) with output:
  2. svn: Can't open file '/storage/web/aiezu/.svn/lock': Permission denied

解答:这是svn提交调用的post-commit钩子没有权限写/storage/web/aiezu/.svn目录引起的。apache集成的svn是使用apache用户调用post-commit钩子的,所以必须保证apache用户对.svn有写权限, 执行chown -R apache.apache /storage/web/aiezu就可以了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值