Apache+svn

简介:

1.  Httpd yum安装:

[root@www_01 ~]# yum -y install httpd

[root@www_01 ~]# yum -y install mod_dav_svn   #安装svn模块以及subversion服务端

#subversion在这会被作为mod_dav_svn模块的相关依赖进行安装

 [root@www_01 ~]# rpm -qa subversion

 subversion-1.6.11-15.el6_7.x86_64

 

2.       创建版本库:

[root@www_01 ~]# mkdir /svn/test1 -p

[root@www_01 ~]# svnadmin create /svn/test1

 

3.       创建svn账户与密码:

[root@www_01 ~]# htpasswd -c /svn/test1/conf/passwd zkq

Adding password for user zkq

 

4.       分配svn帐号权限:

  [root@www_01 ~]# vi /svn/test1/conf/authz  #在最下面加入以下内容,保存退出。

[test1:/]     #指定版本库根目录下的权限

zkq = rw     #zkq组用户权限为读写

* = r     #其他用户只有读权限

 

5.       配置svn版本库文件系统权限:

   [root@www_01~]# chown -R apache.apache /svn/test1

   [root@www_01~]# chcon  -R -t  httpd_sys_content_t  /svn/test1  #selinux权限

 

6.  Apache与svn整合:

[root@www_01 ~]# vi /etc/httpd/conf.d/subversion.conf

LoadModule dav_svn_module    modules/mod_dav_svn.so   #加载dav_svn模块

LoadModule authz_svn_module  modules/mod_authz_svn.so  #加载权限设置模块

#

# Example configuration to enable HTTP access for a directory

#除了这两个模块,还要确保/etc/httpd/conf/httpd.conf文件中的dav_module模块也会被加载

# must be both:

#

#   a) readable and writableby the 'apache' user, and

#默认Apache的启动用户为apache,所以需要apache用户对版本库有读写权限

#

#   b) labelled with the'httpd_sys_content_t' context

 if using

#   SELinux

#selinux相关的安全上下文标签,如果开启了selinux,则版本库目录需要有httpd_sys_content_t安全上下文标签

 

# this configuration, run as root:

#以下内容是配置文件提供的操作步骤模版

#   # cd /var/www/svn

#   # svnadmin create stuff

#   # chown -R apache.apachestuff

#   # chcon -R -thttpd_sys_content_t stuff

#在最下面加入以下内容,保存退出!

<Location /svn>

   DAV svn

   SVNParentPath /svn           #SVNParentPath路径必须为svnadmincreate生成版本库路径的父目录,如上面建立数据仓库的命令为svnadmin create /svn/test1,则SVNParentPath/svn

   AuthType Basic

   AuthName "Welcome tosvn"

   AuthUserFile/svn/test1/conf/passwd

   AuthzSVNAccessFile/svn/test1/conf/authz

   Require valid-user

</Location>

[root@www_01 ~]# grep "dav_module"/etc/httpd/conf/httpd.conf

LoadModule dav_module modules/mod_dav.so

[root@www_01 ~]# /etc/init.d/svnserve  start

[root@www_01 ~]# /etc/init.d/httpd start

 

7.      客户端访问:

出错如下:

-<D:error><C:error/><m:human-readableerrcode="2"> Could not open the requested SVN filesystem

</m:human-readable></D:error>

解决方法:

SVNParentPath /svn   #SVNParentPath路径必须为svnadmin create生成版本库路径的父目录,如上面建立数据仓库的命令为svnadmin create /svn/test1,则SVNParentPath/svn

wKioL1bms0HgRUGrAAA27_U9lWE996.png


源码编译安装错误:

[root@www_01 tools]# cd subversion-1.8.15

[root@www_01 subversion-1.8.15]# ./configure  --prefix=/application/svn --with-apxs=/application/apache/bin/apxs--with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util  --with-ssl --with-zlib --enable-maintainer-mode

出现错误:

checking sqlite library version (via pkg-config)... no

 

An appropriate version of sqlite could not be found.  We recommmend

3.7.15.1, but require at least 3.7.12.

Please either install a newer sqlite on this system

 

or

 

get the sqlite 3.7.15.1 amalgamation from:

   http://www.sqlite.org/sqlite-amalgamation-3071501.zip

unpack the archive using unzip and rename the resulting

directory to:

/server/tools/subversion-1.8.15/sqlite-amalgamation

  解决办法:

[root@www_01tools]# wget http://www.sqlite.org/sqlite-amalgamation-3071501.zip

