服務器維護Linux下Apache完美集成SVN(Yum安裝版)
2020-05-22 20:30 作者:admin
如何做好
服務器維護?北京艾銻無限科技與你談談IT人員必須知道的
服務器維護信息
服務器維護小知識svn(subversion)是目前最流行的開源版本控制工具。使用apache集成svn比svn服務獨立運行好處多多,最大的優點是使svn使用http80端口檢出,防火墻可以少開放一個端口,減少服務器安全風險和降低維護成本。下面在CentOS6.0系統下通過yum安裝的方式,介紹在linux下apache完美集成svn。
服務器維護小知識一、規劃目錄: 網站地址
網站根目錄 /storage/web/aiezu
SVN地址
SVN數據倉庫目錄 /storage/svn/aiezu
服務器維護小知識二、安裝apache:
安裝apache包:
yum -y install httpd #必須
yum -y install mysql mysql-server php php-mbstring php-gd #可選安裝
創建站點根目錄:
mkdir -p /storage/web/aiezu
建立基于域名的虛擬主機,vim /etc/httpd/conf.d/www.aiezu.com.conf添加以下內容:
NameVirtualHost *:80
<Directory "/storage/web/aiezu">
Options -Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
ServerAdmin admin@aiezu.com
DocumentRoot /storage/web/aiezu
ServerName
ErrorLog logs/www.aiezu.com-error_log
CustomLog logs/www.aiezu.com-access_log common
</VirtualHost>
啟動apache和mysql服務:
service mysqld start
service httpd start
服務器維護小知識三、安裝和配置apache SVN模塊:
安裝apache服務SVN模塊mod_dav_svn:
yum -y install mod_dav_svn
#會自動安裝mod_dav_svn及其依賴包:mod_dav_svn-1.6.11-9,neon-0.29.3-2,pakchois-0.4-3.2,subversion-1.6.11-9
建立svn數據倉庫:
mkdir -p /storage/svn/aiezu
svnadmin create /storage/svn/aiezu
建立svn帳號并設置密碼:
htpasswd -c /storage/svn/aiezu/conf/passwd svnuser
分配svn帳號權限:
[aiezu:/]
svnuser = rw #設置aiezu數據倉庫svnuser用戶有讀寫權限
配置svn數據倉庫文件系統權限:
chown -R apache.apache /storage/svn/aiezu
chcon -R -t httpd_sys_content_t /storage/svn/aiezu #selinux權限
配置svn數據倉庫checkout地址:
vim /etc/httpd/conf.d/subversion.conf,添加如下內容:
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so
<Location /svn>
DAV svn
SVNListParentPath on
SVNParentPath /storage/svn
AuthType Basic
AuthName "Authorization"
AuthUserFile /storage/svn/aiezu/conf/passwd
AuthzSVNAccessFile /storage/svn/aiezu/conf/authz
Require valid-user
</Location>
重新加載apache配置:
service httpd reload
四、配置svn post-commit鉤子:
當我們希望在像svn數據倉庫提交新版本時,自動將更新同步到我們的網站,這時我們可以使用svn鉤子,svn鉤子必須放在svn數據倉庫的hooks目錄下,這里我們要添加是svn commit(svn提交)鉤子post-commit:
vim /storage/svn/aiezu/hooks/post-commit,添加如下內容:
#!/bin/bash
export LANG="zh_CN.UTF-8"
export LANG="zh_CN.UTF-8"
export LC_CTYPE="zh_CN.UTF-8"
svn update /storage/web/aiezu/ --username=svnuser --password=svnpass --non-interactive
授予可執行權限:
chmod a+x /storage/svn/aiezu/hooks/post-commit
檢出版本庫:
svn checkout /storage/web/aiezu/
服務器維護小知識五、常見錯誤及其解答:
1、svn checkout(svn檢出)時錯誤一:
The URI does not contain the name of a repository. [403, #190001]
解答:這是由于subversion.conf文件中SVNParentPath路徑設置不正確引起的,SVNParentPath路徑必須為svnadmin create生成數據倉庫路勁的父目錄,如上面建立數據倉庫的命令為svnadmin create /storage/svn/aiezu,則SVNParentPath為/storage/svn。
2、svn checkout時錯誤二:
Unable to connect to a repository at URL 'http://www.aiezu.com/svn'
Access to 'http://www.aiezu.com/svn' forbidden
解答:svn數據倉庫的SVN URL地址不正確,當subversion.conf中設置SVNListParentPath on時,SVN URL地址為SVNParentPath下的具體數據倉庫,而不是SVNParentPath指定的目錄。
3、svn checkout時錯誤三:
Unable to connect to a repository at URL '
Could not open the requested SVN filesystem
解答:svn數據倉庫的SVN URL地址不正確,在SVNParentPath下找不到SVN URL指定的數據倉庫。
4、svn提交(svn commit)時出現如下錯誤:
post-commit hook failed (exit code 1) with output:
svn: Can't open file '/storage/web/aiezu/.svn/lock': Permission denied
解答:這是svn提交調用的post-commit鉤子沒有權限寫/storage/web/aiezu/.svn目錄引起的。apache集成的svn是使用apache用戶調用post-commit鉤子的,所以必須保證apache用戶對.svn有寫權限, 執行chown -R apache.apache /storage/web/aiezu就可以了。
以上內容為艾銻無限為大家提供的
服務器維護小知識,更多內容請關注:
www.bjitwx.com。