通过http访问svn服务器的配置方法 .

基本的安装包有: subversion /httpd/ svn的httpd的mod_dav_svn mod_authz_svn 两个模块.(yum install mod_dav_svn subversion httpd )

svn的服务形式应该是有两种: 1 通过svnserve建立的 通过svn://ip:port 端口默认是3690,这种形式; 2 通过apache httpd或者其他的web服务器的扩展模块,进行svn管理

对于svnserve,通过svnserve -d -r /var/www/svn 这种形式建立 daemon的后台进程,但是结束要 kill `pgrep svnserve` 这种形式 来kill掉,不知道有没有直接的比如 stop的方式.

通过http服务器来管理svn也很不错,可以很方便的浏览.其配置过程如下(首先几个软件都安装,这就不用说了.):

1.在 /etc/httpd/module下面 有两个 mod 关于 svn的.

2.在/etc/httpd/config.d/下有一个subversion.conf(没有就建立一个),其内容是:

复制代码
LoadModule dav_module         modules/mod_dav.so
LoadModule dav_svn_module     modules/mod_dav_svn.so
<Location /svn>
         DAV svn
         SVNPath /var/www/svn/
         AuthType Basic
         AuthName "Subversion repos"
         AuthUserFile /var/www/svn/repos1/conf/passwd
         Require valid-user
 </Location>

# To create a new repository "http://localhost/repos/stuff" using
# this configuration, run as root:
#
# # cd /var/www/svn
# # svnadmin create stuff
# # chown -R apache.apache stuff
# # chcon -R -t httpd_sys_content_t stuff

 

#<Location /repos>
# DAV svn
# SVNParentPath /var/www/svn
#
# # Limit write permission to list of valid users.
# <LimitExcept GET PROPFIND OPTIONS REPORT>
# # Require SSL connection for password protection.
# # SSLRequireSSL
#
# AuthType Basic
# AuthName "Authorization Realm"
# AuthUserFile /path/to/passwdfile
# Require valid-user
# </LimitExcept>
#</Location>

复制代码

其中/var/www/svn是准备放仓库的目录,这个目录可以放置多个代码仓库,AuthUserFile就是用户和密码的文件,也可以移动到其他地方单独管理.

/var/www/svn 下面可以通过 svnadmin createa /var/www/svn/repos1 来建立一个空的仓库.还可以建立多个仓库;这个目录貌似最好 给apche用户所有权限:chown -R apache.apache /var/www/svn ;在repos1/conf目录下可以进行一些账号密码 配置,就不多说了.建立的其他仓库 可以拷贝这些conf文件

其中AuthUserFile 是如何制作的呢?

复制代码
创建“ AuthUserFile ”设置所需的用户密码以及存储的文件

使用 apache bin/htpasswd 命令来创建。命令的格式为

htpasswd [-cmdpsD] passwordfile username


若第一次创建用户,我们必须使用参数“-c”来同时创建用户密码文件

htpasswd -c passwd robert

上述命令创建的一个文件“ passwd”,同时在文件里添加了一个 user named “robert”,执行该命令时会要求输入密码。


注意:创建第二或之后的用户时,一定不能用参数“ c ”,否则之前的用户就会被删除。


如果想要删除某个用户,我们可以使用下列命令:

    htpasswd -D passwd robert

这样, robert就被从 passwd中删除了。
复制代码

下面就是一个示例,创建两个用户 a b,密码 aaa,bbb,再删除。查看密码文件内容:

复制代码
[root@src-server websvn]# htpasswd accesspwd a
htpasswd: cannot modify file accesspwd; use '-c' to create it
[root@src-server websvn]# htpasswd -c accesspwd a
New password:
Re-type new password:
Adding password for user a
[root@src-server websvn]# ll accesspwd
-rw-r--r-- 1 root root 16 Jun 23 02:03 accesspwd
[root@src-server websvn]# htpasswd accesspwd b
New password:
Re-type new password:
Adding password for user b
[root@src-server websvn]# cat accesspwd
a:wpEqdKjINQsvM
b:JEpHUbhZZP3fc
[root@src-server websvn]# htpasswd -D accesspwd b
Deleting password for user b
[root@src-server websvn]# cat accesspwd
a:wpEqdKjINQsvM
[root@src-server websvn]#
复制代码

 

 

3. sudo service httpd restart 重启httpd apache 服务. 貌似很简单呢..回来再整理下svn的命令 补充.

然后通过 http://IP/svn/repos1可以访问这个仓库,可以建立多个仓库同时访问.不过直接访问 IP/svn 无法列出仓库的列表,apache显示 "forbidden \n You don't have permission to access /svn on this server"

 

对于一些svn的web管理程序也有,比如ViewVC 还有一些其他的管理svn的web程序,最好可以在web端创建仓库、权限管理就好了。目前寻找这样的svn web管理程序中。

CentOS 安装websvn直接yum即可,不需要配置mysql,只需要php的支持即可。

查看websvn的包文件

复制代码
[root@src-server ~]# yum install websvn
Loaded plugins: fastestmirror, presto, refresh-packagekit
Loading mirror speeds from cached hostfile
 * base: mirrors.btte.net
 * epel: ftp.kddilabs.jp
 * extras: ftp.stu.edu.tw
 * kernel-xen: us1.mirror.crc.id.au
 * updates: mirrors.tuna.tsinghua.edu.cn
