部署Svn+Apache服务器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了部署Svn+Apache服务器相关的知识,希望对你有一定的参考价值。

一、部署环境

操作系统:centos7.4
yum已配置
selinux已关闭

二、部署svn+apache

1、通过yum安装apache和svn

[[email protected] ~]# yum install -y httpd subversion mod_dav_svn

mod_dav_svn是apache访问svn的模块

2、验证

[[email protected] ~]# httpd -version
Server version: Apache/2.4.6 (CentOS)
Server built:   Aug  4 2017 03:19:10

[[email protected] ~]# svnserve --version
svnserve, version 1.7.14 (r1542130)
     compiled Nov 20 2015, 19:25:09

[[email protected] ~]# find / -name mod_dav_svn.so
[[email protected] ~]# find / -name mod_dav_svn.so
/usr/lib64/httpd/modules/mod_dav_svn.so
[[email protected] ~]# find / -name mod_authz_svn.so
/usr/lib64/httpd/modules/mod_authz_svn.so

3、指定svn目录,并创建仓库

[[email protected]~]# mkdir /svn
[[email protected] ~]# svnadmin create /svn/repo
[[email protected] ~]# ll /svn/repo
total 8
drwxr-xr-x 2 root root  54 Dec  3 13:26 conf
drwxr-sr-x 6 root root 233 Dec  3 13:26 db
-r--r--r-- 1 root root   2 Dec  3 13:26 format
drwxr-xr-x 2 root root 231 Dec  3 13:26 hooks
drwxr-xr-x 2 root root  41 Dec  3 13:26 locks
-rw-r--r-- 1 root root 229 Dec  3 13:26 README.txt

4、修改仓库属主属组为apache

[[email protected] ~]# chown -R apache:apache /svn/repo/
[[email protected] ~]# ll /svn/repo/
total 8
drwxr-xr-x 2 apache apache  54 Dec  3 13:46 conf
drwxr-sr-x 6 apache apache 233 Dec  3 13:46 db
-r--r--r-- 1 apache apache   2 Dec  3 13:46 format
drwxr-xr-x 2 apache apache 231 Dec  3 13:46 hooks
drwxr-xr-x 2 apache apache  41 Dec  3 13:46 locks
-rw-r--r-- 1 apache apache 229 Dec  3 13:46 README.txt

5、创建svn的用户文件和权限文件

[[email protected] ~]# cd /svn/
[[email protected] svn]# touch passwd
[[email protected] svn]# cp repos/project01/conf/authz /svn/
[[email protected] svn]# chown apache:apache passwd
[[email protected] svn]# chown apache:apache authz
[[email protected] svn]# ll
total 4
-rw-r--r-- 1 apache   apache   1080 Dec  3 13:34 authz
-rw-r--r-- 1 apache   apache      0 Dec  3 13:33 passwd
drwxr-xr-x 3 apache apache   23 Dec  3 13:26 repo

6、创建用户admin和guest

[[email protected] svn]# htpasswd -b passwd admin qwer1234
Adding password for user admin
[[email protected] svn]# htpasswd -b passwd guest qwer1234
Adding password for user guest
在权限文件里添加(rw读写,r只读)
[[email protected] svn]# vim authz
...
[/]
admin = rw
guest = r

7、配置httpd

[[email protected] ~]# vim /etc/httpd/conf.d/subversion.conf

<Location /svn/>
        DAV svn
        SVNParentPath /svn
     SVNListParentPath on
        AuthType Basic
        AuthName "Authorization SVN"
        AuthzSVNAccessFile /svn/authz
        AuthUserFile /svn/passwd
        Require valid-user
</Location>

8、启动apache服务

[[email protected] ~]# systemctl start httpd
[[email protected] ~]# netstat -antp|grep :80
tcp6       0      0 :::80                   :::*                    LISTEN      1015/httpd

9、验证部署是否成功

打开浏览器,访问http://ip/svn/repo 输入用户名密码即可访问

技术分享图片

三、下载TortoiseSVN客户端来访问进行svn的访问

1、下载并安装

https://tortoisesvn.net/

2、打开并输入svn访问地址进行访问

技术分享图片

输入用户名密码即可看到访问结果

四、禁止删除与强制注释

