操作系統(tǒng):ubuntu18.04.4 LTS
一、安裝步驟
1、安裝subversion
root@tencentCloud:~# apt update
root@tencentCloud:~# apt install subversion
輸入svnserve --version查看是否安裝成功:
root@tencentCloud:~# svnserve --version
svnserve, version 1.9.7 (r1800392)
compiled Mar 28 2018, 08:49:13 on x86_64-pc-linux-gnu
Copyright (C) 2017 The Apache Software Foundation.
This software consists of contributions made by many people;
see the NOTICE file for more information.
Subversion is open source software, see http://subversion.apache.org/
The following repository back-end (FS) modules are available:
* fs_fs : Module for working with a plain file (FSFS) repository.
* fs_x : Module for working with an experimental (FSX) repository.
* fs_base : Module for working with a Berkeley DB repository.
Cyrus SASL authentication is available.
2、創(chuàng)建倉庫目錄
root@tencentCloud:~# mkdir /home/svn
root@tencentCloud:~# mkdir /home/svn/test
創(chuàng)建/home/svn目錄作為存儲所有項(xiàng)目的位置,創(chuàng)建/home/svn/test作為test項(xiàng)目的倉庫目錄。
3、創(chuàng)建項(xiàng)目
root@tencentCloud:~# svnadmin create /home/svn/test
創(chuàng)建test項(xiàng)目,然后查看是否創(chuàng)建成功:
root@tencentCloud:~# ls /home/svn/test
conf db format hooks locks README.txt
二、修改配置
進(jìn)入/home/svn/test/conf/會看到3個(gè)配置文件:svnserve.conf, passwd, authz 。
svnserve.conf是配置svn的設(shè)置,passwd是配置用戶和密碼,authz是配置用戶的訪問權(quán)限。
1、svnserve.conf
[general]
anon-access = none #使非授權(quán)用戶無法訪問
auth-access = write #使授權(quán)用戶有寫權(quán)限
password-db = passwd #用戶密碼文件,當(dāng)前是統(tǒng)計(jì)目錄下的passwd文件,可以換成其他路徑
authz-db = authz #訪問控制文件,當(dāng)前是同級目錄下的authz文件,可以換成其他路徑
realm = My First Repository #認(rèn)證命名空間,隨便寫
2、passwd
[users]
test1 = 123
test2 = 456
test3 = abc
test4 = def
3、authz
#設(shè)置用戶組
[groups]
group1 = test1,test2
group2 = test3,test4
#設(shè)置權(quán)限
[/]
#用戶組group1對項(xiàng)目都沒有權(quán)限
@group1 =
#用戶組group2對項(xiàng)目有讀寫權(quán)限
@group2 = rw
三、啟動服務(wù)
root@tencentCloud:~# svnserve -d -r /home/svn/test
注意:默認(rèn)端口是3690,要開放防火墻端口。
測試?yán)。?/p>
root@tencentCloud:~# svn checkout svn://127.0.0.1/ --username test1 --password 123
svn: E170001: Authorization failed
root@tencentCloud:~# svn checkout svn://127.0.0.1/ --username test3 --password abc
Checked out revision 0.
可以看到group1的test1鑒權(quán)失敗,group2的test3拉取成功。
四、優(yōu)化
1、配置多項(xiàng)目
上面的配置和啟動方式只能開啟一個(gè)項(xiàng)目的svn,如果要配置多個(gè)項(xiàng)目,就要修改svnserve.conf和authz,并更改啟動方式。
- 先復(fù)制出passwd和authz文件到/home/svn/conf目錄下:
root@tencentCloud:~# cp /home/svn/test/conf/passwd /home/svn/conf
root@tencentCloud:~# cp /home/svn/test/conf/authz /home/svn/conf
root@tencentCloud:~# ls /home/svn/conf
authz passwd
- 修改svnserve.conf配置中password-db和authz-db的地址:
password-db = /home/svn/conf/passwd
authz-db = /home/svn/conf/authz
- 根據(jù)情況修改authz
#設(shè)置用戶組
[groups]
group1 = test1,test2
group2 = test3,test4
#所有項(xiàng)目
[/]
#用戶組group1對所有項(xiàng)目都有讀權(quán)限
@group1 = r
#test項(xiàng)目
[test:/]
#所有用戶都沒有test項(xiàng)目的權(quán)限
* =
#用戶組group2有test項(xiàng)目的讀寫權(quán)限
@group2 = rw
#用戶test4對test項(xiàng)目沒有權(quán)限
test4 =
4.更改啟動方式
root@huaweiCloud:~# svnserve -d -r /home/svn
驗(yàn)證:
root@tencentCloud:~# svn checkout svn://127.0.0.1/ --username test3 --password abc
Checked out revision 0.
2、配置系統(tǒng)服務(wù)
在shell中用svnserve啟動的方式每次開機(jī)都要操作一次,有點(diǎn)繁瑣,可以把它注冊成一個(gè)系統(tǒng)服務(wù),這樣就能用systemctl設(shè)置開機(jī)自啟。
在/etc/systemd/system/目錄下新建svnserve-daemon.service文件,并寫入以下內(nèi)容:
[Unit]
Description=svn server daemon
[Service]
Type=forking
ExecStart=/bin/sh -c "svnserve -d -r /home/svn"
ExecStop=/bin/sh -c "killall svnserve"
Restart=on-failure
[Install]
WantedBy=multi-user.target
然后輸入以下命令開啟服務(wù)并設(shè)置自啟動:
root@tencentCloud:~# systemctl start svnserve-daemon.service
root@tencentCloud:~# systemctl enable svnserve-daemon.service
配置完畢!
5、實(shí)踐補(bǔ)充
1、客戶端TortoiseSVN
linux下可以用svn命令來checkout,那么在windows下我們可以TortoiseSVN客戶端來拉取svn項(xiàng)目,下載地址為TortoiseSVN,里面有TortoiseSVN的安裝包以及漢化包。
2、svn log
之前自己摸索著配置的時(shí)候,把/home/svn/test/conf/svnserve.conf中的anon-access配置成了read,即 anon-access = read ,然后發(fā)現(xiàn)這種配置在輸入 svn log 的時(shí)候查看不了日志。
查找解決方法時(shí)發(fā)現(xiàn)應(yīng)該設(shè)置成none,即 anon-access = none 。
暫時(shí)還不知道是什么原理?