linux 服务配置并设置svn钩子实现自动更新

2019-09-30  本文已影响0人  码农工号9527

一、svn安装设置

1.安装svn启动

yum install subversion

2.建个svn的根目录,因为项目不止一个

mkdir -p /home/svn/
3.新建一个新的空的版本仓库(subversion repository)

svnadmin create /home/svn/repos

4.添加用户

在/home/svn/repos/conf/passwd 添加

账号密码文件无需做修改,也是直接将账号和密码信息追加到文件中即可,注意格式为:

账号 = 密码

5.设置权限

只需在末尾添加,无需在文件其他部分修改和添加任何东西(请忽略groups被我马赛克的地方,那其实也是条无用的记录,我忘记删掉而已),末尾内容如下:

[]

账号1 = rw

账号2 = rw

6.修改svnserve.conf文件,让用户和策略配置升效.

### This file controls the configuration of the svnserve daemon, if you
### use it to allow access to this repository.  (If you only allow
### access through http: and/or file: URLs, then this file is
### irrelevant.)
 
### Visit http://subversion.tigris.org/ for more information.
 
[general]
### These options control access to the repository for unauthenticated
### and authenticated users.  Valid values are "write", "read",
### and "none".  The sample settings below are the defaults.
anon-access = none
auth-access = write
### The password-db option controls the location of the password
### database file.  Unless you specify a path starting with a /,
### the file's location is relative to the directory containing
### this configuration file.
### If SASL is enabled (see below), this file will NOT be used.
### Uncomment the line below to use the default password file.
password-db = passwd
### The authz-db option controls the location of the authorization
### rules for path-based access control.  Unless you specify a path
### starting with a /, the file's location is relative to the the
### directory containing this file.  If you don't specify an
### authz-db, no path-based access control is done.
### Uncomment the line below to use the default authorization file.
# authz-db = authz
### This option specifies the authentication realm of the repository.
### If two repositories have the same authentication realm, they should
### have the same password database, and vice versa.  The default realm
### is repository's uuid.
realm = My First Repository

7.关闭防火墙并开启服务仓库

systemctl stop firewalld

svnserve -d -r /home/svn 

8.设置钩子自动更新
建立你的web程序目录

mkdir /home/www

建立钩子脚本
在/home/svn/repos/hooks 目录下创建 post-commit,内容如下

#!/bin/bash
export LANG=en_US.UTF-8
SVN=/usr/bin/svn            #这里配置的是svn安装bin目录下的svn文件
WEB=/home/www      #要更新的目录
$SVN update $WEB --username admin --password 123456

让post-commit有执行的权限

chmod a+x post-commit

Checkout一份代码到站点目录

/usr/bin/svn checkout svn://localhost/repos /home/www

可以看到  /home/www/web 目录下就新增了这个文件了。
可以用windows svn客户端checkout一份代码到本地目录。第一次检出会要求数据用户名密码,即第四步配置的账号和密码

svn://192.168.1.112/repos

注意:192.168.1.112是我本地虚拟机的ip地址 实际根据自己的需求

上一篇 下一篇

猜你喜欢

热点阅读