svn+apache 安裝和使用 並與Nginx 整合

svn簡介

svn(subversion)是近年來崛起的版本管理工具,是cvs的接班人。目前,絕大多數開源軟件都使用svn作爲代碼版本管理軟件。

運行方式:

svn服務器有2種運行方式:獨立服務器和藉助apache。2種方式各有利弊,用戶自行選擇。

存儲方式:

svn存儲版本數據也有2種方式:BDB(一種事務安全型表類型)和FSFS(一種不需要數據庫的存儲系統)。因爲BDB方式在服務器中斷時,有可能鎖住數據,所以還是FSFS方式更安全一點。

SVN安裝

官方安裝文檔:http://svn.apache.org/repos/asf/subversion/trunk/INSTALL

準備工作:

我採用的是目前當前網站發佈的版本:subversion-1.8.1

首先,需要安裝預先安裝四個組件,subversion才能正常工作。

系統默認已經安裝apr-util及apr這兩個包,只不過他們的版本較低,只支持subversion1.4

#rpm-qa|grepapr

apr-util-1.2.7-7.el5_3.2

apr-util-1.2.7-7.el5_3.2

apr-1.2.7-11.el5_3.1

xorg-x11-drv-dynapro-1.1.0-2

apr-1.2.7-11.el5_3.1

subversion要求較高的版本,爲此,我們需要刪除系統自帶的apr,apr-util這兩個包!

#rpm-e--allmatchesapr-util

error:Faileddependencies:

libaprutil-1.so.0()(64bit)isneededby(installed)subversion-1.4.2-4.el5_3.1.x86_64

libaprutil-1.so.0()(64bit)isneededby(installed)httpd-2.2.3-31.el5.centos.x86_64

libaprutil-1.so.0isneededby(installed)subversion-1.4.2-4.el5_3.1.i386

#rpm-e--allmatchesapr-util--nodeps

#rpm-e--allmatchesapr--nodeps

如果沒有執行以上步驟,在安裝完成後,會發現你執行相關的命令都會報錯!

例如:

#svnserve--version

svnserve:symbollookuperror:/usr/local/svn/lib/libsvn_subr-1.so.0:undefinedsymbol:

軟件下載:

wgethttp://down1.chinaunix.net/distfiles/neon-0.25.5.tar.gz
wgethttp://219.239.26.13/download/49189183/72260493/3/gz/168/72/1374806117800_72/subversion-1.8.1.tar.gz
wgethttp://mirrors.hust.edu.cn/apache//apr/apr-1.4.8.tar.gz
wgethttp://mirrors.hust.edu.cn/apache//apr/apr-util-1.5.2.tar.gz
wgethttp://www.sqlite.org/sqlite-amalgamation-3071501.zip

安裝:

#tarxzfapr-1.4.8.tar.gz

#cdapr-1.4.8

#./configure--prefix=/usr/local/apr

#make&&makeinstall

#echo"/usr/local/apr/lib/">>/etc/ld.so.conf

#ldconfig

#tar-zxfapr-util-1.5.2.tar.gz

#cdapr-util-1.5.2

#./configure--prefix=/usr/local/apr-util--with-apr=/usr/local/apr/bin/apr-1-config

#make&&makeinstall

#echo"/usr/local/apr-util/lib">>/etc/ld.so.conf

#ldconfig

#tarxzfneon-0.25.5.tar.gz

#cdneon-0.25.5

#./configure--prefix=/usr/local/neon

#make&&makeinstall

#echo"/usr/local/neon/lib">>/etc/ld.so.conf

#ldconfig

Pcre
a)wgethttp://sourceforge.net/projects/pcre/files/pcre/8.32/pcre-8.32.tar.bz2/download
b)tarxfpcre-8.32.tar.bz2
c)cdpcre-8.32
d)./configure--prefix=/usr/local/pcre
e)make&&makeinstall

#unzipsqlite-amalgamation-3071501.zip

#mvsqlite-amalgamation-3071501subversion-1.8.1/sqlite-amalgamation

#./configure--prefix=/data/svn--with-openssl=/usr/include/openssl--without-berkeley-db--with-apr=/usr/local/apr--with-apr-util=/usr/local/apr-util

#make&&makeinstall

vim/etc/profile加入:

