服务端下载http://subversion.apache.org/download/
客户端下载http://tortoisesvn.net/downloads.htmltar zxvf svn_install.tar.gz -C /home/soft/
其中svn_install.tar.gz 包含以下软件包:
apr-1.4.6.tar.gzzxvf apr-util-1.4.1.tar.gzpcre-8.12.tar.gzhttpd-2.4.2.tar.gzsqlite-amalgamation-3071300.zipneon-0.29.6.tar.gzsubversion-1.7.5.tar.gz所需软件包 svn_install.tar.gz 百度云盘下载地址:
svn需要SQLite支持,下载sqlite-amalgamation-3071300.zip 下载链接http://www.sqlite.org/download.html
svn需要neon,用于svn 命令行支持http或者https协议访问svn 下载链接2 yum install gcc gcc-c++
3 ll
4 yum remove apr-util-devel apr apr-util-mysql apr-docs apr-devel apr-util apr-util-docs
5 yum -y install lrzsz zlib zlib-devel libxml2 libxml2-devel expat
6 rz
7 ll
8 tar zxvf svn_install.tar.gz -C /home/soft
9 mkdir -pv /home/soft
10 ll
11 tar zxvf svn_install.tar.gz -C /home/soft
12 cd /home/soft/
13 ll
14 ll
15 mv svn_install/* .
16 ll
17 tar zxvf apr-1.4.6.tar.gz
18 cd apr-1.4.6
19 ll
20 sed -i 's/^.*$RM "$cfgfile"$/# $RM "$cfgfile"/' configure
21 ./buildconf
22 yum install autoconf
23 yum install libtool
24 ./configure --prefix=/usr/local/apr
25 make && make install
26 cd ..
27 tar zxvf apr-util-1.4.1.tar.gz
28 cd apr-util-1.4.1
29 ll
30 ./configure --prefix=/usr/local/apr --with-apr=/usr/local/apr
31 make && make install
32 cd ..
33 ll
34 tar zxvf pcre-8.12.tar.gz
35 cd pcre-8.12
36 ll
37 ./configure
38 make && make install
39 history
40 cd ..
41 ll
42 tar zxvf httpd-2.4.2.tar.gz
43 cd httpd-2.4.2
44 ll
45 ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr/bin/apu-1-config --enable-so --enable-dav --enable-dav-fs --enable-dav-lock --enable-maintainer-mode --enable-rewrite
46 make && make install
47 history
48 cd ,,
49 cd ..
50 tar zxvf neon-0.29.6.tar.gz
51 cd neon-0.29.6
52 ./configure
53 make && make install
54 history
55 cd ..
56 unzip sqlite-amalgamation-3071300.zip
57 tar zxvf subversion-1.7.5.tar.gz
58 mkdir -p /home/soft/subversion-1.7.5/sqlite-amalgamation
59 cp sqlite-amalgamation-3071300/sqlite3.c /home/soft/subversion-1.7.5/sqlite-amalgamation/
60 cd subversion-1.7.5
61 ./configure --prefix=/usr/local/subversion --with-apxs=/usr/local/apache/bin/apxs --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr/bin/apu-1-config --with-ssl --with-zlib --enable-maintainer-mode --with-neon=/usr/local
make && make install
编译安装好后:
检查
/usr/local/subversion/bin/svnserve –version
创建svn目录
mkdir -p /www/svn创建svn仓库/usr/local/subversion/bin/svnadmin create /www/svn/yeadongchmod 755 /www/svn -Rchown apache.apache -R /www/svn修改apache配置vi /usr/local/apache/conf/httpd.conf 添加如下内容:LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so注意:最好在LoadModule部分的末尾添加以上两行否则会load失败
再最末尾添加:<Location /svn>DAV svnSVNListParentPath onSVNParentPath /www/svnAuthType BasicAuthName “welcome to svn”AuthUserFile /www/svn/passwd.confAuthzSVNAccessFile /www/svn/authzRequire valid-user</Location>将
User daemonGroup daemon改为User apacheGroup apache测试apache配置是否有误
/usr/local/apache/bin/apachectl -t启动apache/usr/local/apache/bin/apachectl start将apache加入开机启动项
echo “/usr/local/apache/bin/apachectl start” > /etc/rc.local
创建apache认证密码文件/usr/local/apache/bin/htpasswd -cm /www/svn/passwd.conf admin #第一次运行会自动创建passwd.conf文件,连续输入两次密码/usr/local/apache/bin/htpasswd -m /www/svn/passwd.conf root #第二次运行只带参数-m即可,如果再带上-c参数会覆盖之前的配置配置svn权限
vi /www/svn/authz 内容如下[groups]supergroup = admin,rootguest = test[/]
@supergroup = rwyeadong = r* =注意:apache有读取/www/svn/passwd.conf和 /www/svn/authz文件的权限,并且/www/svn目录及/www对其他用户有读权限
如将/www或者/www/svn目录设置为700,主属为root,那么apache及其他用户就没有进入/www/或者/www/svn目录的权限就更不可能读取该目录下的文件重启http服务
访问svn 路径http://ip/svn/yeadong#启动svn服务端,由于我们将apache和svn整合所以不需要启动svn服务
/usr/local/subversion/bin/svnserve -d -r /www/svndata/jfzy增加提交时备注说明限定至少输入五个字符才能提交cd /www/svn/yeadong/hookscp pre-commit.tmpl pre-commitvi pre-commit
注释以下两行:#$SVNLOOK log -t “$TXN” “$REPOS” | \# grep “[a-zA-Z0-9]” > /dev/null || exit 1根据实际情况修改以下一行:SVNLOOK=/usr/local/subversion/bin/svnlook添加以下几行:LOGMSG=`$SVNLOOK log -t “$TXN” “$REPOS” | grep “[a-zA-Z0-9]” | wc -c`#要求注释不能少于5个字符,您可自定义if [ "$LOGMSG" -lt 5 ];thenecho -e “Empty log is not allowed,please input more than 5 chars comment.” 1>&2exit 1
fi注释掉commit-access-control.pl “$REPOS” “$TXN” commit-access-control.cfg || exit 1
注意pre-commit主属要为apache用户chown apache.apache /www/svn/jfzy/hooks/pre-commit进阶功能,svn提交完成之后触发post-commit钩子将代码rsync到线上服务器
进入svn仓库目录下的hooks目录例如/www/svn/yeadong/hooks/创建post-commit脚本vi post-commit内容如下:#!/bin/sh
#说明;必须手动checkout一份工作目录,并且注意svn服务的运行用户对该目录有所有权限
#一定要对svn update是否成功做判断在执行rsync,否则有可能代码错误导致更新出错
#修改svn工作目录父目录下的.subversion/servers文件,设置store-passwords = yes自动保存密码。
#或者执行svn的时候带–no-auth-cache,不缓存认证信息
export LANG=en_US.UTF-8
SVN=”/usr/local/subversion/bin/svn”
DST=”192.168.66.223″
RSYNC_PROJECT=”main”
SVN_SERVER=”http://192.168.1.178:8080/svn/yeadong”
SVN_USER=”admin”
SVN_PWD=”redhat”
SOURCE=”/code/yeadong_test”
LOG_DIR=”/tmp/svn_log”
[ ! -d LOG_DIR ] && mkdir -p ${LOG_DIR}
LOG_FILE=”${LOG_DIR}/svn_hooks_post-commit.log”
NEWTIME=`date +%F_%T`
echo “########执行时间${NEWTIME}##########” >>${LOG_FILE}
[ ! -d ${SOURCE} ] && echo -e “请手动执行以下命令:\n$SVN checkout ${SVN_SERVER} ${SOURCE} –username ${SVN_USER} –password ${SVN_PWD}\sed -i ‘/^#.*store-passwords.*$/s/^.*$/store-passwords = yes/’ .subversion/servers”update_svn ()
{ cd ${SOURCE}$SVN update –username ${SVN_USER} –password ${SVN_PWD} –no-auth-cacheif [ $? -ne 0 ];thenecho “time:${NEWTIME} svn update failed” >>${LOG_FILE}exit 1elif [ $? -eq 0 ];thenecho “time:${NEWTIME} svn update complete >>${LOG_FILE}”fi}rsync_code (){ /usr/bin/rsync -avz ${SOURCE}/main/* ${DST}::${RSYNC_PROJECT} >>${LOG_FILE} 2>&1/usr/bin/rsync -avz ${SOURCE}/9wee_s0/* ${DST}::${RSYNC_PROJECT} >>${LOG_FILE} 2>&1/usr/bin/rsync -avz ${SOURCE}/static/* ${DST}::${RSYNC_PROJECT}/webserver/webapps/root/ >>${LOG_FILE} 2>&1}update_svnrsync_code[ $? -eq 0 ] && echo “执行成功” >>${LOG_FILE} || echo “执行失败” >>${LOG_FILE}说明:在任何svn客户端提交代码到svn服务器http://192.168.66.93:8080/svn/yeadong都会触发该脚本自动执行,如果脚本执行失败客户端会有相应提示
注意svn服务端运行用户对svn 工作目录需要具有所有权限,例如/code/yeadong_test 为svn客户端checkout的目录,而服务端是以apache用户运行的所以chown -R /code/yeadong_testsvn常用命令
命令行checkout 版本库
mkdir /codecd /code迁出版本:
svn checkout http://192.168.50.144:8080/svn/yeadong –username yeadong –password 123456导出(导出一个干净的不带.svn文件夹的目录树)
svn export http://192.168.50.144:8080/svn/yeadong –username yeadong –password 123456更新版本:
svn update http://192.168.50.144:8080/svn/yeadong –username yeadong –password 123456提交版本
svn commint往版本库中添加新的文件
cd /code/yeadong/mainsvn add anaconda-ks.cfgsvn commit -m “update” anaconda-ks.cfg从版本库删除文件
svn delete -m “delete file” http://192.168.50.144:8080/svn/yeadong/main/anaconda-ks.cfgsvn commit/root/.subversion/auth目录下存放认证账号密码如果是简单明文认证一般存放在/root/.subversion/auth/svn.simple目录下设置不保存密码切不提示
修改/root/.subversion/servers 在最末尾位置添加一行store-plaintext-passwords = no或者执行执行在–username xxx –password xxx后面加上参数: –no-auth-cache
#启动svn服务端,由于我们将apache和svn整合所以不需要启动svn服务
svnserve -d -r /www/svndata/yeadong原文请访问: