RT, 軟件採用yum方式安裝。
一、軟件安裝
1. 安裝SVN、Apache及其他相關
yum install httpd mod_dav_svn subversion mod_ssl
2. 測試安裝是否成功
出現截圖所示內容表示安裝成功,下面開始配置
二、配置SVN
1.創建svn服務器根文件夾
#mkdir /home/svn
那麼以後我的每個項目,如果需要提交到svn服務器上,我都應該放到這個路徑下面去了
2.創建一個版本庫
#svnadmin create /home/svn/kbzc
3.配置配置權限、用戶等
新建用戶文件:(用vi編輯器就可以)
# vi /home/svn/svn_passwd
[users]
usera=666666
userb=666666
接下來需要配置用戶的讀寫權限,同樣的,單獨新建一個文件,來管理所有的項目
# vi /home/svn/svn_authz
文件的內容一般有這樣幾個部分:
[aliases]
[groups] #svn的用戶組
admins = usera #admins用戶組下目前只有hujie一個用戶,多個用英文逗號隔開
[kbzc:/] #kbzc版本庫的根目錄
@admins = rw #用戶組前面需要加上@符號,rw表示讀、寫權限
* = #其他一切用戶連讀都不讓讀
啓用自定義配置:
vi /home/svn/kbzc/conf/svnserve.conf
啓用[general]的幾行
[general]
anon-access = none
auth-access = write
password-db = /home/svn/svn_passwd #這就是我建立的統一用戶文件
authz-db = /home/svn/svn_authz #我建立的統一的權限文件
現在啓動svn服務,就可以用svn://的方式訪問了,建議是直接用下面的方式去啓動
#svnserve -d -r /home/svn
然後測試一下:
#svn co svn://localhost/kbzc
會提示你輸入用戶名,密碼,登錄進去就可以看到有關路徑和文件信息了。
停止SVN服務器:
killall svnserve
三、Apache+SVN整合
1、新增一個httpd的用戶(不是svn用戶,他們對用戶驗證是獨立的)
#htpasswd -c /home/svn/svn_http_passwd zhangdc
根據提示,輸入密碼即可
給httpd添加用戶,必須是htpasswd命令,第一次添加需要新建文件,帶上 -c參數,以後就不需要了
2、編輯Apache的Subversion配置文件
vi /etc/httpd/conf.d/subversion.conf
添加如下信息
<Location /svn>
DAV svn
#SVNPath /home/svn/kbzc #如果你只有一個版本庫可以用它
SVNParentPath /home/svn/ #多個版本庫用它,配合SVNListParentPath
SVNListParentPath on #多個版本庫的時候可以用他,配合SVNParentPath
AuthType Basic
AuthName "Authorization Realm"
AuthUserFile /home/svn/svn_http_passwd #不可與svn的用戶公用一個文件
AuthzSVNAccessFile /home/svn/svn_authz #這個可以與之前的那個權限文件公用
Require valid-user #需要驗證用戶
</Location>
上述需要注意的是:/home/svn/svn_http_passwd不應該與svn共同使用一個用戶文件,原因是httpd與svn用戶都是單獨的,前者會對用戶文件中的密碼進行加密,後者則不會加密,我之前用的就是公用的,然後導致用svn://訪問,密碼始終都是錯誤的
3、設置資源庫文件所屬賬戶
chown -R apache.apache /home/svn
重啓Apache:
service httpd restart
現在就可以在瀏覽器嘗試訪問了:
http://svn_machine_ip/project
按提示輸入用戶名密碼。
訪問不了?頁面提示:“
This server could not verify that you are authorized to access the document requested.”
查看下apache日誌:
tail -100f /etc/httpd/logs/error_log
[Sat Oct 15 06:54:06 2016] [error] [client 192.168.22.1] (13)Permission denied: Could not open password file: /home/svn/passwd
[Sat Oct 15 06:54:06 2016] [error] [client 192.168.22.1] access to /svn failed, reason: verification of user id 'zdc' not configured
[Sat Oct 15 06:54:13 2016] [error] [client 192.168.22.1] (13)Permission denied: Could not open password file: /home/svn/passwd
[Sat Oct 15 06:54:13 2016] [error] [client 192.168.22.1] access to /svn failed, reason: verification of user id 'zdc' not configured
[Sat Oct 15 06:54:16 2016] [error] [client 192.168.22.1] (13)Permission denied: Could not open password file: /home/svn/passwd
[Sat Oct 15 06:54:16 2016] [error] [client 192.168.22.1] access to /svn failed, reason: verification of user id 'zdc' not configured
[Sat Oct 15 06:58:59 2016] [error] [client 192.168.22.1] (13)Permission denied: Could not open password file: /home/svn/passwd
[Sat Oct 15 06:58:59 2016] [error] [client 192.168.22.1] access to /svn failed, reason: verification of user id 'zdc' not configured
[Sat Oct 15 06:59:05 2016] [error] [client 192.168.22.1] (13)Permission denied: Could not open password file: /home/svn/passwd
[Sat Oct 15 06:59:05 2016] [error] [client 192.168.22.1] access to /svn failed, reason: verification of user id 'zhangdc' not configured
[Sat Oct 15 07:00:49 2016] [error] [client 192.168.22.1] (13)Permission denied: Could not open password file: /home/svn/passwd
[Sat Oct 15 07:00:49 2016] [error] [client 192.168.22.1] access to /svn failed, reason: verification of user id 'zhangdc' not configured
對於這個問題有人說關掉SElinux,個人沒試過,不過肯定不好,影響主機安全性。
執行如下命令即可:
chcon -R -h -t httpd_sys_content_t /home/svn
四、配置Https方式訪問版本倉庫
需要用到OpenSSL工具。
1.生成需要的證書、密鑰
上面是以http方式訪問的,安全性低,下面設置強制https訪問svn:
2.配置Apache的Subversion強制使用Https
生成私鑰
cd /etc/httpd/conf
openssl genrsa -out httpd.key 1024
用前面的私鑰生成證書
openssl req -new -key httpd.key -out httpd.pem -days 3650 -x509
修改Apache的SSL配置文件
# vim /etc/httpd/conf.d/ssl.conf
SSLCertificateFile /etc/httpd/conf/httpd.pem
SSLCertificateKeyFile /etc/httpd/conf/httpd.key
配置subversion強制使用https訪問
# vim /etc/httpd/conf/httpd.conf
啓用SSLRequireSSL配置(去掉前面的註釋符)。