您的位置:首页 > 运维架构 > Apache

Apache+svn

2016-03-14 20:52 597 查看
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/test13. 创建svn账户与密码:[root@www_01 ~]# htpasswd -c /svn/test1/conf/passwd zkqAdding 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.confLoadModule 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.confLoadModule dav_module modules/mod_dav.so[root@www_01 ~]# /etc/init.d/svnserve start[root@www_01 ~]# /etc/init.d/httpd start7. 客户端访问:出错如下:-<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。源码编译安装错误:[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 recommmend3.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.zipunpackthe archive using unzip and rename the resultingdirectory 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]# lsaclocal.m4 config.nice Makefile.inautogen.sh configure NOTICEBUGS configure.ac READMEbuild doc sqlite-amalgamationbuild.conf gen-make.opts subversionbuild-outputs.mk gen-make.py toolsCHANGES get-deps.sh win-tests.pyCOMMITTERS INSTALLconfig.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 --versionsvnserve,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-commitstep.1:然后打开文件清空内容,修改为以下代码:#!/bin/shexport 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-commitstep.3:在服务器进入项目目录/var/www/test checkout 整个项目。注意此处不要checkout文件夹,正确代码应该是这样:svn checkout svn://{您的服务器地址}:{端口号}/test. #注意目录后面还有一个点注意:此处的/test 可不需要添加:( 添加的目的是为了实现多个项目。 )svn checkout svn://{您的服务器地址}:3690 . #注意目录后面还有一个点至此,如果按照此步骤搞下来,应该已经没有问题了,你可以本地commit代码,自动同步到项目了。常见错误,我遇到的255错误:post-commit没有给执行权限 或者 头部没有执行用sh执行,就是没有#!/bin/sh提示跳过目录:服务器目录没有checkout代码,记得一定要先checkout一次,才能同步(!,每次新建项目都需要)什么提示也没有:这种情况出现在用工具commit的时候,成功了,但是就是没有同步,建议你到linux下,使用./post-commit手动执行看报什么错误。如果乱码,请将文件内编码格式修改为GBK提示**** is a direcitory:/usr/bin/svn你把这个搞错了,他不是一个目录,是svn的路径[b]常见错误及其解答:[/b]1、svn checkout(svn检出)时错误一: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时错误二: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 -Rapache.apache /storage/web/aiezu就可以了。本文出自 “兰州linux运维” 博客,请务必保留此出处http://linuxzkq.blog.51cto.com/9379412/1751040
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: