1. 程式人生 > >Linux搭建SVN伺服器

Linux搭建SVN伺服器

安裝: yum -y install subversion

14:21:13 [email protected] ~
$yum -y install subversion
Loaded plugins: fastestmirror, security
Setting up Install Process
Determining fastest mirrors
 * elrepo: mirrors.tuna.tsinghua.edu.cn
base                                                                     | 3.7 kB     00:00     
base/primary_db                                                          | 4.7 MB     00:00     
centos-sclo-rh                                                           | 2.9 kB     00:00     
centos-sclo-rh/primary_db                                                | 489 kB     00:42 
centos-sclo-rh/primary_db                                                | 1.2 MB     00:52     
centos-sclo-sclo                                                         | 2.9 kB     00:00     
centos-sclo-sclo/primary_db                                              | 151 kB     00:13     
elrepo                                                                   | 2.9 kB     00:00     
elrepo/primary_db                                                        | 682 kB     00:00     
epel                                                                     | 3.2 kB     00:00     
epel/primary                                                             | 3.2 MB     00:01     
epel                                                                          12522/12522
extras                                                                   | 3.4 kB     00:00     
extras/primary_db                                                        |  26 kB     00:00     
librehat-shadowsocks                                                     | 3.0 kB     00:00     
librehat-shadowsocks/primary_db                                          | 6.8 kB     00:00     
updates                                                                  | 3.4 kB     00:00     
updates/primary_db                                                       | 1.2 MB     00:00 

建立版本庫目錄: mkdir /home/svn/svnrepos   (位置隨意)

14:28:28 [email protected] ~
$mkdir /home/svn/svnrepos

建立SVN版本庫: svnadmin create /home/svn/svnrepos/project  (位置 + project(自定義名字))

14:29:21 [email protected] ~
$svnadmin create /home/svn/svnrepos/project

修改配置: cd /home/svn/svnrepos/project/conf

14:30:41 
[email protected]
~ $cd /home/svn/svnrepos/project/conf

修改authz: vi authz

14:30:46 [email protected] /home/svn/svnrepos/project/conf
$vi authz

[/]  (別打反了!!!) 賬號 = 許可權    例:rw(讀寫)

[/]
one = rw
two = rw
three = rw

修改passwd: vi passwd

14:32:43 [email protected] /home/svn/svnrepos/project
$vi passwd

格式:賬號 = 密碼

[users]
# harry = harryssecret
# sally = sallyssecret
one = 123
two = 123
three = 123

修改svnserve.conf: vi svnserve.conf

14:34:51 [email protected] /home/svn/svnrepos/project
$vi svnserve.conf
[general]
### These options control access to the repository for unauthenticated
### and authenticated users.  Valid values are "write", "read",
### and "none".  The sample settings below are the defaults.
anon-access = read     (去除前面#號)
auth-access = write    (去除前面#號)
### The password-db option controls the location of the password
### database file.  Unless you specify a path starting with a /,
### the file's location is relative to the directory containing
### this configuration file.
### If SASL is enabled (see below), this file will NOT be used.
### Uncomment the line below to use the default password file.
password-db = passwd   (去除前面#號)   或 
password-db = /home/svn/svnrepos/project/conf/passwd (passwd的路徑)
### The authz-db option controls the location of the authorization
### rules for path-based access control.  Unless you specify a path
### starting with a /, the file's location is relative to the the
### directory containing this file.  If you don't specify an
### authz-db, no path-based access control is done.
### Uncomment the line below to use the default authorization file.
authz-db = authz       (去除前面#號)   或 
authz-db = /home/svn/svnrepos/project/conf/authz     (authz的路徑)
### This option specifies the authentication realm of the repository.
### If two repositories have the same authentication realm, they should
### have the same password database, and vice versa.  The default realm
### is repository's uuid.
# realm = My First Repository

[sasl]
### This option specifies whether you want to use the Cyrus SASL
### library for authentication. Default is false.
### This section will be ignored if svnserve is not built with Cyrus
### SASL support; to check, run 'svnserve --version' and look for a line
### reading 'Cyrus SASL authentication is available.'
# use-sasl = true
### These options specify the desired strength of the security layer
### that you want SASL to provide. 0 means no encryption, 1 means
### integrity-checking only, values larger than 1 are correlated
### to the effective key length for encryption (e.g. 128 means 128-bit
### encryption). The values below are the defaults.
# min-encryption = 0
# max-encryption = 256

開啟防火牆:     多數情況下伺服器安裝完成,配置完成後,無法連線svn伺服器,均是防火牆問題,按照下面3條命令逐一執行即可新增3690埠(3690是SVN的埠)到防火牆: /sbin/iptables -I INPUT -p tcp --dport 3690 -j ACCEPT

14:40:56 [email protected] ~
$/sbin/iptables -I INPUT -p tcp --dport 3690 -j ACCEPT

儲存防火牆規則: /etc/init.d/iptables save

14:41:03 [email protected] ~
$/etc/init.d/iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]

重新啟動防火牆: service iptables restart

14:41:16 [email protected] ~
$service iptables restart
iptables:將鏈設定為政策 ACCEPT:filter nat                [確定]
iptables:清除防火牆規則:                                 [確定]
iptables:正在解除安裝模組:                                   [確定]
iptables:應用防火牆規則:                                 [確定]

啟動svn伺服器: svnserve -d -r /home/svn/svnrepos   (版本庫目錄)

14:41:43 [email protected] ~
$svnserve -d -r /home/svn/svnrepos

檢視SVN是否啟動: ps -ef | grep svn或ps aux | grep svn

14:41:54 [email protected] ~
$ps -ef | grep svn
root      1234     1  0 11:17 ?        00:00:00 svnserve -d -r /home/svn/svnrepos
root      1233  4321  0 14:42 pts/0    00:00:00 grep svn

14:42:01 [email protected] ~
$ps aux | grep svn
root      1234  0.0  0.0 123456  1200 ?        Ss   11:17   0:00 svnserve -d -r /home/svn/svnrepos
root      1233  0.0  0.0 123455   864 pts/0    S+   14:42   0:00 grep svn

若執行ps -ef | grep svn或ps aux | grep svn這兩條命令中的任意一條得到上面的結果,則svn已啟動

開發工具連線SVN: svn://ip地址:3690/project(project為“建立SVN版本庫”中自己自定的名字)  或     svn://ip地址/project

輸入連線地址後會彈出使用者名稱和密碼的輸入框,賬號和密碼在上面修改的passwd檔案中,輸入賬號和密碼,點選確定即可連線成功