CentOS下SVN伺服器的搭建使用

來源:互聯網
上載者:User

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

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

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

    ②建立版本庫:

 
  1. mkdir /svn/project        //建立版本庫所在檔案夾  
  2. svnadmin create --fs-type fsfs /svn/project/first      
  3. //建立版本庫,如果需要使用bdb方式儲存,則將fsfs改成bdb即可  

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

 
  1. svn import /home/software file:///svn/project/first --message "初始化版本"   
  2. //將home檔案夾的檔案匯入版本庫  
  3. svn list --verbose file:///svn/project/first  //查看匯入的檔案 

    ④啟動svn服務,svn服務預設連接埠為3690,可以使用“netstat -ntlp”命令查看服務啟動是否成功:

 
  1. svnserve -d -r /svn/project/first 

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

 
  1. ### This file is an example authorization file for svnserve. 
  2. ### Its format is identical to that of mod_authz_svn authorization 
  3. ### files. 
  4. ### As shown below each section defines authorizations for the path and 
  5. ### (optional) repository specified by the section name. 
  6. ### The authorizations follow. An authorization line can refer to: 
  7. ###  - a single user, 
  8. ###  - a group of users defined in a special [groups] section, 
  9. ###  - an alias defined in a special [aliases] section, 
  10. ###  - all authenticated users, using the '$authenticated' token, 
  11. ###  - only anonymous users, using the '$anonymous' token, 
  12. ###  - anyone, using the '*' wildcard. 
  13. ### 
  14. ### A match can be inverted by prefixing the rule with '~'. Rules can 
  15. ### grant read ('r') access, read-write ('rw') access, or no access 
  16. ### (''). 
  17.  
  18. [aliases] 
  19. # joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average 
  20.  
  21. [groups] 
  22. # harry_and_sally = harry,sally 
  23. # harry_sally_and_joe = harry,sally,&joe 
  24. admin=first,second,third             //使用者組admin包含的成員 
  25. user=anyone                          //使用者組user包含的成員 
  26.  
  27. # [/foo/bar] 
  28. # harry = rw 
  29. # &joe = r 
  30. # * = 
  31.  
  32. # [repository:/baz/fuz] 
  33. # @harry_and_sally = rw 
  34. # * = r 
  35.  
  36. [/] 
  37. @admin=rw                         //使用者組admin內成員擁有讀寫權限 
  38. @user=r                           //使用者組user內成員擁有讀許可權 

    ⑥添加svn訪問使用者,vi passwd,為authz裡指派的使用者設定密碼,等號左邊為使用者名稱,等號右邊是密碼;

 
  1. ### This file is an example password file for svnserve. 
  2. ### Its format is similar to that of svnserve.conf. As shown in the 
  3. ### example below it contains one section labelled [users]. 
  4. ### The name and password for each user follow, one account per line. 
  5.  
  6. [users] 
  7. # harry = harryssecret 
  8. # sally = sallyssecret 
  9.  
  10. first=first 
  11. second=second 
  12. third=third 
  13. anyone=anyone 

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

 
  1. anon-access = none  //不允許匿名使用者讀寫
  2. auth-access = write 
  3. password-db = passwd  //svn讀取的passwd檔案
  4. authz-db = authz  //svn讀取的許可權控制檔案

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

    svn://IP地址/svn/project/first  

    2、藉助apache伺服器,通過web端訪問svn:

    ①給apache伺服器安裝兩個svn外掛程式,這兩個外掛程式同樣可以使用yum安裝:    

 
  1. yum install mod_dav_svn     //使subversion與dav模組通訊的功能 
  2. yum install mod_authz_svn   //實現許可權控制功能 

    ②使用命令“httpd -M”可以查看是否載入這兩個模組,如載入,則有如下回應:

 
  1. Loaded Modules: 
  2.  core_module (static) 
  3.  mpm_prefork_module (static) 
  4.  http_module (static) 
  5.  so_module (static) 
  6.  auth_basic_module (shared) 
  7.  auth_digest_module (shared) 
  8.  authn_file_module (shared) 
  9.  authn_alias_module (shared) 
  10.  authn_anon_module (shared) 
  11.  authn_dbm_module (shared) 
  12.  authn_default_module (shared) 
  13.  authz_host_module (shared) 
  14.  authz_user_module (shared) 
  15.  authz_owner_module (shared) 
  16.  authz_groupfile_module (shared) 
  17.  authz_dbm_module (shared) 
  18.  authz_default_module (shared) 
  19.  ldap_module (shared) 
  20.  authnz_ldap_module (shared) 
  21.  include_module (shared) 
  22.  log_config_module (shared) 
  23.  logio_module (shared) 
  24.  env_module (shared) 
  25.  ext_filter_module (shared) 
  26.  mime_magic_module (shared) 
  27.  expires_module (shared) 
  28.  deflate_module (shared) 
  29.  headers_module (shared) 
  30.  usertrack_module (shared) 
  31.  setenvif_module (shared) 
  32.  mime_module (shared) 
  33.  dav_module (shared) 
  34.  status_module (shared) 
  35.  autoindex_module (shared) 
  36.  info_module (shared) 
  37.  dav_fs_module (shared) 
  38.  vhost_alias_module (shared) 
  39.  negotiation_module (shared) 
  40.  dir_module (shared) 
  41.  actions_module (shared) 
  42.  speling_module (shared) 
  43.  userdir_module (shared) 
  44.  alias_module (shared) 
  45.  substitute_module (shared) 
  46.  rewrite_module (shared) 
  47.  proxy_module (shared) 
  48.  proxy_balancer_module (shared) 
  49.  proxy_ftp_module (shared) 
  50.  proxy_http_module (shared) 
  51.  proxy_ajp_module (shared) 
  52.  proxy_connect_module (shared) 
  53.  cache_module (shared) 
  54.  suexec_module (shared) 
  55.  disk_cache_module (shared) 
  56.  cgi_module (shared) 
  57.  version_module (shared) 
  58.  authz_ldap_module (shared) 
  59.  dav_svn_module (shared) 
  60.  authz_svn_module (shared) 
  61. Syntax OK 

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

 
  1. <Location /svn> 
  2. DAV svn 
  3. SVNPath /svn/project/first 
  4. AuthzSVNAccessFile /etc/httpd/conf.d/authz
  5. //apache伺服器讀取的權限原則檔案   
  6. AuthType Basic 
  7. AuthName "Project" 
  8. AuthUserFile /etc/httpd/conf.d/passwd 
  9. //apache伺服器讀取的密碼隱藏檔
  10. Require valid-user 

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

 
  1. htpasswd -c /svn/project/first admin 
  2. //命令為htpasswd,-c為參數,/svn/project/first為訪問的版本庫,admin為使用者名稱 

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

    ⑤重啟apache服務,就可以在網頁端使用剛才設定的使用者名稱密碼訪問了,網址為http://IP地址:連接埠/svn.

本文出自 “虹貓仗劍走天涯” 部落格,謝絕轉載!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.