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/first
⑤修改策略控制檔案,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/first
- 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://IP地址:連接埠/svn.
本文出自 “虹貓仗劍走天涯” 部落格,謝絕轉載!