#SVNSETTING
SVN_HOME=/data/svn
PATH=$PATH:$SVN_HOME/bin:
exportSUSBVERSIONPATH

#APACHESETTING
APACHE_HOME=/app/apache
PATH=$PATH:$APACHE_HOME/bin:
exportAPACHEPAT

#source/etc/profile

#svnserve--version
svnserve,version1.8.1(r1503906)
compiledAug22013,13:48:33onx86_64-unknown-linux-gnu

Copyright(C)2013TheApacheSoftwareFoundation.
Thissoftwareconsistsofcontributionsmadebymanypeople;
seetheNOTICEfileformoreinformation.
Subversionisopensourcesoftware,seehttp://subversion.apache.org/

Thefollowingrepositoryback-end(FS)modulesareavailable:

*fs_fs:Moduleforworkingwithaplainfile(FSFS)repository.

CyrusSASLauthenticationisavailable.

安裝成功

apache與SVN整合

apache安裝

#cp-rfapr-1.4.8httpd-2.4.6/srclib/apr

#cp-rfapr-util-1.5.2httpd-2.4.6/srclib/apr-util

#cdhttp-2.4.6

#./configure--prefix=/app/apache--with-included-apr--with-included-apr-util--with-apr=/usr/local/apr--with-apr-util=/usr/local/apr-util/--with-pcre=/usr/local/pcre--enable-dav--enable-so-enable-maintainer-mode-enable-rewrite

#make&&makeinstall

vim/etc/init.d/httpd

#!/bin/bash
#
#httpdStartupscriptfortheApacheHTTPServer
#
#chkconfig:2359898
#description:ApacheisaWorldWideWebserver.
#ItisusedtoserveHTMLfilesandCGI.
#processname:httpd

#Sourcefunctionlibrary.
./etc/rc.d/init.d/functions

#Seehowwewerecalled.
case"$1"in
start)
echo"StartingApacheServer..."
/app/apache/bin/apachectlstart
;;
stop)
echo"StoppingApacheServer..."
/app/apache/bin/apachectlstop
;;
restart)
echo"RestartingApacheServer..."
/app/apache/bin/apachectlrestart
;;
*)
echo"Usage:$0{start|stop|restart|status}"
exit1
;;
esac
exit0

Apache開機自啓動:

chkconfig--addhttpd

chkconfig--level345httpdon

svn配置

-----------SVN+Apache-------------

#cp-rf/data/svn/libexec/mod_*/app/apache/modules/

#vim/app/apache/conf/httpd.conf

#Example:
#LoadModulefoo_modulemodules/mod_foo.so
LoadModuledav_svn_modulemodules/mod_dav_svn.so
LoadModuleauthz_svn_modulemodules/mod_authz_svn.so

<Location/svn>
DAVsvn
SVNListParentPathon
SVNParentPath/data/svn
AuthTypeBasic
AuthName"Subversionrepository"
AuthUserFile/data/svn/passwd.conf
AuthzSVNAccessFile/data/svn/authz.conf
Requirevalid-user
</Location>


#/etc/init.d/httpdrestart

創建用戶

htpasswd-c/data/svn/passwd.confuser

設置權限

vim/data/svn/authz.conf

創建項目:

svnadmincreate/data/svn/omd

svn+apache與Nginx整合(這樣做可以隱藏svn服務器的真實ip,起到一定的安全作用。如果沒有這個需求的話可以忽略)

vim/app/nginx/conf.d/svn.test.org

server{
listen80;
server_namesvn.test.org;
charsetutf-8;

location~*{
root/svn;
proxy_passhttp://192.168.101.66:80;
proxy_set_headerHostsvn.test.org;
proxy_set_headerX-Real-IP$remote_addr;
proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;
}

location~/\.ht{denyall;}
}

------------單獨使用SVN-------------

建立svn版本庫目錄

可建多個:
mkdir-p/data/svn/svndata/repos1
mkdir-p/data/svn/svndata/repos2

建立svn版本庫

svnadmincreate/data/svn/svndata/repos1
svnadmincreate/data/svn/svndata/repos2

修改svn版本庫配置文件

版本庫1:
vi/data/svn/svndata/repos1/conf/svnserve.conf

內容修改爲:
[general]
anon-access=none
auth-access=write
password-db=/data/svn/conf/pwd.conf
authz-db=/data/svn/conf/authz.conf
realm=repos1

