软件列表(下载地址)
httpd-2.2.16.tar.gz http://labs.renren.com/apache-mirror//httpd/httpd-2.2.16.tar.gz
apr-1.4.2.tar.gz http://labs.renren.com/apache-mirror//apr/apr-1.4.2.tar.gz
apr-util-1.3.9.tar.gz http://labs.renren.com/apache-mirror//apr/apr-util-1.3.9.tar.gz
neon-0.29.3.tar.gz http://www.webdav.org/neon/neon-0.29.3.tar.gz
sqlite-amalgamation-3.7.2.tar.gz http://www.sqlite.org/sqlite-amalgamation-3.7.2.tar.gz
subversion-1.6.12.tar.gz http://subversion.tigris.org/downloads/subversion-1.6.12.tar.gz
Svn web访问创建,删除,密码修改文件 svnpwd.php
httpd-2.2.16.tar.gz http://labs.renren.com/apache-mirror//httpd/httpd-2.2.16.tar.gz
apr-1.4.2.tar.gz http://labs.renren.com/apache-mirror//apr/apr-1.4.2.tar.gz
apr-util-1.3.9.tar.gz http://labs.renren.com/apache-mirror//apr/apr-util-1.3.9.tar.gz
neon-0.29.3.tar.gz http://www.webdav.org/neon/neon-0.29.3.tar.gz
sqlite-amalgamation-3.7.2.tar.gz http://www.sqlite.org/sqlite-amalgamation-3.7.2.tar.gz
subversion-1.6.12.tar.gz http://subversion.tigris.org/downloads/subversion-1.6.12.tar.gz
Svn web访问创建,删除,密码修改文件 svnpwd.php
软件安装
注:软件全下载到/opt/soft 目录下
arp 安装
# tar zxvf apr-1.4.2.tar.gz
# cd apr-1.4.2
# ./configure
# make
# make install
# cd apr-1.4.2
# ./configure
# make
# make install
apr-util 安装
# tar zxvf apr-util-1.3.9.tar
# cd apr-util-1.3.9
# ./configure --with-apr=/usr/local/apr
# make
# make install
# cd apr-util-1.3.9
# ./configure --with-apr=/usr/local/apr
# make
# make install
neon-0.29 安装
# tar zxvf neon-0.29.3.tar.gz
# cd neon-0.29.3
# ./configure
# make
# make install
# cd neon-0.29.3
# ./configure
# make
# make install
sqlite-amalgamation 安装
# tar zxvf sqlite-amalgamation-3.7.2.tar.gz
# cd sqlite-amalgamation-3.7.2
# ./configure
# make
# make install
# cd sqlite-amalgamation-3.7.2
# ./configure
# make
# make install
Apache 安装
# tar zxvf httpd-2.2.16.tar.gz
# cd httpd-2.2.16
# ./configure --prefix=/opt/apache \
--enable-dav \
--enable-rewrite \
--enable-so \
--enable-maintainer-mode \
--enable-mods-shared='all' \
--with-apr=/usr/local/apr/bin/apr-1-config \
--with-apr-util=/usr/local/apr/bin/apu-1-config
# make
# make install
# cd httpd-2.2.16
# ./configure --prefix=/opt/apache \
--enable-dav \
--enable-rewrite \
--enable-so \
--enable-maintainer-mode \
--enable-mods-shared='all' \
--with-apr=/usr/local/apr/bin/apr-1-config \
--with-apr-util=/usr/local/apr/bin/apu-1-config
# make
# make install
subversion 安装
# tar zxvf subversion-1.6.12.tar.gz
# cd subversion-1.6.12
# mkdir sqlite-amalgamation
# cp /opt/soft/sqlite-amalgamation-3.7.2/sqlite3.c /opt/soft/subversion-1.6.12/sqlite-amalgamation
# ./configure --prefix=/opt/subversion \
--with-apxs=/opt/apache/bin/apxs \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr \
--with-zlib=/usr/include \
--enable-maintainer-mode
# make
# make install
# cd subversion-1.6.12
# mkdir sqlite-amalgamation
# cp /opt/soft/sqlite-amalgamation-3.7.2/sqlite3.c /opt/soft/subversion-1.6.12/sqlite-amalgamation
# ./configure --prefix=/opt/subversion \
--with-apxs=/opt/apache/bin/apxs \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr \
--with-zlib=/usr/include \
--enable-maintainer-mode
# make
# make install
创建svn仓库
# groupadd svn -g 801
# useradd -u 801 -g svn svnroot
# mkdir /opt/svn
# /opt/subversion/bin/svnadmin create --fs-type fsfs /opt/svn/svndocs
# chown -R svnroot.svn /opt/svn
配置svn与apache接合
# vi /opt/apache/conf/httpd.conf
将配置文件里的user,group修改为svnroot和svn,如下:
User svnroot
Group svn
找到下面2行
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so
在末尾添加以下内容
<Location /svn>
DAV svn
SVNParentPath /opt/svn/
AuthzSVNAccessFile /opt/svn/svndocs/conf/authz
AuthType Basic
AuthName "SVN Server"
AuthUserFile /opt/svn/svn-user
Require valid-user
</Location>
注: SVNPath 为svn父目录
AuthzSVNAccessFile 为用户权限配置文件
AuthUserFile 为svn用户配置文件
# groupadd svn -g 801
# useradd -u 801 -g svn svnroot
# mkdir /opt/svn
# /opt/subversion/bin/svnadmin create --fs-type fsfs /opt/svn/svndocs
# chown -R svnroot.svn /opt/svn
配置svn与apache接合
# vi /opt/apache/conf/httpd.conf
将配置文件里的user,group修改为svnroot和svn,如下:
User svnroot
Group svn
找到下面2行
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so
在末尾添加以下内容
<Location /svn>
DAV svn
SVNParentPath /opt/svn/
AuthzSVNAccessFile /opt/svn/svndocs/conf/authz
AuthType Basic
AuthName "SVN Server"
AuthUserFile /opt/svn/svn-user
Require valid-user
</Location>
注: SVNPath 为svn父目录
AuthzSVNAccessFile 为用户权限配置文件
AuthUserFile 为svn用户配置文件
创建svn用户
# /opt/apache/bin/htpasswd -c -m /opt/svn/svn-user user1
注:第一次创建用户时,要带参数-c ,以后新增用户不必用-c ,否则将会清除以前用户
-m 表示以md5码加密
如新增用户user2
# /opt/apache/bin/htpasswd -m /opt/svn/svn-user user2
修改user2用户密码
# /opt/apache/bin/htpasswd -m /opt/svn/svn-user user1
New password:
Re-type new password:
Adding password for user user1
-m 表示以md5码加密
如新增用户user2
# /opt/apache/bin/htpasswd -m /opt/svn/svn-user user2
修改user2用户密码
# /opt/apache/bin/htpasswd -m /opt/svn/svn-user user1
New password:
Re-type new password:
Adding password for user user1
用户权限配置
修改svnserve.conf配置文件
# vi /opt/svn/svndocs/conf/svnserve.conf
将# authz-db = authz 前面#号删除,authz-db = authz 前面不能有空格。
将# anon-access = read 修改为anon-access = none 前面不能有空格,禁止匿名用户访问文件
也可使用password认证
将#password-db = passwd前面#号删除,password-db = passwd 前面不能有空格
修改/opt/svn/svndocs/conf/authz配置文件
# vi /opt/svn/svndocs/conf/authz
# vi /opt/svn/svndocs/conf/authz
[groups]
# harry_and_sally = harry,sally
dev = user1,user2
# [/foo/bar]
# harry = rw
# * =
# [repository:/baz/fuz]
# @harry_and_sally = rw
# * = r
[/]
@dev = rw
[/p_w_picpath]
user1 = r
# harry_and_sally = harry,sally
dev = user1,user2
# [/foo/bar]
# harry = rw
# * =
# [repository:/baz/fuz]
# @harry_and_sally = rw
# * = r
[/]
@dev = rw
[/p_w_picpath]
user1 = r
注: [groups]创建组,格式组名 = 用户名 [可以多个用户,以(,分号)]分隔
[\] 表示根目录,@dev = rw 表示dev组用户对根目录有读写权限 (r表示读,w表示写)
[/p_w_picpath] user1 =r 表示user1 对p_w_picpath目录只有读取权限
[\] 表示根目录,@dev = rw 表示dev组用户对根目录有读写权限 (r表示读,w表示写)
[/p_w_picpath] user1 =r 表示user1 对p_w_picpath目录只有读取权限
测试svn
访问
http://ip/svn/svndocs,输入创建的svn用户名、密码,会出现 Rivision 0:/,说明配置成功。
使用svn协议访问
要使用svn://url来访问,先要启动svnserve服务
# /opt/subversion/bin/svnserve -d -r /opt/svn
注: -r 表示svn父目录
# /opt/subversion/bin/svnserve -d -r /opt/svn
注: -r 表示svn父目录
就可使用svn://ip/svndocs来访问svn服务了。
SVN 同步web文件配置
svn库目录 /opt/svn/svndocs
web目录 /opt/web/dev_www
web目录 /opt/web/dev_www
将svndoc库checkout到/opt/web/dev_www目录
# /opt/subversion/bin/svn checkout file:///opt/svn/svndocs /opt/web/dev_www
# /opt/subversion/bin/svn checkout file:///opt/svn/svndocs /opt/web/dev_www
配置post-commit 钩子触发后执行的脚本
# vi /opt/svn/svndocs/hooks/post-commit
#!/bin/bash
REPOS="$1"
REV="$2"
/root/sh/dev_svn.sh
# vi /opt/svn/svndocs/hooks/post-commit
#!/bin/bash
REPOS="$1"
REV="$2"
/root/sh/dev_svn.sh
post-commit 权限设置
# chmod +x /opt/svn/svndocs/hooks/post-commit
# chmod +x /opt/svn/svndocs/hooks/post-commit
/root/sh/dev_svn.sh脚本内容如下:
#!/bin/sh
export LANG="en_US.UTF-8"
/opt/subversion/bin/svn update /opt/web/dev_www
export LANG="en_US.UTF-8"
chown www:www -R /opt/web/dev_www &
export LANG="en_US.UTF-8"
/opt/subversion/bin/svn update /opt/web/dev_www
export LANG="en_US.UTF-8"
chown www:www -R /opt/web/dev_www &
svn备份
每天凌晨0点自动备份svn版本库.并自动删除7天前的数据
#!/bin/sh
#svnbak auto at 0:00 daily run......
#svnbak auto deleted 7 days ago
svn=/usr/bin/svnadmin
svndir=/opt/svn
svnlook=/opt/subversion/bin/svnlook
svnbakdir=/opt/svn-bak
date=`date +%Y-%m-%d -d "-1 days"`
olddate=`date +%Y-%m-%d -d "-7 days"`
if [ ! -d $svnbakdir ];then
mkdir -p $svnbakdir
fi
svnlist=`ls -l /opt/svn | grep d | awk '{print $NF}'`
for svnwork in $svnlist
do
mkdir -p $svnbakdir/$date
$svn hotcopy $svndir/$svnwork $svnbakdir/$date/$svnwork-$date --clean-logs
#取到当前svn版本库的最新版本号,方便增量备份
$svnlook youngest $svndir/$svnwork > $svndir/$svnwork/$svnwork-in.txt
done
if [ -d $svnbakdir/$olddate ];then
rm -rf $svnbakdir/$olddate
fi
#svnbak auto at 0:00 daily run......
#svnbak auto deleted 7 days ago
svn=/usr/bin/svnadmin
svndir=/opt/svn
svnlook=/opt/subversion/bin/svnlook
svnbakdir=/opt/svn-bak
date=`date +%Y-%m-%d -d "-1 days"`
olddate=`date +%Y-%m-%d -d "-7 days"`
if [ ! -d $svnbakdir ];then
mkdir -p $svnbakdir
fi
svnlist=`ls -l /opt/svn | grep d | awk '{print $NF}'`
for svnwork in $svnlist
do
mkdir -p $svnbakdir/$date
$svn hotcopy $svndir/$svnwork $svnbakdir/$date/$svnwork-$date --clean-logs
#取到当前svn版本库的最新版本号,方便增量备份
$svnlook youngest $svndir/$svnwork > $svndir/$svnwork/$svnwork-in.txt
done
if [ -d $svnbakdir/$olddate ];then
rm -rf $svnbakdir/$olddate
fi
svn增量备份
#!/bin/sh
#svn increment bak
#at 0:00 daily run......
svndir=/opt/svn
svninbak=/opt/svninbak
date=`date +%Y-%m-%d -d "-1 days"`
svnadmin=/usr/bin/svnadmin
svnlook=/opt/subversion/bin/svnlook
svnlist=`ls -l /opt/svn | grep d | awk '{print $NF}'`
if [ ! -d $svninbak/$date ];then
mkdir -p $svninbak/$date
fi
for svninc in $svnlist
do
inc=`cat $svndir/$svninc/$svninc-in.txt`
((inc++))
$svnadmin dump -r $inc:head --incremental $svndir/$svninc > $svninbak/$date/$svninc-$date.dump
$svnlook youngest $svndir/$svninc > $svndir/$svninc/$svninc-in.txt
$svnlook youngest $svndir/$svninc > $svndir/$svninc/$svninc-in.txt
done
svnadmin dump备份
# svnadmin dump /opt/svn/svndocs > /opt/svn-bak/svndocs
svn 恢复
# svnadmin create /opt/svn/svndocs
# svnadmin load /opt/svn/svndocs < /opt/svn-bak/svndocs
一个技巧:
如果你有一个较大的Subsersion版本库而你又想用最少的空间来将它备份下来,用这个命令(请将/repo替换成你的版本库路径)吧:
# svnadmin dump /opt/svn/svndocs > /opt/svn-bak/svndocs
svn 恢复
# svnadmin create /opt/svn/svndocs
# svnadmin load /opt/svn/svndocs < /opt/svn-bak/svndocs
一个技巧:
如果你有一个较大的Subsersion版本库而你又想用最少的空间来将它备份下来,用这个命令(请将/repo替换成你的版本库路径)吧:
svnadmin dump –deltas /repo |bzip2 |tee dump.bz2 | md5sum >dump.md5
分步解释:
最重要的一步是 -deltas,将消耗更多的CPU资源,但拥有更有效的差异存储办法。
bzip2压缩方案比gzip慢,但换来的更好的压缩率。
分步解释:
最重要的一步是 -deltas,将消耗更多的CPU资源,但拥有更有效的差异存储办法。
bzip2压缩方案比gzip慢,但换来的更好的压缩率。
更有趣的是,tee方法将压缩的数据流转向到文件dump.bz2,同时将其输出到标准输出,后者有转向给了MD5摘要计算工具。要恢复这个版本库,检查校验值(md5sum创建的),创建一个空的版本库,恢复备份:
md5sum -c dump.md5 <dump.bz2
svnadmin create newrepo
bzcat dump.bz2 | svnadmin load newrepo
请享受压缩后用MD5校验的备份吧,最后别忘记将dump.md5和dump.bz2存储到真正安全的地方!
svnadmin create newrepo
bzcat dump.bz2 | svnadmin load newrepo
请享受压缩后用MD5校验的备份吧,最后别忘记将dump.md5和dump.bz2存储到真正安全的地方!
参考文档:
http://bbs.linuxtone.org/viewthread.php?tid=6246&highlight=svn
http://www.ibm.com/developerworks/cn/java/j-lo-apache-subversion/
http://www.svn8.com/svnpz/20090428/5032.html
svn常用命令:
http://bbs.linuxtone.org/thread-1342-1-1.html
转载于:https://blog.51cto.com/cqfish/1022359