Linux上SVN的搭建使用(ab****43ab****43)

開發人員經常會上傳代碼,或者改對代碼做一些更改。svn就是用來將修改後的代碼更新到服務器上的。下面就來看一下怎麼在Linux環境下搭建svn服務(subversion)。

步驟: 
1、檢查是否已經有svn 
2、安裝subversion 
3、檢查是否安裝成功 
4、創建svn資源倉庫 
5、新增用戶及密碼,配置權限,配置資源庫權限 
6、啓動或者重啓服務 
7、從機安裝subversion 
8、測試

一、檢查是否已經有svn

如果沒有安裝就會是下面的樣子,提示找不到命令。

[root@localhost ~]# svnserve --version
-bash: svnserve: command not found

如果已經安裝,會顯示版本信息:

[root@localhost ~]#  svnserve --version
svnserve, version 1.6.11 (r934486)
   compiled Aug 17 2015, 08:37:43

Copyright (C) 2000-2009 CollabNet.
Subversion is open source software, see http://subversion.tigris.org/
This product includes software developed by CollabNet (http://www.Collab.Net/).

The following repository back-end (FS) modules are available:

* fs_base : Module for working with a Berkeley DB repository.
* fs_fs : Module for working with a plain file (FSFS) repository.

Cyrus SASL authentication is available.

二、安裝 
在Linux下安裝的是subversion,直接用yum 安裝即可。

[root@localhost ~]#
[root@localhost ~]# yum install -y subversion

三、檢查安裝是否成功 
同樣用的是 svnserve –version成功安裝會顯示版本信息

[root@localhost ~]# svnserve --version

四、創建svn資源倉庫 
配置文件就是在這一步生成。

[root@localhost ~]# svnadmin create /svndir
[root@localhost ~]# cd /svndir/
[root@localhost svndir]# ls
conf  db  format  hooks  locks  README.txt
[root@localhost svndir]# cd conf/
[root@localhost conf]# ls
authz  passwd  svnserve.conf

五、新增用戶及密碼,配置權限 
已經看到在倉庫下面生成了三個文件 
authz #權限配置文件 
passwd #用戶名密碼文件 
svnserve.conf #資源庫配置文件

[root@localhost conf]# vim passwd
### 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
yunwei = 123456
~

新增一行: 
yunwei = 123456 
新增用戶“yunwei”,密碼是“123456”

[root@localhost conf]# vim authz


[groups]
# harry_and_sally = harry,sally
# harry_sally_and_joe = harry,sally,&joe

[/]
* = r
@admin = rw
dangerman =

[svndir:/]
@admin = rw

在[groups]下面加入: 
* = r #所有用戶有讀權限 
dangerman = ##危險分子?什麼是危險分子?沒有任何權限

[svndir:/] ###定義目錄,項目的根目錄 
* = rw

[root@localhost conf]# vim svnserve.conf

這個配置文件打開下面幾行前面的註釋,刪除最前面的空格: 
anon-access = read 
auth-access = write 
password-db = passwd 
authz-db = authz 
realm = My First Repository

六、啓動或者重啓服務

[root@localhost conf]# /etc/init.d/svnserve start
Starting svnserve:                                     [  OK  ]

如果要指定目錄要加參數:

[root@localhost svndir]# mkdir /svndir/svn
[root@localhost svndir]# svnserve -d -r /svndir/svn  ####(只是看一下可以指定目錄,這個實驗不需要)
svnserve: Can't bind server socket: Address already in use

問題來了!!!問題來了: 
顯示Address already in use

原因在這裏:svnserve -d -r /svndir/svn 這條命令就是指定目錄的啓動。但是前面已經啓動一次了。解決辦法:

[root@localhost svndir]# /etc/init.d/svnserve stop
Stopping svnserve:                                         [  OK  ]
[root@localhost svndir]# svnserve -d -r /svndir/
[root@localhost svndir]# ls
conf  db  format  hooks  locks  README.txt 
[root@localhost svndir]# netstat -antlp | grep svn
tcp        0      0 0.0.0.0:3690                0.0.0.0:*                   LISTEN      5045/svnserve

七、測試,從機安裝subversion 
在次從機安裝也安裝一個subversion 用來測試。

注: 
服務主機:192.168.1.65 
從機:192.168.1.121

在從機上checkout 根目錄

[root@localhost ~]# svn checkout svn://192.168.1.65/svndir/
Checked out revision 0.

需要注意的這裏check的目錄跟服務主機裏面定義的[svndir]要一樣。

[root@localhost ~]# svn checkout svn://192.168.1.65/svndir/
svn: URL 'svn://192.168.1.65/svndir' doesn't exist

如果出現在這個報錯,就要檢查服務主機的auth配置文件了: 
如果配置文件的的目錄指定的是[svndir:/],而且svndir的目錄在根下(/svndir) 
那啓動的時候即嫑指定目錄直接用/etc/init.d/svnserve start 啓動即可。我們這裏目錄符合默認目錄,不用指定了。直接用/etc/init.d/svnserve start,或者不用指定目錄。 
svnserve -d -r /svndir/ 這表示指定目錄到/svndir/ 
目錄不對應會報錯。

7.1:在從機上從機:192.168.1.121上提交

[root@localhost ~]# ls
Desktop    Downloads  Pictures  svndir     Videos
Documents  Music      Public    Templates
[root@localhost ~]# cd svndir/
[root@localhost svndir]# ls
[root@localhost svndir]# touch xiao
[root@localhost svndir]# ls
xiao
[root@localhost svndir]# pwd
/root/svndir
[root@localhost svndir]# ls
xiao
[root@localhost svndir]# svn add /root/svndir/xiao
A         /root/svndir/xiao
[root@localhost svndir]# svn commit /root/svndir/xiao -m 1
Authentication realm: <svn://192.168.1.65:3690> My First Repository
Password for 'root':
Authentication realm: <svn://192.168.1.65:3690> My First Repository
Username: ^Csvn: Commit failed (details follow):
  n: Caught signal
[root@localhost svndir]# svn commit /root/svndir/xiao -m 1
Authentication realm: <svn://192.168.1.65:3690> My First Repository
Password for 'root':
Authentication realm: <svn://192.168.1.65:3690> My First Repository
Username: yunwei
Password for 'yunwei':

-----------------------------------------------------------------------
ATTENTION!  Your password for authentication realm:

   <svn://192.168.1.65:3690> My First Repository

can only be stored to disk unencrypted!  You are advised to configure
your system so that Subversion can store passwords encrypted, if
possible.  See the documentation for details.

You can avoid future appearances of this warning by setting the value
of the 'store-plaintext-passwords' option to either 'yes' or 'no' in
'/root/.subversion/servers'.
-----------------------------------------------------------------------
Store password unencrypted (yes/no)? yes
Adding         xiao
Transmitting file data .
Committed revision 1.

注意: 
1、提交代碼前,必須先cd到/root/svndir/(就是checkout下來的)目錄裏; 
2、服務器上沒有的文件,在客戶端需要先add預提交,再commit,如果服務器端已有的文件,直接commit

預提交的命令:

 svn add /root/svndir/xiao
  • 提交的命令:
svn commit /root/svndir/xiao -m 1

出現committed revision 1 提交成功了。

到服務端查看有沒有提交成功: 
服務主機:192.168.1.65

[root@localhost svndir]# svn checkout svn://192.168.1.65/svndir/
A    svndir/xiao
Checked out revision 1.
[root@localhost svndir]# ls
conf  db  format  hooks  locks  README.txt  svn  svndir
[root@localhost svndir]# cd svndir/
[root@localhost svndir]# ls
xiao

接下來測試更新:

從機:192.168.1.121:

[root@localhost svndir]# ls
xiao
[root@localhost svndir]# vim xiao

hello koby bryant !
~

修改了xiao 這個文件的內容,之前是空文件,現在加上一行內容。 
然後重新提交:

[root@localhost svndir]# svn commit /root/svndir/xiao -m 2
Sending        xiao
Transmitting file data .
Committed revision 2.

服務器主機:192.168.1.65

[root@localhost svndir]# svn up
     xiao
Updated to revision 2.
[root@localhost svndir]# ls
xiao
[root@localhost svndir]# vim xiao
hello koby bryant !
~

內容已經更改。

因爲是更改內容,目錄和文件已經有了,所以不用checkout了,直接svn up就可以了。

7.2、在服務器主機:192.168.1.65上提交

[root@localhost svndir]# ls
xiao  yao
[root@localhost svndir]# pwd
/svndir/svndir
[root@localhost svndir]# svn add /svndir/svndir/yao
A         /svndir/svndir/yao
[root@localhost svndir]# svn commit /svndir/svndir/yao -m 3
Authentication realm: <svn://192.168.1.65:3690> My First Repository
Password for 'root':
Authentication realm: <svn://192.168.1.65:3690> My First Repository
Username: yunwei
Password for 'yunwei':

-----------------------------------------------------------------------
ATTENTION!  Your password for authentication realm:

   <svn://192.168.1.65:3690> My First Repository

can only be stored to disk unencrypted!  You are advised to configure
your system so that Subversion can store passwords encrypted, if
possible.  See the documentation for details.

You can avoid future appearances of this warning by setting the value
of the 'store-plaintext-passwords' option to either 'yes' or 'no' in
'/root/.subversion/servers'.
-----------------------------------------------------------------------
Store password unencrypted (yes/no)? yes
Adding         yao
Transmitting file data .
Committed revision 3.

注意:還是要cd到/svndir/svndir裏面再預提交,然後提交。 
顯示Committed revision 3.就說明提交成功

到從機:192.168.1.121上更新看效果:

[root@localhost svndir]# svn up
A    yao
Updated to revision 3.
[root@localhost svndir]# ls
xiao  yao
[root@localhost svndir]# cat yao
hello rayallen

上面提交不管是在服務器主機上還是在從機上,都需要輸入服務器主機的root用戶密碼,以及在conf文件裏面設置的用戶和密碼。上面測試是用的文件測試,目錄同樣可以。 
比如: 
從機上:192.168.1.121

[root@localhost svndir]# mkdir xiaoyao
[root@localhost svndir]# ls
xiao  xiaoyao  yao
[root@localhost svndir]# svn add /root/svndir/xiaoyao/
A         /root/svndir/xiaoyao
[root@localhost svndir]# svn commit /root/svndir/xiaoyao/ -m 4
Adding         xiaoyao

Committed revision 4.

服務器主機上:192.168.1.65

[root@localhost svndir]# svn up
A    xiaoyao
Updated to revision 4.
[root@localhost svndir]# ls
xiao  xiaoyao  yao

至此,svn的安裝配置測試就成功了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章