[root@www_01tools]# unzip sqlite-amalgamation-3071501.zip -d /server/tools/subversion-1.8.15/sqlite-amalgamation

[root@www_01subversion-1.8.15]# ls

aclocal.m4        config.nice    Makefile.in

autogen.sh        configure      NOTICE

BUGS              configure.ac   README

build             doc            sqlite-amalgamation

build.conf        gen-make.opts  subversion

build-outputs.mk  gen-make.py   tools

CHANGES           get-deps.sh    win-tests.py

COMMITTERS        INSTALL

config.log        LICENSE

[root@www_01subversion-1.8.15]# ./configure --prefix=/application/svn --with-apxs=/application/apache/bin/apxs--with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-zlib--enable-mod-activation --with-ssl

………………………………….

configure:WARNING: unrecognized options: --with-ssl

[root@www_01subversion-1.8.15]# make && make install

 

检查安装是否成功:

[root@www_01subversion-1.8.15]# /application/svn/bin/svnserve --version

svnserve,version 1.8.15 (r1718365)

   compiled Mar 11 2016, 22:37:40 onx86_64-unknown-linux-gnu

 

Copyright (C)2015 The Apache Software Foundation.

This softwareconsists of contributions made by many people;

see the NOTICEfile for more information.

Subversion isopen source software, see http://subversion.apache.org/

 

The followingrepository back-end (FS) modules are available:

 

* fs_fs : Modulefor working with a plain file (FSFS) repository.                                                

 

svnserve.conf文件内容的注解如下:

[general]

#匿名访问的权限,可以是read,write,none,默认为read
anon-access = none
#使授权用户有写权限 
auth-access = write
#密码数据库的路径 
password-db = /server/svn/repositories/conf/passwd
#访问控制文件 
authz-db = /server/svn/repositories/conf/authz
#认证命名空间,subversion会在认证提示里显示,并且作为凭证缓存的关键字 
realm = repositories
 
查看SVN监听的端口:

[root@www_01 conf]# netstat -tunlp|grep 3690
tcp        0      0 0.0.0.0:3690                0.0.0.0:*                   LISTEN      94596/svnserve
 
加入系统环境变量(此步为源码安装时必须要做的):
[root@www_01 ~]# echo "export PATH=/application/svn/bin:$PATH" >>/etc/profile
[root@www_01 ~]# echo "export PATH" >>/etc/profile
[root@www_01 ~]# source /etc/profile
[root@www_01 ~]# svnserve --version
svnserve, version 1.8.15 (r1718365)
   compiled Mar 11 2016, 22:37:40 on x86_64-unknown-linux-gnu
 
Copyright (C) 2015 The Apache Software Foundation.
This software consists of contributions made by many people;
see the NOTICE file for more information.
Subversion is open source software, see http://subversion.apache.org/
 
The following repository back-end (FS) modules are available:
 
* fs_fs : Module for working with a plain file (FSFS) repository.
 

停止启动SVN:

killall svnserve    #停止

/application/svn/bin/svnserve -d -r /server/svn/repositories  #单版本库启动
/application/svn/bin/svnserve -d -r /server/svn               #多版本库启动
 
查看Apache加载的模块及语法:

# /application/apache/bin/apachectl -t -D DUMP_MODULES
Loaded Modules:
 core_module (static)
 authn_file_module (static)
 authn_dbm_module (static)
substitute_module (static)
 deflate_module (static)
。。。。。。。。。。。。。。。。。。。。。。。。。。。
。。。。。。。。。。。。。。。。。。。。。。。。。。。
 so_module (static)
 dav_svn_module (shared)
 authz_svn_module (shared)
Syntax OK
 
检查svn是否与apache兼容:
[root@www_01 ~]# grep "dav_svn_module" /application/apache/conf/httpd.conf
LoadModule dav_svn_module     /application/svn/libexec/mod_dav_svn.so
[root@www_01 ~]# grep "authz_svn_module" /application/apache/conf/httpd.conf
LoadModule authz_svn_module   /application/svn/libexec/mod_authz_svn.so
两行信息,并且查看/usr/local/apache/modules 下是否有mod_dav_svn.so,
 和mod_authz_svn.so 文件

如果http.conf 中没有增加代码。modules 下有mod_dav_svn.so,
 和mod_authz_svn.so 文件,再http.conf中增加那两行代码。

如果没有mod_dav_svn.so,
 和mod_authz_svn.so,svn安装的错误。按照步骤重装。