要求:禁止普通用户删除文件,并针对管理员用户使其只在某个项目下的某个文件夹有删除权限,并且所有用户上传文件时需添加注释
实现:通过编写钩子脚本来实现
注:因对shell掌握不熟,以下脚本难免有疏漏之处,有改进的地方可以交流下

1、

[[email protected] ~]# cd /svn/repo/hooks/
[[email protected] hooks]# ll
total 36
-rw-r--r-- 1 apache apache 1977 Dec  3 13:46 post-commit.tmpl
-rw-r--r-- 1 apache apache 1638 Dec  3 13:46 post-lock.tmpl
-rw-r--r-- 1 apache apache 2289 Dec  3 13:46 post-revprop-change.tmpl
-rw-r--r-- 1 apache apache 1567 Dec  3 13:46 post-unlock.tmpl
-rw-r--r-- 1 apache apache 3426 Dec  3 13:46 pre-commit.tmpl
-rw-r--r-- 1 apache apache 2434 Dec  3 13:46 pre-lock.tmpl
-rw-r--r-- 1 apache apache 2786 Dec  3 13:46 pre-revprop-change.tmpl
-rw-r--r-- 1 apache apache 2122 Dec  3 13:46 pre-unlock.tmpl
-rw-r--r-- 1 apache apache 2780 Dec  3 13:46 start-commit.tmpl

修改pre-commit.tmpl为pre-commit,并给予755权限

[[email protected] hooks]# cp pre-commit.tmpl pre-commit
[[email protected] hooks]# chmod 755 pre-commit
[[email protected] hooks]# ll
total 40
-rw-r--r-- 1 apache apache 1977 Dec  3 13:46 post-commit.tmpl
-rw-r--r-- 1 apache apache 1638 Dec  3 13:46 post-lock.tmpl
-rw-r--r-- 1 apache apache 2289 Dec  3 13:46 post-revprop-change.tmpl
-rw-r--r-- 1 apache apache 1567 Dec  3 13:46 post-unlock.tmpl
-rwxr-xr-x 1 apache apache 3426 Dec  3 14:25 pre-commit
-rw-r--r-- 1 apache apache 3426 Dec  3 13:46 pre-commit.tmpl
-rw-r--r-- 1 apache apache 2434 Dec  3 13:46 pre-lock.tmpl
-rw-r--r-- 1 apache apache 2786 Dec  3 13:46 pre-revprop-change.tmpl
-rw-r--r-- 1 apache apache 2122 Dec  3 13:46 pre-unlock.tmpl
-rw-r--r-- 1 apache apache 2780 Dec  3 13:46 start-commit.tmpl

2、编辑文件

#!/bin/sh
REPOS="$1"
TXN="$2"
SVNLOOK=/usr/bin/svnlook
SCMLIST="admin"            
C_USER=`$SVNLOOK info -t $TXN $REPOS | sed -n "1p"`
PROJECT=repo

if [ " `echo $SCMLIST | grep $C_USER |wc -l`" -eq 1  ];then
        echo `$SVNLOOK changed -t $TXN $REPOS` > /svn/$PROJECT/commit_log
        admin_path=`grep $C_USER /svn/$PROJECT/admin_path | awk -F " " ‘{print $2}‘`
        user_path=`cat /svn/$PROJECT/commit_log|cut -d" " -f2`
        if  cat /svn/$PROJECT/commit_log|cut -d" " -f1|uniq -u|grep "^D";then
                if  [ `echo ${user_path%/*}` != `echo $admin_path` ];then
            echo "You do not have permisson to delete a file" >&2
            exit 1
                fi
     fi
fi

LOGMSG=$($SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" | wc -c)
if [ "$LOGMSG" -lt 1 ]; then
        echo -e "
 Please write a note "1>&2
exit 1
fi
exit 0

其中admin_path 为管理员用户在那个文件夹下有删除权限,需手工添加

以上是关于部署Svn+Apache服务器的主要内容,如果未能解决你的问题,请参考以下文章

在centos6上部署apache+svn服务器

linux安装部署apache+subversion+jsvnadmin

Apache+SVN部署

Apache+SVN部署

如何用Jenkins实现自动化部署svn更新代码

微信开发之SVN提交代码与FTP同步到apache的根目录