iT邦幫忙

DAY 11
9

關於IT資訊界的筆記和學習紀錄系列 第 15

SVN 入門安裝設定教學(下)

  1. 建立目錄及放置檔案
    6.1 在建立目錄和檔案時的結構可依自行需求設定

    [root@localhost ~]# cd /tmp
    [root@localhost ~]# mkdir mytestproj #建立mytestproj資料夾
    [root@localhost ~]# cd mytestproj
    [root@localhost ~]# mkdir configurations options main
    [root@localhost ~]# vim configurations/testconf1.cfg #內容可自行輸入
    [root@localhost ~]# vim options/testopts1.cfg
    [root@localhost ~]# vim main/mainfile1.cfg

6.2 匯入
把剛剛所建立好的資料匯入到 subversion

[root@localhost ~]# svn import /tmp/mytestproj/ file:///var/www/svn/repos/mytestproj -m "Initial repository layout for mytestproj"
Adding         /tmp/mytestproj/main
Adding         /tmp/mytestproj/main/mainfile1.cfg
Adding         /tmp/mytestproj/configurations
Adding         /tmp/mytestproj/configurations/testconf1.cfg
Adding         /tmp/mytestproj/options
Adding         /tmp/mytestproj/options/testopts1.cfg
Committed revision 1.

登入網頁測試http:// yourmahcine/repos (yourmachine請輸入自己IP或是網址)
會看到下圖,且可以點選mytestproj查詢內容

6.3 取出
此時可以看到匯入的資料,除了文字檔外,都可點選下載。
這邊來測試用另一台Linux主機上使用它。此操作為另一台Linux主機

[root@localhost ~]#  cd /tmp
[root@localhost ~]#  svn co http:// yourmahcine /repos/mytestproj
                                           #(yourmachine請輸入自己IP或是網址)
A    mytestproj/main
A    mytestproj/main/mainfile1.cfg
A    mytestproj/configurations
A    mytestproj/configurations/testconf1.cfg
A    mytestproj/options
A    mytestproj/options/testopts1.cfg
Checked out revision 1.

6.4 編輯及提交
此時已經從Subversion伺服器取出第一版。現在來試試編輯一些東西後在提交回Subversion伺服器,此操作為另一台Linux主機

[root@localhost ~]#  cd mytestproj/
[root@localhost ~]#  vim configurations/testconf1.cfg  #自行加入或刪除一些內容
[root@localhost ~]#  svn commit -m "Added a line to testconf1.cfg."
Sending        configurations/testconf1.cfg
Transmitting file data .
Committed revision 2.

6.5 新增或刪除物件
在新增上使用Add這個參數,刪除使用delete這個參數,設定完後會發現在版本上會變為第3版,此操作為另一台Linux主機。
不管在做任何的操作之前都一定要先更新一次,再做動作。

[root@localhost ~]#  svn co http:// yourmahcine /repos/mytestproj
                                                   #(yourmachine請輸入自己IP或是網址)
A    mytestproj/main
A    mytestproj/main/mainfile1.cfg
A    mytestproj/configurations
A    mytestproj/configurations/testconf1.cfg
A    mytestproj/options
A    mytestproj/options/testopts1.cfg
Checked out revision 2.

[root@localhost ~]#  cd mytestproj
[root@localhost ~]#  cp /etc/yum.repos.d/CentOS-Base.repo configurations/
[root@localhost ~]#  svn add configurations/CentOS-Base.repo   #新增檔案
A         configurations/CentOS-Base.repo

[root@localhost ~]#  svn commit -m "Added the CentOS Yum repo file."
Adding         configurations/CentOS-Base.repo
Transmitting file data .
Committed revision 3.

6.6 還原
如果在臨時上有問題要還原到之前的版本的話,可以先查看log,這邊會存放每次所提交的訊息。在針對log部份做還原。
Log 查詢版本

[root@localhost ~]#   svn log http://yoursvnserver/repos
                  #(yourmachine請輸入自己IP或是網址),此為針對整個版本庫查詢
[root@localhost ~]#  svn log http://yoursvnserver/repos/mytestproj
                  #(yourmachine請輸入自己IP或是網址),此為針對個別項目查詢

還原版本

[root@localhost ~]#   svn co -r 1 http://yoursvnserver/repos/mytestproj
                    #(yourmachine請輸入自己IP或是網址),數字1為要還原的版本

6.7 存取控制清單
簡單的說這個部份就是權限的設定,可以給使用者寫入或讀取的設定。
此設定都是透過 AuthzSVNAccessFile這個檔案選項來完成的,以一個檔名來作為參數。

[root@localhost ~]#  vim /etc/httpd/conf.d/subversion.conf
<Location /repos>
        DAV svn
        SVNParentPath /var/www/svn/repos
        AuthzSVNAccessFile /etc/svn-acl-conf     #加入此段,路徑部份可自己修改
        AuthType Basic
        AuthName "Subversion repos"
        AuthUserFile /etc/svn-auth-conf
        Require valid-user
</Location>

6.8 再來就可以依自行設定的路徑建立檔案,這邊是建立於 /etc/svn-acl-config
當中存取權可以是 r(唯讀)、rw(讀寫)、或空白(禁止存取)。預設的 ACL 是禁止用戶存取版本。

[root@localhost ~]#  vim /etc/svn-acl-config
[framework:/]
john =  r
joe = rw

也可以在名叫 groups 的分段內建立群組,然後在存取控制清單內將 @ 符號放在群組前面

[groups]
staff = joe, george

[framework:/]
john =  r
@staff = rw

如果想令所有用戶能閱讀每個版本庫,你可以為每個版本庫的根目錄加入以下一個分段
[/]
* = r

到這邊SVN的設定大概都完成了。

SVN 入門安裝設定教學(上)
全文同步於FAQ-BOOK
IT鐵人文章分享


上一篇
SVN 入門安裝設定教學(上)
下一篇
NFS Server端設定
系列文
關於IT資訊界的筆記和學習紀錄41
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言