版本庫2:
vi/data/svn/svndata/repos2/conf/svnserve.conf

內容修改爲:
[general]
anon-access=none
auth-access=write
password-db=/data/svn/conf/pwd.conf
authz-db=/data/svn/conf/authz.conf
realm=repos2

即除realm=repos2外,其他與版本庫1配置文件完全相同。如果有更多的版本庫,依此類推。

配置允許訪問的svn用戶

mkdir/data/svn/conf

vi/data/svn/conf/pwd.conf

爲了簡化配置,2個版本庫共用1個用戶配置文件。如有必要,也可以分開。

注意:對用戶配置文件的修改立即生效,不必重啓svn

文件格式如下:
[users]
<用戶1>=<密碼1>
<用戶2>=<密碼2>

其中,[users]是必須的。下面列出要訪問svn的用戶,每個用戶一行。示例:
[users]
admin=hello
user=123

配置svn用戶訪問權限

vi/data/svn/conf/authz.conf

爲了簡化配置,3個版本庫共用1個權限配置文件/data/svn/conf/pwd.conf。如有必要,也可以分開。文件中定義用戶組和版本庫目錄權限。

注意:
*權限配置文件中出現的用戶名必須已在用戶配置文件中定義
*對權限配置文件的修改立即生效,不必重啓svn

用戶組格式:
[groups]
<用戶組名>=<用戶1>,<用戶2>
其中,1個用戶組可以包含1個或多個用戶,用戶間以逗號分隔。

版本庫目錄格式:
[<版本庫>:/項目/目錄]
@<用戶組名>=<權限>
<用戶名>=<權限>

其中,方框號內部分可以有多種寫法:
/,表示根目錄及以下。根目錄是svnserve啓動時指定的,我們指定爲/opt/svndata。這樣,/就是表示對全部版本庫設置權限。
repos1:/,表示對版本庫1設置權限
repos2:/abc,,表示對版本庫2中的abc項目設置權限
repos2:/abc/aaa,,表示對版本庫2中的abc項目的aaa目錄設置權限

權限主體可以是用戶組、用戶或*,用戶組在前面加@,*表示全部用戶。權限可以是w、r、wr和空,空表示沒有任何權限。

示例:
[groups]
admin=admin
test=user
[/]
@admin=rw
*=r

[repos1:/abc/aaa]
admin=rw

[repos2:/pass]
admin=

svn配置完畢,刪除無用文件

rm/data/svn/svndata/repos1/conf/authz
rm/data/svn/svndata/repos1/conf/passwd
rm/data/svn//svndata/repos2/conf/authz
rm/data/svn/svndata/repos2/conf/passwd

建立啓動svn的用戶

useradd-s/sbin/nologinsvn

允許用戶svn訪問版本庫

chown-Rsvn:svn/data/svn

啓動svn

svnserve-d--listen-port9999-r/data/svn/svndate"

其中:
su-svn表示以用戶svn的身份啓動svn
-d表示以daemon方式(後臺運行)運行
–listen-port9999表示使用9999端口,可以換成你需要的端口。但注意,使用1024以下的端口需要root權限
-r/opt/svndata指定根目錄是/opt/svndata

檢查:
ps-ef|grepsvnserve

如果顯示如下,即爲啓動成功:
svn   6941  1 015:07?    00:00:00svnserve-d–listen-port9999-r/data/svn/svndata

建立svn啓動腳本

vim/etc/init.d/svn

#!/bin/bash
#buildthisfilein/etc/rc.d/init.d/svn
#chmod755/etc/rc.d/init.d/svn
#chkconfig:-8515
#description:svnserver

SVN_HOME=/data/svn/svndata

if[!-f"/data/svn/install/bin/svnserve"]

then

echo"svnserverstartup:cannotstart"

exit

fi

case"$1"in


start)

echo"Startingsvnserve..."

svnserve-d--listen-port9999-r$SVN_HOME

echo"Finished!"

;;

stop)

echo"Stopingsvnserve..."

killallsvnserve

echo"Finished!"

;;

restart)

$0stop

$0start

;;

*)


echo"Usage:svn{start|stop|restart}"

exit1
esac

chmod755/etc/init.d/svn

設置svn開機自啓動

chkconfigsvnon

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