使用post-commit 钩子文件实现自动部署:

 搭建svn都不是仅仅为了把代码存到仓库,而是同步部署到对应的项目。

在 svn目录的 /hooks里面有一堆tmpl,这些tmpl可以做很多事情,不过今天我们就说一下自动部署post-commit.tmpl。

位置在svn 版本库hooks 文件下 带tmpl 的文件全是模板文件

功能介绍:           

start-commit:            提交前触发事务

post-commit:             提交完成触发事务

post-lock:               对文件进行加锁操作之后执行该脚本

post-revprop-change:     版本属性修改后触发事务

post-unlock:             对文件进行解锁之后执行该脚本

pre-commit:             提交完成前执行

pre-lock:               对文件进行加锁操作之前执行该脚本

pre-revprop-change:     在修改版本属性之前,执行此脚本

pre-unlock:             对文件进行解锁操作之前执行该脚本

我们要用post-commit需要手动复制对应tmpl里面的内容到新的post-commit里面

cppost-commit.tmpl post-commit

step.1:

然后打开文件清空内容,修改为以下代码:

#!/bin/sh

export LANG=zh_CN.UTF-8

/usr/bin/svn update --username **** --password ****/var/www/test

其中第一行意思是:用sh来解析这个脚本,因为各种shell的语法有细微的差别

第二行是编码格式:这里我使用的是UTF-8

最后一行/usr/bin/svn 是svn的路径,不是项目路径,应该都是一样的,后半句分别是用户名密码、和项目路径。--username这个比较坑了,网上搜出来的很多都搞错了,前面其实是两个减号,英文输入法下的。

step.2:

修改post-commit的可执行权限

chmod 755 post-commit

step.3:

在服务器进入项目目录/var/www/test checkout 整个项目。

注意此处不要checkout文件夹,正确代码应该是这样:

svn checkout svn://{您的服务器地址}:{端口号}/test.   #注意目录后面还有一个点

注意:此处的/test 可不需要添加:( 添加的目的是为了实现多个项目。 )

svn checkout svn://{您的服务器地址}:3690 .       #注意目录后面还有一个点

至此,如果按照此步骤搞下来,应该已经没有问题了,你可以本地commit代码,自动同步到项目了。


常见错误,我遇到的

  1. 255错误:post-commit没有给执行权限 或者 头部没有执行用sh执行,就是没有#!/bin/sh

  2. 提示跳过目录:服务器目录没有checkout代码,记得一定要先checkout一次,才能同步(!,每次新建项目都需要)

  3. 什么提示也没有:这种情况出现在用工具commit的时候,成功了,但是就是没有同步,建议你到linux下,使用./post-commit手动执行看报什么错误。如果乱码,请将文件内编码格式修改为GBK

  4. 提示**** is a     direcitory:/usr/bin/svn你把这个搞错了,他不是一个目录,是svn的路径

常见错误及其解答:

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 -Rapache.apache /storage/web/aiezu就可以了。

 


本文转自 linuxzkq 51CTO博客,原文链接:http://blog.51cto.com/linuxzkq/1751040


相关文章
|
网络协议 Linux 网络安全
Linux下svn的安装以及在Apache服务下访问
最近安装SVN过程中遇到了很多坑,做一下记录。
202 0
Linux下svn的安装以及在Apache服务下访问
|
Linux Apache
Linux整合Apache和SVN
本篇内容记录了对Apache和SVN下载、安装、导入等操作。
119 1
|
Apache 网络协议 数据安全/隐私保护
puppet 整合SVN+APACHE
转载:http://blog.51cto.com/ywzhou/1576387 1、安装Apache [root@puppet ~]# yum install -y httpd httpd-devel [root@puppet ~]# service ...
1000 0
|
Apache 网络协议 C++
搭建SVN+APACHE环境
项目需求 根据开发需求,建立svn环境,同时建立source、bd分支,source分支所有人都能访问,bd分支管理员kazihuo可访问。同时,在此基础上构建apache,以便于相关人员能通过浏览器访问分支信息,权限配置同svn! SVN部分 服务安装 [root@KAZIHUO]#...
1165 0
|
Apache 数据安全/隐私保护
|
Apache 数据安全/隐私保护 Ubuntu
|
Linux Apache 数据安全/隐私保护
|
Apache 数据安全/隐私保护 开发工具

热门文章

最新文章

相关实验场景

更多

推荐镜像

更多