qazxsw1 发表于 2018-11-24 09:06:00

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

  svn(subversion)是目前最流行的开源版本控制工具。使用apache集成svn比svn服务独立运行好处多多,最大的优点是使svn使用http80端口检出,防火墙可以少开放一个端口,减少服务器安全风险和降低维护成本。下面在CentOS6.0系统下通过yum安装的方式,介绍在linux下apache完美集成svn。
一、规划目录:
网站地址http://www.aiezu.com网站根目录/storage/web/aiezuSVN地址http://www.aiezu.com/svn/aiezuSVN数据仓库目录/storage/svn/aiezu二、安装apache:
  安装apache包:
yum -y install httpd #必须  
yum -y install mysql mysql-server php php-mbstring php-gd #可选安装
  创建站点根目录:
mkdir -p /storage/web/aiezu  建立基于域名的虚拟主机,vim /etc/httpd/conf.d/www.aiezu.com.conf添加以下内容:
NameVirtualHost *:80  

  
Options -Indexes FollowSymLinks
  
AllowOverride None
  
Order allow,deny
  
Allow from all
  

  

  
ServerAdmin admin@aiezu.com
  
DocumentRoot /storage/web/aiezu
  
ServerName www.aiezu.com
  
ErrorLog logs/www.aiezu.com-error_log
  
CustomLog logs/www.aiezu.com-access_log common
  

  启动apache和mysql服务:
service mysqld start  
service httpd start
三、安装和配置apache SVN模块:
  安装apache服务SVN模块mod_dav_svn:
yum -y install mod_dav_svn  
#会自动安装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数据仓库:
mkdir -p /storage/svn/aiezu  
svnadmin create /storage/svn/aiezu
  建立svn帐号并设置密码:
htpasswd -c /storage/svn/aiezu/conf/passwd svnuser  分配svn帐号权限:
  
svnuser = rw #设置aiezu数据仓库svnuser用户有读写权限
  配置svn数据仓库文件系统权限:
chown -R apache.apache /storage/svn/aiezu  
chcon -R -t httpd_sys_content_t /storage/svn/aiezu #selinux权限
  配置svn数据仓库checkout地址:
  vim /etc/httpd/conf.d/subversion.conf,添加如下内容:
LoadModule dav_svn_module modules/mod_dav_svn.so  
LoadModule authz_svn_module modules/mod_authz_svn.so
  

  
DAV svn
  
SVNListParentPath on
  
SVNParentPath /storage/svn
  
AuthType Basic
  
AuthName “Authorization”
  
AuthUserFile /storage/svn/aiezu/conf/passwd
  
AuthzSVNAccessFile /storage/svn/aiezu/conf/authz
  
Require valid-user
  

  重新加载apache配置:
service httpd>四、配置svn post-commit钩子:
  当我们希望在像svn数据仓库提交新版本时,自动将更新同步到我们的网站,这时我们可以使用svn钩子,svn钩子必须放在svn数据仓库的hooks目录下,这里我们要添加是svn commit(svn提交)钩子post-commit:
  vim /storage/svn/aiezu/hooks/post-commit,添加如下内容:
#!/bin/bash  
export LANG=”zh_CN.UTF-8″
  
export LANG=”zh_CN.UTF-8″
  
export LC_CTYPE=”zh_CN.UTF-8″
  
svn update /storage/web/aiezu/ –username=svnuser –password=svnpass –non-interactive
  授予可执行权限:
chmod a+x /storage/svn/aiezu/hooks/post-commit  检出版本库:
svn checkout http://www.aiezu.com/svn/aiezu /storage/web/aiezu/五、常见错误及其解答:
  1、svn checkout(svn检出)时错误一:
The URI does not contain the name of a repository.   解答:这是由于subversion.conf文件中SVNParentPath路径设置不正确引起的,SVNParentPath路径必须为svnadmin create生成数据仓库路劲的父目录,如上面建立数据仓库的命令为svnadmin create /storage/svn/aiezu,则SVNParentPath为/storage/svn。
  2、svn checkout时错误二:
Unable to connect to a repository at URL ‘http://www.aiezu.com/svn’  
Access to ‘http://www.aiezu.com/svn’ forbidden
  解答:svn数据仓库的SVN URL地址不正确,当subversion.conf中设置SVNListParentPath on时,SVN URL地址为SVNParentPath下的具体数据仓库,而不是SVNParentPath指定的目录。
  3、svn checkout时错误三:
Unable to connect to a repository at URL http://www.aiezu.com/svn/test’  
Could not open the requested SVN filesystem
  解答:svn数据仓库的SVN URL地址不正确,在SVNParentPath下找不到SVN URL指定的数据仓库。
  4、svn提交(svn commit)时出现如下错误:
post-commit hook failed (exit code 1) with output:  
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就可以了。


页: [1]
查看完整版本: 在Linux系统下Apache完美集成SVN(Yum安装版)