1. 程式人生 > >linux下搭建SVN伺服器以及遇到的常見問題解決

linux下搭建SVN伺服器以及遇到的常見問題解決


                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: <svn://192.168.X.X:X> 。。。
                Password for 'root': 
                Authentication realm: <svn://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 (<FILE>) {
                    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,在最後新增如下資訊:
                <Location /project>
                    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
                </Location>

        3,啟動HTTPD伺服器
                # service httpd restart
                Stopping httpd:                                            [FAILED]
                Starting httpd:                                            [  OK  ]
四、此過程遇到的問題及解決方案