服務(wù)器維護(hù)Linux下Apache完美集成SVN(Yum安裝版)
2020-05-22 20:30 作者:admin
如何做好
服務(wù)器維護(hù)?北京艾銻無限科技與你談?wù)処T人員必須知道的
服務(wù)器維護(hù)信息
服務(wù)器維護(hù)小知識svn(subversion)是目前最流行的開源版本控制工具。使用apache集成svn比svn服務(wù)獨立運行好處多多,最大的優(yōu)點是使svn使用http80端口檢出,防火墻可以少開放一個端口,減少服務(wù)器安全風(fēng)險和降低維護(hù)成本。下面在CentOS6.0系統(tǒng)下通過yum安裝的方式,介紹在linux下apache完美集成svn。
服務(wù)器維護(hù)小知識一、規(guī)劃目錄: 網(wǎng)站地址
網(wǎng)站根目錄 /storage/web/aiezu
SVN地址
SVN數(shù)據(jù)倉庫目錄 /storage/svn/aiezu
服務(wù)器維護(hù)小知識二、安裝apache:
安裝apache包:
yum -y install httpd #必須
yum -y install mysql mysql-server php php-mbstring php-gd #可選安裝
創(chuàng)建站點根目錄:
mkdir -p /storage/web/aiezu
建立基于域名的虛擬主機,vim /etc/httpd/conf.d/www.aiezu.com.conf添加以下內(nèi)容:
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服務(wù):
service mysqld start
service httpd start
服務(wù)器維護(hù)小知識三、安裝和配置apache SVN模塊:
安裝apache服務(wù)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數(shù)據(jù)倉庫:
mkdir -p /storage/svn/aiezu
svnadmin create /storage/svn/aiezu
建立svn帳號并設(shè)置密碼:
htpasswd -c /storage/svn/aiezu/conf/passwd svnuser
分配svn帳號權(quán)限:
[aiezu:/]
svnuser = rw #設(shè)置aiezu數(shù)據(jù)倉庫svnuser用戶有讀寫權(quán)限
配置svn數(shù)據(jù)倉庫文件系統(tǒng)權(quán)限:
chown -R apache.apache /storage/svn/aiezu
chcon -R -t httpd_sys_content_t /storage/svn/aiezu #selinux權(quán)限
配置svn數(shù)據(jù)倉庫checkout地址:
vim /etc/httpd/conf.d/subversion.conf,添加如下內(nèi)容:
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鉤子:
當(dāng)我們希望在像svn數(shù)據(jù)倉庫提交新版本時,自動將更新同步到我們的網(wǎng)站,這時我們可以使用svn鉤子,svn鉤子必須放在svn數(shù)據(jù)倉庫的hooks目錄下,這里我們要添加是svn commit(svn提交)鉤子post-commit:
vim /storage/svn/aiezu/hooks/post-commit,添加如下內(nèi)容:
#!/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
授予可執(zhí)行權(quán)限:
chmod a+x /storage/svn/aiezu/hooks/post-commit
檢出版本庫:
svn checkout /storage/web/aiezu/
服務(wù)器維護(hù)小知識五、常見錯誤及其解答:
1、svn checkout(svn檢出)時錯誤一:
The URI does not contain the name of a repository. [403, #190001]
解答:這是由于subversion.conf文件中SVNParentPath路徑設(shè)置不正確引起的,SVNParentPath路徑必須為svnadmin create生成數(shù)據(jù)倉庫路勁的父目錄,如上面建立數(shù)據(jù)倉庫的命令為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數(shù)據(jù)倉庫的SVN URL地址不正確,當(dāng)subversion.conf中設(shè)置SVNListParentPath on時,SVN URL地址為SVNParentPath下的具體數(shù)據(jù)倉庫,而不是SVNParentPath指定的目錄。
3、svn checkout時錯誤三:
Unable to connect to a repository at URL '
Could not open the requested SVN filesystem
解答:svn數(shù)據(jù)倉庫的SVN URL地址不正確,在SVNParentPath下找不到SVN URL指定的數(shù)據(jù)倉庫。
4、svn提交(svn commit)時出現(xiàn)如下錯誤:
post-commit hook failed (exit code 1) with output:
svn: Can't open file '/storage/web/aiezu/.svn/lock': Permission denied
解答:這是svn提交調(diào)用的post-commit鉤子沒有權(quán)限寫/storage/web/aiezu/.svn目錄引起的。apache集成的svn是使用apache用戶調(diào)用post-commit鉤子的,所以必須保證apache用戶對.svn有寫權(quán)限, 執(zhí)行chown -R apache.apache /storage/web/aiezu就可以了。
以上內(nèi)容為艾銻無限為大家提供的
服務(wù)器維護(hù)小知識,更多內(nèi)容請關(guān)注:
www.bjitwx.com。