svn +nginx
svn(subversion)是近年來崛起的版本管理工具,是cvs的接班人。目前,絕大多數開源軟件都使用svn作為代碼版本管理軟件。
svn服務器有2種運行方式:
1. 獨立服務器(本帖將重點討論這種方式)
2. 借助apache,目前nginx還不支持。
二種方式各有利弊,可以根據自己的需要進行配置,我不需要Http進行訪問,只需要客戶端可以Commit & update 就可以,下面是我選擇的第一種方式-獨立的SVN服務器。
系統環境:Centos-5.5 + Php-5.3.3 + Nginx-0.8.49 + Mysql-5.5.5m3+subersion-1.6.12
================================================================
============ 以上介紹系統完成,下面開始SVN安裝 ==============
================================================================
獲取svn安裝包,直接切換到root用戶進行所有操作:
最新版下載地址:http://subversion.apache.org/
直接到下載頁面:http://svn.haxx.se/dev/archive-2010-06/0320.shtml
[root@hexu.org]$ wget "http://subversion.tigris.org/downloads/subversion-1.6.12.tar.gz"
[root@hexu.org]$ wget "http://subversion.tigris.org/downloads/subversion-deps-1.6.12.tar.gz"
下載完成之后,開始編譯:
[root@hexu.org]$ tar xfvz subversion-1.6.12.tar.gz
[root@hexu.org]$ tar xfvz subversion-deps-1.6.12.tar.gz
[root@hexu.org]$ cd subversion-1.6.12
[root@hexu.org]$ ./configure -–prefix=/usr/local/svn --without-berkeley-db
注:以svnserve方式運行,不加apache編譯參數。以fsfs格式存儲版本庫,不編譯berkeley-db
如果最后出現下面WARNING,我們直接忽略即可。因為不使用BDB存儲。
configure: WARNING: we have configured without BDB filesystem support
You don't seem to have Berkeley DB version 4.0.14 or newer
installed and linked to APR-UTIL. We have created Makefiles which
will build without the Berkeley DB back-end; your repositories will
use FSFS as the default back-end. You can find the latest version of
Berkeley DB here:
http://www.sleepycat.com/download/index.shtml
編譯完成之后,開始安裝:
[root@hexu.org]$ make && make install
如果 make install 出現下面錯誤:
error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory
解決辦法:
#1、編輯/etc/ld.so.conf文件:
[root@hexu.org]$ vi /etc/ld.so.conf
# 添加下面一行
/usr/local/lib
#2、保存后運行ldconfig。
[root@hexu.org]$ /sbin/ldconfig
#3、再重新運行make install 問題得到解決。
[root@hexu.org]$ make install
#注:ld.so.conf和ldconfig用于維護系統動態鏈接庫
測試是否安裝成功:
[root@hexu.org]$ /usr/local/svn/bin/svnserve --version
如果顯示如下,svn安裝成功:
svnserve, version 1.6.12 (r955767)
compiled Sep 1 2010, 01:36:17
Copyright (C) 2000-2009 CollabNet.Subversion is open source software, see http://subversion.tigris.org/
This product includes software developed by CollabNet (http://www.Collab.Net/).
The following repository back-end (FS) modules are available:
* fs_fs : Module for working with a plain file (FSFS) repository.
Cyrus SASL authentication is available.
================================================================
============ 為了方便下操作,下面將SVN的BIN添加到PATH ====================
================================================================
在/etc/profile最后加入 SVN Path 以方便操作:
[root@hexu.org]$ vi /etc/profile
#比如像下面這樣添加:
PATH=/usr/local/php/bin:/usr/local/mysql/bin:/usr/local/svn/bin:$PATH
#添加完成執行,馬上生效:
[root@hexu.org]$ source /etc/profile
#測試查看設置是否成功
[root@hexu.org]$ echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/php/bin:/usr/local/mysql/bin:/usr/local/svn/bin:......
#上面已經包含了“/usr/local/svn/bin”,說明已經成功。
================================================================
============ 以上安裝完成,下面開始建立SVN版本庫 =============
================================================================
svn版本庫可建多個比如:repos,repos1,repos2….:
新建目錄和初始化版本庫:
#新建SVN存放數據文件的版本庫目錄
[root@hexu.org]$ mkdir -p /data/svn/repos
#初始化版本庫,生成相關配置文件:
[root@hexu.org]$ svnadmin create /data/svn/repos
初始化版本庫完成,開始設置配置svnserve.conf:
[root@hexu.org]$ vi /data/svn/repos/conf/svnserve.conf### This file controls the configuration of the svnserve daemon, if you
### use it to allow access to this repository. (If you only allow
### access through http: and/or file: URLs, then this file is
### irrelevant.)
### Visit http://subversion.tigris.org/ for more information.
[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 = none # 注意這里必須設置,否則所有用戶不用密碼就可以訪問
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
### 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
### 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 = repos
[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。
初始化版本庫完成,開始設置passwd 用戶賬號信息:
[root@hexu.org]$ vi /data/svn/repos/conf/passwd.
### This file is an example password file for svnserve.
### Its format is similar to that of svnserve.conf. As shown in the
### example below it contains one section labelled [users].
### The name and password for each user follow, one account per line.
# 在下面添加用戶和密碼,每行一組 username = password
[users]
# harry = harryssecret
# sally = sallyssecret
wangyong = password1
zhangsan = password2
初始化版本庫完成,開始設置authz 用戶訪問權限:
### This file is an example authorization file for svnserve.
### Its format is identical to that of mod_authz_svn authorization
### files.
### As shown below each section defines authorizations for the path and
### (optional) repository specified by the section name.
### The authorizations follow. An authorization line can refer to:
### - a single user,
### - a group of users defined in a special [groups] section,
### - an alias defined in a special [aliases] section,
### - all authenticated users, using the '$authenticated' token,
### - only anonymous users, using the '$anonymous' token,
### - anyone, using the '*' wildcard.
###
### A match can be inverted by prefixing the rule with '~'. Rules can
### grant read ('r') access, read-write ('rw') access, or no access
### ('').
[aliases]
# joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average
# [groups]
# harry_and_sally = harry,sally
# harry_sally_and_joe = harry,sally,&joe
# [/foo/bar]
# harry = rw
# &joe = r
# * =
# [repository:/baz/fuz]
# @harry_and_sally = rw
# * = r
#### ==================== 下面我新加的 ==================== ###
[groups]
grp_hexu = zhangsan, wangyong # grp_hexu 組包括兩個用戶zhangsan, wangyong
[/]
zhangsan = # zhangsan 對根目錄沒有任何權限
wangyong = rw # wangyong 對根目錄有讀寫權限
[repos:/hexu.org] # 對repos倉庫的hexu.org項目進行權限 限制
@grp_hexu = rw # 限制grp_hexu 組對hexu.org項目有讀寫權限
wangyong = # 限制wangyong所有權限,其它用戶有讀寫權限
[repos:/test.org] # 對repos倉庫的test.org項目進行權限 限制
@grp_hexu = rw # 限制grp_hexu 組對test.org項目有讀寫權限
zhangsan = r # 限制zhangsan只有讀權限,其它用戶有讀寫權限
其中,1個用戶組可以包含1個或多個用戶,用戶間以逗號分隔。
下面是舉例一個最簡單的svnserver.conf & passwd & authz配置:
## svnserver.conf 配置
[root@hexu.org]$ vi /data/svn/repos/conf/svnserve.conf
[general]
anon-access = none
auth-access = write
password-db = passwd
authz-db = authz
realm = repos
## passwd 配置
[root@hexu.org]$ vi /data/svn/repos/conf/passwd
[users]
#user1 = password1
#user2 = password2
zhangsan = ZhanGSan
## authz 配置
[root@hexu.org]$ vi /data/svn/repos/conf/authz
[aliases]
[groups]
[/]
zhangsan = rw
啟動svn服務器和新建svn用戶:
# 以SVN身份運行,新建用戶:
[root@hexu.org]$ useradd svn
#設置SVN版本庫的用戶和組:
[root@hexu.org]$ chown -R svn:svn /data/svn
#啟動svn:
[root@hexu.org]$ su - svn -c "svnserve -d --listen-port 9999 -r /data/svn"
#檢查是否啟動:
[root@hexu.org]$ps -ef|grep svn
#如果顯示如下,即為啟動成功:
svn 6941 1 0 15:07 ? 00:00:00 svnserve -d –listen-port 9999 -r /data/svn
額外說明:
su - svn表示以用戶svn的身份啟動svn
-d表示以daemon方式(后臺運行)運行
–listen-port 9999表示使用9999端口,可以換成你需要的端口。但注意,使用1024以下的端口需要root權限
-r /data/svn 指定SVN服務的根目錄是/data/svn
通過web方式訪問svn有很多方法,請參閱配置websvn或配置bsSvnBrowser的方法。
好了所有配置完成,可以使用客戶端SVN進行操作了。
================================================================
============ 以上介紹SVN版本庫完成,下面開始測試 =============
================================================================
服務測試方法 1:
[root@hexu.org]$ cd /tmp
[root@hexu.org]$ mkdir test
[root@hexu.org]$ touch test.txt
[root@hexu.org]$ svn import /tmp/test/ file:///usr/local/svndata/repos -m "this is thie first import"
[root@hexu.org]$ mkdir -p /tmp/test2
[root@hexu.org]$ cd /tmp/test2
[root@hexu.org]$ svn co file:///usr/local/svndata/repos /tmp/test2/
#或者:
[root@hexu.org]$ svn co svn://{your-server-ip}:9999/repos/
#這時應該可以看到文件test.txt.
服務測試方法 2:
[root@hexu.org]$ telnet {your-server-ip} 9999 檢查端口是不是通的
如果telnet 檢查不通,有可能是防火墻(iptables)里面端口沒開:
[root@hexu.org]$ vi /etc/sysconfig/iptables
-A RH-Firewall-1-INPUT -p tcp --dport 9999 -j ACCEPT
#保存完成,重啟 iptables
[root@hexu.org]$ /etc/init.d/iptables restart
#或
[root@hexu.org]$ service iptables restart
轉載于:https://blog.51cto.com/2526575/567184
總結
以上是生活随笔為你收集整理的svn +nginx的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 再谈querySelector和quer
- 下一篇: DLL返回自定义结构的数组