Setting up Install Process
Package websvn-2.3.3-2.el6.noarch already installed and latest version
Nothing to do
[root@src-server ~]#rpm -ql websvn
/etc/httpd/conf.d/websvn.conf
/etc/websvn/config.php
/usr/share/doc/websvn-2.3.3
/usr/share/doc/websvn-2.3.3/changes.txt
/usr/share/doc/websvn-2.3.3/doc
/usr/share/doc/websvn-2.3.3/doc/install.html
/usr/share/doc/websvn-2.3.3/doc/style.css
/usr/share/doc/websvn-2.3.3/doc/templates.html
/usr/share/doc/websvn-2.3.3/license.txt
/usr/share/websvn
/usr/share/websvn/blame.php
/usr/share/websvn/cache
/usr/share/websvn/comp.php
/usr/share/websvn/diff.php
/usr/share/websvn/dl.php
/usr/share/websvn/filedetails.php
/usr/share/websvn/include
/usr/share/websvn/include/accessfile.php
/usr/share/websvn/include/auth.php
/usr/share/websvn/include/bugtraq.php
/usr/share/websvn/include/command.php
/usr/share/websvn/include/config.php
/usr/share/websvn/include/configclass.php
/usr/share/websvn/include/diff_inc.php
/usr/share/websvn/include/diff_util.php
/usr/share/websvn/include/header
/usr/share/websvn/include/setup.php
/usr/share/websvn/include/svnlook.php
/usr/share/websvn/include/template.php
/usr/share/websvn/include/utils.php
/usr/share/websvn/include/version.php
/usr/share/websvn/index.php
/usr/share/websvn/languages
/usr/share/websvn/languages/chinese-simplified.php
/usr/share/websvn/languages/languages.php
/usr/share/websvn/languages/省略省略省略
/usr/share/websvn/listing.php
/usr/share/websvn/log.php
/usr/share/websvn/revision.php
/usr/share/websvn/rss.php
/usr/share/websvn/temp
/usr/share/websvn/templates
/usr/share/websvn/templates/BlueGrey
/usr/share/websvn/templates/BlueGrey/省略省略省略
/usr/share/websvn/templates/Elegant
/usr/share/websvn/templates/Elegant/省略省略省略
/usr/share/websvn/templates/calm
/usr/share/websvn/templates/calm/省略省略省略
/usr/share/websvn/wsvn.php
/var/cache/websvn
复制代码

下面就是vim /etc/websvn/config.php,其实这个文件就是/usr/share/websvn/include/config.php,只是做了一个链接到etc目录,这种方法对于这种需要配置的web程序来说,还真是方便。

[root@src-server ~]# ll /etc/websvn/config.php
-rw-r--r-- 1 root root 21210 Jun 24 18:48 /etc/websvn/config.php
[root@src-server ~]# ll /usr/share/websvn/include/config.php
lrwxrwxrwx 1 root root 33 Jun 23 01:01 /usr/share/websvn/include/config.php -> ../../../../etc/websvn/config.php
[root@src-server ~]#

这里需要修改的配置选项有:

$config->parentPath('/srv/svn/');

$config->useMultiViews();

############ $config->useAuthenticationFile('/srv/svn/passwd');#这里是因为我 不知道如何在websvn上登录我的账号

 $config->setBlockRobots();#防止搜索程序收录

$config->expandTabsBy(4);#默认的8 似乎并不适合我的习惯

$config->useEnscript();##语法高亮 建议安装GNU Enscript高亮显示程序包,官方下载:http://www.iki.fi/~mtr/genscript/

#  关于编码 我不知道如何设置,SetInputEncoding 对于我的websvn-2.3.3不起作用,反而websvn出现500错误。

修改/etc/httpd/conf.d/websvn.conf 添加基本权限认证

复制代码
Alias /websvn /usr/share/websvn/

<Directory /usr/share/websvn/>
   Options MultiViews Indexes
   DirectoryIndex wsvn.php
   order allow,deny
   allow from all
        AuthType Basic
        AuthName "Authorization Realm"
        AuthUserFile /srv/svn/passwd
        Require valid-user

</Directory>
复制代码

websvn就可以在线浏览了。

 

 

 

 第三节:在线修改htpasswd密码

前面是由apache的htpasswd来通过 base 认证来进行账号管理的。通过这个小程序可以在线添加删除 校验账号密码。还有点小遗憾是 没有对 添加 删除 进行权限管理。校验后 才可以进行这个选项。

 

 

 

  由于我在svn的Loacation节点设置了用户认证AuthUserFile,并且必须通过验证后才能访问,所以这时候弹出来个登录对话框,这也正常不过了。但是我多次输入“正确的”用户名和密码,总是提示输入验证信息不正确,连续错误三次后,直接跳转到错误页面了:Authorization Required 

This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.

    这是怎么回事呢?我明明在svn仓库目录下conf的passwd加入了用户名和密码设置了!又尝试了几次,发现还是如此。然后我用htpasswd命令给passwd添加了用户密码,发现能正常访问了!但是通过svn://就不行了!这是怎么回事呢?后来打开passwd文件前后对比了一下,svn仓库目录下的是未做任何处理的原始字符串,而后者却做了加密处理......都怪我没有留意,经过思考后,发现应该是这样才对:

    通过http访问的账号是Apache http验证的。

    通过svn://访问的账号是svn仓库conf目录下passwd指定的。两个是独立的认证方式。

    于是按图索骥赶紧生成Apache http授权文件。产生方式:
    在命令行模式下,进入到.../apache/apache2/conf/目录下,运行下面的命令:

    bin/htpasswd -mc passwd <username>       #提示输入用户密码

 

    最后在Apache配置文件svn的location段中指定AuthUserFile的文件为刚才生成的授权文件。然后打开浏览器输入url->弹出登陆框->输入用户名密码,嘿,可以正常访问了

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值