天天看點

centos下SVN搭建與使用

SVN作為新一代代碼版本管理工具,有很多優點,管理友善,邏輯明确,安全性高,代碼一緻性高。SVN資料存儲有兩種方式,BDB(事務安全表類型)和FSFS(一種不需要資料庫的存儲系統),為了避免在伺服器連接配接中斷時鎖住資料,FSFS是一種更安全也更多人使用的方式。SVN的運作方式也有兩種,一種是獨立伺服器,另一種是借助apache服務,各有利弊,下面就介紹一下這兩種方式各自的部署步驟。

   1、作為獨立伺服器運作:

   ①安裝svn,使用本地yum源安裝,作業系統鏡像裡自帶的就有,yum install svn,具體步驟請參考http://ailurus.blog.51cto.com/4814469/1168336;

   ②建立版本庫:

mkdir /svn/project        //建立版本庫所在檔案夾  

svnadmin create --fs-type fsfs /svn/project/first      

//建立版本庫,如果需要使用bdb方式存儲,則将fsfs改成bdb即可  

   ③初始化版本庫,即導入檔案到版本庫中:

svn import /home/software file:///svn/project/first --message "初始化版本"  

//将home檔案夾的檔案導入版本庫  

svn list --verbose file:///svn/project/first  //檢視導入的檔案

   ④啟動svn服務,svn服務預設端口為3690,可以使用“netstat -ntlp”指令檢視服務啟動是否成功:

svnserve -d -r /svn/project

   ⑤修改政策控制檔案,vi authz,如果以後要添加使用者,就将使用者名加在相應的使用者組(admin或者user)後面即可:

### 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

admin=first,second,third             //使用者組admin包含的成員

user=anyone                          //使用者組user包含的成員

# [/foo/bar]

# harry = rw

# &joe = r

# * =

# [repository:/baz/fuz]

# @harry_and_sally = rw

# * = r

[/]

@admin=rw                         //使用者組admin内成員擁有讀寫權限

@user=r                           //使用者組user内成員擁有讀權限

⑥添加svn通路使用者,vi passwd,為authz裡配置設定的使用者設定密碼,等号左邊為使用者名,等号右邊是密碼;

### 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.

[users]

# harry = harryssecret

# sally = sallyssecret

first=first

second=second

third=third

anyone=anyone

   ⑦修改svn讀取的權限政策檔案,vi /svn/project/first/conf/svnserve.conf:

anon-access = none    //不允許匿名使用者讀寫

auth-access = write

password-db = passwd  //svn讀取的passwd檔案

authz-db = authz      //svn讀取的權限控制檔案

   ⑧安裝svn用戶端,就可以使用用戶端通過如下的url就可以通路了:

   svn://IP位址/svn/project/first  

   2、借助apache伺服器,通過web端通路svn:

   ①給apache伺服器安裝兩個svn插件,這兩個插件同樣可以使用yum安裝:    

yum install mod_dav_svn     //使subversion與dav子產品通信的功能

yum install mod_authz_svn   //實作權限控制功能

   ②使用指令“httpd -M”可以檢視是否加載這兩個子產品,如加載,則有如下回應:

Loaded Modules:

core_module (static)

mpm_prefork_module (static)

http_module (static)

so_module (static)

auth_basic_module (shared)

auth_digest_module (shared)

authn_file_module (shared)

authn_alias_module (shared)

authn_anon_module (shared)

authn_dbm_module (shared)

authn_default_module (shared)

authz_host_module (shared)

authz_user_module (shared)

authz_owner_module (shared)

authz_groupfile_module (shared)

authz_dbm_module (shared)

authz_default_module (shared)

ldap_module (shared)

authnz_ldap_module (shared)

include_module (shared)

log_config_module (shared)

logio_module (shared)

env_module (shared)

ext_filter_module (shared)

mime_magic_module (shared)

expires_module (shared)

deflate_module (shared)

headers_module (shared)

usertrack_module (shared)

setenvif_module (shared)

mime_module (shared)

dav_module (shared)

status_module (shared)

autoindex_module (shared)

info_module (shared)

dav_fs_module (shared)

vhost_alias_module (shared)

negotiation_module (shared)

dir_module (shared)

actions_module (shared)

speling_module (shared)

userdir_module (shared)

alias_module (shared)

substitute_module (shared)

rewrite_module (shared)

proxy_module (shared)

proxy_balancer_module (shared)

proxy_ftp_module (shared)

proxy_http_module (shared)

proxy_ajp_module (shared)

proxy_connect_module (shared)

cache_module (shared)

suexec_module (shared)

disk_cache_module (shared)

cgi_module (shared)

version_module (shared)

authz_ldap_module (shared)

dav_svn_module (shared)

authz_svn_module (shared)

Syntax OK

③編輯apache服務配置檔案vi /etc/httpd/conf/httpd.conf,加入下面幾行:

<Location /svn>

DAV svn

SVNPath /svn/project/zbw

AuthzSVNAccessFile /etc/httpd/conf.d/authz

//apache伺服器讀取的權限政策檔案  

AuthType Basic

AuthName "Project"

AuthUserFile /etc/httpd/conf.d/passwd

//apache伺服器讀取的密碼存儲檔案

Require valid-user

   ④編輯檔案authz放在檔案夾/etc/httpd/conf.d中,檔案格式同文章上面的那個authz檔案,編輯檔案passwd放在檔案夾/etc/httpd/conf.d中,使用如下指令生成使用者名和密碼:

htpasswd -c /svn/project/first admin

//指令為htpasswd,-c為參數,/svn/project/first為通路的版本庫,admin為使用者名

然後重複輸入你想設定的密碼就可以自動存儲在檔案passwd中,預設為md5存儲。

   ⑤重新開機apache服務,就可以在網頁端使用剛才設定的使用者名密碼通路了,網址為http://192.168.2.100:8088/svn.

本文轉自 忘情OK  51CTO部落格,原文連結:http://blog.51cto.com/itchentao/1551219,如需轉載請自行聯系原作者