龙空技术网

linux运维之代码一键发布方案Svn+inotify+rsync

佛系程序员 1498

前言:

眼前各位老铁们对“centos7svn配置钩子”大约比较珍视,看官们都想要知道一些“centos7svn配置钩子”的相关知识。那么小编同时在网络上收集了一些有关“centos7svn配置钩子””的相关知识,希望姐妹们能喜欢,咱们快快来了解一下吧!

流程:

1:代码测试没有问题后,提交到svn服务器。

2:svn服务器会update到某一目录下,inotify会监控这个目录的状态。

3:如果检测到目录状态改变,会rsync远程推送到后台的应用服务器。

Svn服务器安装: svn inotify 以及rsync后台应用服务器:rsync

开始安装:

准备服务器:

3台:1台svn 2台应用服务器

操作系统: CentOS Linux release 7.3.1611 (Core)

Svn服务器:

安装svn:

yum install subversion -y

cd /opt/

创建仓库目录 存储代码的目录

svnadmin create blog

vim /opt/blog/conf/svnserve.conf

修改一下配置

anon-access = none

password-db = passwd

authz-db = authz

vim /opt/blog/conf/auth

[/]

lampol = rw

vim /opt/blog/conf/passwd

[users]

lampol = 123456

配置钩子 实现提交代码 自动更新目录

cd /opt/shop/hooks

cp post-commit.tmpl post-commit

vim post-commit

添加一下配置

export LANG=en_US.UTF-8

/usr/bin/svn update /home/blog --username lampol --password 123456

chmod +x post-commit

开始启动svn配置

svnserve -d -r /opt/shop/

开始检出 检出到 /home/blog目录

svn co svn://127.0.0.1 /home/blog

客户端提交代码 可以看淡 提交的文件会自动更新到 /home/blog

svn配置完毕 成功

安装rsync

yum install rsync -y

vim /etc/rsyncd.passwd

123456

chmod 600 /etc/rsyncd.passwd

开始安装inotify

安装依赖

yum install automake libtool -y

wget

tar xf 3.20.1.tar.gz

cd inotify-tools-3.20.1/

./autogen.sh

./configure --prefix=/usr/local/inotify

make && make install

应用服务器

vim /etc/rsyncd.conf

pid file = /var/run/rsyncd.pid

lock file = /var/run/rsync.lock

log file = /var/log/rsyncd.log

uid = root

gid = root

use chroot = no

max connections = 200

timeout = 300

[blog]

path = /home/blog

ignore errors

read only = false

write only = no

list = false

hosts allow = 192.168.1.0/24

auth users = rsync

secrets file = /etc/rsyncd.passwd

vim /etc/rsyncd.passwd

rsync:123456

chmod 600 /etc/rsyncd.passwd

启动rsync

rsync --daemon

配置完毕后测试一下看看能不能推送过去

测试一下看看

rsync -av --delete --exclude ".svn" /home/www/ rsync@192.168.1.77::shop --password-file=/etc/rsyncd.passwd

运行脚本

#!/bin/bash

ips=('192.168.1.16' '192.168.1.36')

len=${#ips[@]}

/usr/local/inotify/bin/inotifywait -mrq --exclude /home/blog/.svn/ --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e close_write,modify,delete,create,attrib,move /home/blog/|while read file

do

echo $file >/tmp/inotify.txt

for (( i=0;i<$len;i++ ))

do

rsync -qav --delete --exclude '.svn' /home/blog/ rsync@${ips[$i]}::blog --password-file=/etc/rsyncd.passwd

done

done

本文章的对应视频教程,私聊我,或者看我空间即可看到。

标签: #centos7svn配置钩子