linux下搭建SVN服务器以及遇到的常见问题解决

开发环境:centos6.5

一、安装必须的软件包.

        使用命令yum install subversion (SVN服务器)

二,基本的SVN服务器配置
        1,新建一个目录用于存储SVN所有文件
                # mkdir /home/svn

        2,新建一个版本仓库
                # svnadmin create /home/svn/project

        3,初始化版本仓库中的目录
                # mkdir project project/server project/client project/test (建立临时目录)
                # svn import project/ file:///home/svn/project -m "初始化SVN目录"
                # rm -rf project (删除临时建立的目录)

        4,添加用户
                要添加SVN用户非常简单,只需在/home/svn/project/conf/passwd文件添加一个形如“username=password"的条目就可以了.为了测试,我添加了如下内容:
                [users]
                # harry = harryssecret
                # sally = sallyssecret
                pm = pm_pw                                                                      
//pm指用户名
                server_group = server_pw
                client_group = client_pw
                test_group = test_pw

        5,修改用户访问策略
                /home/svn/project/conf/authz记录用户的访问策略,以下是参考:
                        [groups]
                        project_p = pm                       
                        project_s = server_group
                        project_c = client_group
                        project_t = test_group
                        
                        [project:/]
                        @project_p = rw
                        * =
                        
                        [project:/server]
                        @project_p = rw
                        @project_s = rw
                        * =
                        
                        [project:/client]
                        @project_p = rw
                        @project_c = rw
                        * =
                        
                        [project:/doc]
                        @project_p = rw
                        @project_s = rw
                        @project_c = rw
                        @project_t = rw
                        * =
                以上信息表示,只有pm有根目录的读写权,server_group能访问server目录,client_group能访问client目录,所有人都可以访问doc目录.

        6,修改svnserve.conf文件,让用户和策略配置升效.
                svnserve.conf内容如下:
                        [general]
                        anon-access = none
                        auth-access = write
                        password-db = /home/svn/project/conf/passwd
                        authz-db = /home/svn/project/conf/authz

        7,启动服务器
                # svnserve -d -r /home/svn

        8,测试服务器
               # svn co svn://192.168.X.X/project
                Authentication realm: 。。。
                Password for 'root': 
                Authentication realm: 192.168.X.X:X>。。。
                Username: pm
                Password for 'pm': 
                A    project/test
                A    project/server
                A    project/client
                Checked out revision 1.  ( 表示测试提取成功 )

                # cd project/server
                # vim main.c
                # svn add main.c 
                # svn commit main.c -m "test"
                Adding         main.c
                Transmitting file data .
                Committed revision 2.  ( 测试提交成功 )
其中192.168.X.X指自己虚拟机的Ip地址
三,配置SVN服务器的HTTP支持
        1,转换SVN服务器的密码
                由于SVN服务器的密码是明文的,HTTP服务器不与支持,所以需要转换成HTTP支持的格式。这是借用别人的一个Perl脚本完成这个工作(感谢huabo).
                脚本内容如下:
                # cd /home/svn/project/conf/
                # cat PtoWP.pl 
                #!/usr/bin/perl
                # write by huabo, 2009-11-20
                
                use warnings;
                use strict;
                
                #open the svn passwd file
                open (FILE, "passwd") or die ("Cannot open the passwd file!!!\n");
                
                #clear the apache passwd file
                open (OUT_FILE, ">webpasswd") or die ("Cannot open the webpasswd file!!!\n");
                close (OUT_FILE);
                
                #begin
                foreach () {
                    if($_ =~ m/^[^#].*=/) {
                        $_ =~ s/=//;
                        `htpasswd -b webpasswd $_`;
                    }
                }

                # ./PtoWP.pl ( 先给该脚本加可执行权限,然后执行以转换密码 )
                Adding password for user pm
                Adding password for user server_group
                Adding password for user client_group
                Adding password for user test_group
                现在目录下会多一个webpasswd文件。

        2,修改httpd.conf,添加关于SVN服务器的内容
                编辑/etc/httpd/conf/httpd.conf,在最后添加如下信息:
               
                    DAV svn
                    SVNPath /home/svn/project/
                    AuthType Basic
                    AuthName "svn for project" 
                    AuthUserFile /home/svn/project/conf/webpasswd 
                    AuthzSVNAccessFile /home/svn/project/conf/authz
                    Satisfy all
                    Require valid-user
               

        3,启动HTTPD服务器
                # service httpd restart
                Stopping httpd:                                            [FAILED]
                Starting httpd:                                            [  OK  ]
四、此过程遇到的问题及解决方案

1、 service httpd restart  在重启httpd的时候出现  :
Starting httpd: Syntax error on line 993 of /etc/httpd/conf/httpd.conf:
Unknown DAV provider: svn

这是因为系统没有安装mod_dav_svn,它是Subversion与Apache之间的接口(通过它,Apache就可以访问版本库,可以让客户端也使用HTTP的扩展协议 WebDAV/DeltaV进行访问)

采用命令yum install mod_dav_svn   安装mod_dav_svn即可解决问题


2、通过svn从从客户端提交代码时出现

svn: Can't open file '/home/svn/project/db/txn-current-lock': Permission denied

最直接的办法是给它权限即用  sudo chmod 777 /home/svn/project 即可解决问题


3、svnserve -d -r /home/svn在启动hhtpd时出现:svnserve: 不能绑定服务器套接字: 地址已在使用

说明该进程正在使用可以用命令 ps -aux 查看进程

用命令kill -9 +进程标识号来强行终止进程即可解决


 五、用浏览器访问http://192.168.X.X/project/server/测试

输入用户名跟密码登陆出现下图及证明正确了






你可能感兴趣的:(linux下搭建SVN服务器以及遇到的常见问题解决)