1. 安装apache+svn
sudo apt-get install apache2
sudo apt-get install subversion
sudo apt-get install libapache2-svn
sudo apt-get install apache2-utils
2. Apache配置
2.1 配置加密
/etc/apache2/mods-enabled/authz_user.load添加
LoadModule authn_file_module /usr/lib/apache2/modules/mod_authn_file.so
LoadModule auth_basic_module /usr/lib/apache2/modules/mod_auth_basic.so
LoadModule auth_digest_module /usr/lib/apache2/modules/mod_auth_digest.so
2.2 配置svn与apache关联
/etc/apache2/mods-enabled/dav.load
LoadModule dav_svn_module /usr/lib/apache2/modules/mod_dav_svn.so
LoadModule authz_svn_module /usr/lib/apache2/modules/mod_authz_svn.so
2.3 设置端口准入,一般默认端口是80
sudo ufw allow 80
3. SVN创建版本库与账号密码管理
3.1 创建版本库
svnadmin create /share/data/svncode/test
3.2 创建用户名和密码,这里用htdigest
htdigest -c /share/data/scm/htdigest/passwd Tina Jacky
3.3 创建权限文件 test.txt
touch /share/data/scm/svnadmin/test.txt
编辑内容如下:
[groups]
admin=svnadmin,Jacky
[/]
*=
@admin=rw
4,关联apache和SVN
编辑sudo vim /etc/apache2/conf-enabled/svn.conf
<Location /test>
DAV svn
SVNPath /share/data/svncode/test
AuthType Digest
AuthName "Tina"
AuthUserFile /share/data/scm/htdigest/passwd
Require valid-user
AuthzSVNAccessFile /share/data/scm/svnadmin/test.txt
</Location>
5.重启apache
sudo /etc/init.d/apache2 restart
6. 启动svn
svnserve -d -r /share/data/svncode
需要开机自运行的话写个脚本autosvn.sh,放到/root下内容如下:
#!/bin/bash
svnserve -d -r /share/data/svncode
修改/etc/rc.local
sudo vim /etc/rc.loacl
最后行添加/root/autosvn.sh
7. windows安装客户端即可,在客户端输入http://192.168.1.107/test就可访问。同样在浏览器输入对应的IP地址也可访问
8.设置提交格式
修改hooks/pre-commit
SVNLOOK=/usr/bin/svnlook
if [ -z "`$SVNLOOK log -t "$TXN" "$REPOS" | grep "Reason:"`" ]; then
echo "Please Refer to the following format:" 1>&2
echo "Reason: xxxx" 1>&2
echo "Auditor:xxxx" 1>&2
exit 1
fi
if [ -z "`$SVNLOOK log -t "$TXN" "$REPOS" | grep "Auditor:"`" ]; then
echo "Please Refer to the following format:" 1>&2
echo "Reason: xxxx" 1>&2
echo "Auditor:xxxx" 1>&2
exit 1
fi
9. 设置权限目录自动更新
9.1 创建权限目录
svnadmin create /share/data/svncode/scm
9.2 创建权限文件
touch /share/data/scm/svnadmin/scm.txt并配置权限参数
9.3 下载权限目录
svn co http://192.168.1.107/scm --username=“Jacky”
9.4 svn.conf配置scm仓库以及权限
9.5 在scm/hookes/post-commit添加
SVN=/usr/bin/svn
scmupdate=/share/data/svn/scm/svmadmin
export LANG=en_US.UTF-8
$SVN up --username Jacky --password passwd--no-auth-cache --non-interactive --force $scmupdate > /dev/null
9.6 重启apache ,这样每次权限目录更新,就会被及时更新