颇为阿娇978 发表于 2018-11-23 11:50:20

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
  
DAVsvn
SVNListParentPathon
SVNParentPath/data/svn
AuthTypeBasic
AuthName"Subversionrepository"
AuthUserFile/data/svn/passwd.conf
AuthzSVNAccessFile/data/svn/authz.conf
Requirevalid-user

  
#/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
  内容修改为:

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
  内容修改为:

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。
  文件格式如下:

=
=
  其中,是必须的。下面列出要访问svn的用户,每个用户一行。示例:

admin=hello
user=123
  配置svn用户访问权限
  vi/data/svn/conf/authz.conf
  为了简化配置,3个版本库共用1个权限配置文件/data/svn/conf/pwd.conf。如有必要,也可以分开。文件中定义用户组和版本库目录权限。
  注意:
*权限配置文件中出现的用户名必须已在用户配置文件中定义。
*对权限配置文件的修改立即生效,不必重启svn。
  用户组格式:

=,
其中,1个用户组可以包含1个或多个用户,用户间以逗号分隔。
  版本库目录格式:
[:/项目/目录]
@=
=
  其中,方框号内部分可以有多种写法:
/,表示根目录及以下。根目录是svnserve启动时指定的,我们指定为/opt/svndata。这样,/就是表示对全部版本库设置权限。
repos1:/,表示对版本库1设置权限
repos2:/abc,,表示对版本库2中的abc项目设置权限
repos2:/abc/aaa,,表示对版本库2中的abc项目的aaa目录设置权限
  权限主体可以是用户组、用户或*,用户组在前面加@,*表示全部用户。权限可以是w、r、wr和空,空表示没有任何权限。
  示例:

admin=admin
test=user
[/]
@admin=rw
*=r
  
admin=rw
  
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



页: [1]
查看完整版本: svn+apache 安装和使用 并与Nginx 整合