CentOS 上apache+Subversion搭建及常见问题处理

来源:互联网 发布:牙签弩淘宝多少钱 编辑:程序博客网 时间:2024/04/30 06:40

1. 前提关闭selinux 和 iptables

关闭selinux
vim /etc/selinux/config
#SELINUX=enforcing                                  加#注销
SELINUX=disabled                                    增加一行
保存。重启服务器
关闭iptables

server iptables stop

==============================================================================

2. 下载安装svn和模块

[root@lucifer ~]# yum install mod_dav_svn subversion

默认会安装apache

==============================================================================

3. 设置
3.1. Apache配置

[root@lucifer ~] vim /etc/httpd/conf/httpd.conf                      —— 按所需修改并存档
[root@lucifer ~] service httpd start
[root@lucifer ~] chkconfig httpd on

浏览器测试下apache是否安装成功http://ip
==============================================================================
3.2. Apache的Subversion 设置

[root@lucifer ~] 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

# 加入下列内容来支持基本验证,并将 Apache 指向实际放置版本库的地方。

单版本库
<Location /repos>                                                                  #svn在访问的时候用到,http://ip/repos
        DAV svn                                                                             #不用修改
        SVNPath /home/svn/repos                                            #资料库的绝对地址
        AuthType Basic
        AuthName "Subversion repos"
        AuthzSVNAccessFile /etc/svn-policy-file                      #账号权限文件
        AuthUserFile /etc/svn-auth-conf                                    #账号文件
        Require valid-user
</Location>

多版本库
<Location /svn>
        DAV svn
        SVNListParentPath on                                                     #这个是多版本特有的
        SVNParentPath /home/svn                                              #多版本库时的共同目录,与单版本的不同
        AuthType Basic
        AuthName "Subversion repos"
        AuthzSVNAccessFile /etc/svn-policy-file
        AuthUserFile /etc/svn-auth-conf
        Require valid-user
</Location>

注意事项:
(1)单个版本库就是SVNPath /home/svn/repos 跟svnadmin create /home/svn/repos 目录要一样,要不忙死你……【这个是对单个版本库】,多个版本库svn的主目录就是 SVNParentPath /home/svn
(2)AuthzSVNAccessFile是权限控制文件,单个版本库可要可不要,多个版本库要设置不同版本库的权限
(3)svn目录的权限设置成755

创建账号密码,使用 -cm 参数。它会创建文件并用 MD5 将口令加密。注意:第一次设置用户密码要加入 –c 这个参数,以后就可以不用了

[root@lucifer ~] htpasswd -cm /etc/svn-auth-conf yourusername
New password:
Re-type new password:

Adding password for user yourusername


[root@lucifer ~] htpasswd -m /etc/svn-auth-conf anotherusername
New password:
Re-type new password:
Adding password for user anotherusername
==============================================================================
3.3. 设置你的版本库

[root@lucifer ~] cd /home
[root@lucifer ~] mkdir svn
[root@lucifer ~] cd svn
[root@lucifer ~] svnadmin create repos
[root@lucifer ~] chown -R apache:apache repos
[root@lucifer ~] service httpd restart
==============================================================================
4、验证安装

打开浏览器,单版本库输入地址:http://服务器ip/repos。出现登陆窗口,输入用户名跟密码,如果安装成功将看见Revision 0:/ 的页面。

多版本库输入地址(多版本库需要设置权限才能访问):http://服务器ip/svn。出现登陆窗口,输入用户名跟密码,如果安装成功将看见Revision 0:/ 的页面。
==============================================================================
5.添加权限

vim /etc/svn-policy-file

[/]
* = r                                    #svn父目录所有人都与读的权限

[groups]                            #组
Admin = test                    #admin组成员

[REPO_NAME:/]
USER_NAME = rw

注意:[/]这个要设置好,这里面的权限设置可以让你对REPO_NAME的版本库有相同的权限,一般不要也行,个人建议不要

/部分中的*用来匹配匿名用户。对除只读以外的任何访问Apache AuthType Basic都会提示输入用户名和密码。REPO_NAME:/一节继承了之前的权限设置,于是匿名用户对其有只读权限。最后一项设置为用户USER_NAME授予来REPO_NAME源码库的读写权限。

==============================================================================

6.服务器端操作

在第一次执行脚本之前需要checkout,svn co http://服务器ip/repos /home/svn/repos

svn update /web目录/ --username 用户 --password 密码

==============================================================================

7.将SVN添加进selinux
chcon -R -t httpd_sys_content_t /home/svn
启动selinux

==============================================================================

8、可能遇到的问题

整个过程不会一帆风顺的,这里介绍一些可能遇到的问题。

1、【这个问题是我创建单个版本库时遇到的】安装好了后,浏览器打开http://服务器ip/svn,登陆出现不了页面,出现:
<D:error>

<C:error/> <m:human-readable errcode="2"> Could not open the requested SVN filesystem </m:human-readable> </D:error>
解决:这是httpd.conf里的<Locate svn>中的SVNPath指向错误没指到创建的资料库

2、输入账号密码提示不能认证,查看Apache的/etc/httpd/logs/error_log,有如下提示:

[Tue Oct 05 18:07:09 2010] [error] [client 125.223.118.90] (13)Permission denied: Could not open password file: /svn/svnroot/passwd
[Tue Oct 05 18:07:09 2010] [error] [client 125.223.118.90] access to /svn failed, reason: verification of user id 'test' not configured

从日志看,因为检查过配置文件没有拼错,所以可以肯定是权限问题。从ls命令的结果可以看出,由于passwd的权限是没有问题的。
后来看了一位朋友的帖子【Linux环境下搭建Apache+subversion+svnmanager】的启发,可能是SELinux引发的问题,
于是执行命令:
chcon -R -h -t httpd_sys_content_t /svn/svnroot
后来还是不行。执行以下命令后搞定
chcon -R -h -t httpd_sys_content_t /svn

总结教训:还是linux不熟悉的原因造成的,我是linux的新手。看来得恶补linux的基本知识。

3、组(group)设置

在TortoiseSVN中做Commit操作时可能遇到如下错误:

Can't open file '/svn/svnroot/telnet/db/txn-current-lock': Permission denied

可以将telnet的所属组设置为apache

chgrp -R apache  /svn/svnroot/telnet

4、文件夹创建删除属性

在TortoiseSVN中做Commit操作时可能遇到如下错误:

Can't open '/svn/svnroot/telnet/db/tempfile.tmp': Permission denied

Can't make directory '/svn/svnroot/telnet/dav/activities.d': Permission denied

设置telnet 群组的访问方式为“创建和删除文件”

0 0
原创粉丝点击