linux系統Centos環境下搭建SVN服務器及權限配置


linux系統Centos環境下如何搭建SVN服務器以及svnserve.conf、authz、passwd配置文件詳細介紹

 

1
至於svn的概念,這里就不做詳細闡述了,可以自行百度。簡單來講就是一個代碼管理工具。本筆記就是記錄下svn安裝搭建步驟而已。
1,yum安裝svn

  1. yum install subversion -y

2.驗證是否安裝完成

  1. svnserve --version

如顯示svn版本以及介紹信息,說明svn安裝成功。或直接netstat 或ps查看也可以。

3,創建svn版本庫
mkdir /home/svn   #把版本庫放在了home目錄下的svn文件夾
svnadmin create /home/svn/repo0 #將svn作為所有版本庫的目錄,並創建了一個名為repo0的版本庫

4.配置當前的版本庫
創建版本庫后,在當前版本庫目錄中會生成下面的文件,重點是配置文件。

  1. [root@yueminghai svn]# cd /home/svn/repo0
  2. [root@yueminghai repo0]# ll
  3. 總用量 24
  4. drwxr-xr-x 2 root root 4096 5 5 05:50 conf
  5. drwxr-sr-x 6 root root 4096 5 5 05:50 db
  6. -r--r--r-- 1 root root 2 5 5 05:50 format
  7. drwxr-xr-x 2 root root 4096 5 5 05:50 hooks
  8. drwxr-xr-x 2 root root 4096 5 5 05:50 locks
  9. -rw-r--r-- 1 root root 229 5 5 05:50 README.txt
  10. [root@yueminghai repo0]# ll conf
  11. 總用量 12
  12. -rw-r--r-- 1 root root 1080 5 5 05:50 authz
  13. -rw-r--r-- 1 root root 309 5 5 05:50 passwd
  14. -rw-r--r-- 1 root root 2279 5 5 05:50 svnserve.conf
  15.  

說明

(1)svnserve.conf:  svn服務綜合配置文件,只需要更改四行。
(2)passwd: 用戶名口令文件。前邊是svn賬號,后邊是密碼,密碼是明文存儲。配置哪些用戶可以授權使用,里邊包含用戶名和密碼。
(3)authz: 權限配置文件。
(4)注意更改svnserve.conf配置文件需要重啟svn,更高authz和passwd不需要重啟svn。重啟方法:pkill svnserve 然后重新svnserve -d -r 項目目錄即可。

4.1 修改passwd文件

  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. zhangsan = 123456
  10. lisi = 123456

前邊是svn賬號,后邊是密碼,密碼是明文存儲。配置哪些用戶可以授權使用,里邊包含用戶名和密碼。

4.2修改authz文件。
這個配置文件就兩個地方需要設置就可以了,一個是組和用戶的設置,另一個是版本庫的目錄格式配置以及權限分配。
4.2.1,組和用戶配置。
(1)一個組group可以包含一個和多個用戶,其中用戶名必須在用戶配置文件中已經定義。
(2)可以將指定具體組,比如開發組和運維組等。
4.2.2,版本庫配置以及權限分配。
版本庫目錄格式為  :
[版本庫:/項目/目錄]
用戶名 = 權限
@組名 = 權限
說明:
(1)權限,分為r,w,rw和空。空代表沒有任何權限
(2)版本庫目錄多種寫法,如果只寫根/代表對這個項目以及下邊所有目錄都有權限,如果單獨制定目錄,可以加上具體目錄名。
其中根是svn啟動的時候我們指定的-r指定的版本庫。
舉例如下:
[repo0:/] 代表對repo0所有版本庫設置權限權限
[repo0:/yueminghai]  代表對repo0版本庫下的yueminghai項目設置權限
[repo0:/yueminghai/demo]  代表對repo0版本庫下的yueminghai項目的demo目錄設置權限

 

  1. [aliases]
  2. # joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average
  3. #這里實現了別名的定義
  4. [groups]
  5. # harry_and_sally = harry,sally
  6. # harry_sally_and_joe = harry,sally,&joe
  7. team0=zhangsan #將上面創建的分成兩個組
  8. team1=lisi
  9. # [/foo/bar]
  10. # harry = rw
  11. # &joe = r #上面的別名定義在這里實現 &在這里理解為指針就很容易了
  12. # * =
  13. # [repository:/baz/fuz]
  14. # @harry_and_sally = rw
  15. # * = r
  16. [repo0:/]
  17. @team0=r
  18. @team1=rw
  19. yueminghai = r
  20. # 第一個小組只有讀取的權限,第二個小組有讀寫的權限
  21. # 單個版本庫的權限配置在這個文件中實現

4.3 修改svnserve.conf並重啟svn
vi  svnserve.conf 主要修改如下參數,其他不需要修改:

 

  1. anon-access = none
  2. auth-access = write
  3. password-db = passwd  #這個文件可以統一指定一個passwd文件便於統一管理不需要單獨每個版本庫單獨配置。
  4. authz-db = authz  #這個文件可以統一指定一個authz文件便於統一管理不需要單獨每個版本庫單獨配置。
  1. [general]
  2. ### These options control access to the repository for unauthenticated
  3. ### and authenticated users.  Valid values are "write", "read",
  4. ### and "none".  The sample settings below are the defaults.
  5. anon-access = none #沒有登錄的用戶不能訪問
  6. auth-access = write #登錄的用戶可以寫入
  7. ### The password-db option controls the location of the password
  8. ### database file.  Unless you specify a path starting with a /,
  9. ### the file's location is relative to the directory containing
  10. ### this configuration file.
  11. ### If SASL is enabled (see below), this file will NOT be used.
  12. ### Uncomment the line below to use the default password file.
  13. password-db = passwd #密碼文件為當前目錄下的passwd
  14. ### The authz-db option controls the location of the authorization
  15. ### rules for path-based access control.  Unless you specify a path
  16. ### starting with a /, the file's location is relative to the the
  17. ### directory containing this file.  If you don't specify an
  18. ### authz-db, no path-based access control is done.
  19. ### Uncomment the line below to use the default authorization file.
  20. authz-db = authz #驗證文件為當前目錄下的authz

這里着重說明下,參數前面不要有空格,否則啟動報錯。
5 導入、導出工程
導入

  1. $ mkdir MyProject
  2. $ mkdir MyProject/hehe
  3. $ mkdir MyProject/haha
  4. svn import MyProject svn://192.168.1.112/repo0/MyProject -m "first import project"

導出

  1. svn co svn://192.168.1.112/repo0/MyProject

配置完畢。有問題或建議的朋友可以留言。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM