简介:

Sersync 是基于 inotify 来编写的 Linux 系统文件监控工具,当监控到文件发生变化时,调用 rsync 同步文件。

类似的功能,以前有用 rsync + inotify 实现过,这次来使用一下这个同步更迅速、功能更完善的 Sersync 。

一、代码分发服务器上安装 Sersync 、Rsync

shell > cd /usr/local/src
shell > wget https://github.com/wsgzao/sersync/archive/master.zip
shell > unzip master.zip
shell > cd sersync-master && ls
inotify-tools-3.14.tar.gz README.md rsync-3.1..tar.gz sersync2..4_64bit_binary_stable_final.tar.gz

# 来到这里,你只要看一眼 README.md 你就啥都懂了

> Rsync

shell > tar zxf rsync-3.1..tar.gz
shell > cd rsync-3.1.
shell > ./configure; make; make install

> Inotify-tools

shell > tar zxf inotify-tools-3.14.tar.gz
shell > cd inotify-tools-3.14
shell > ./configure; make; make install

> Sersync ( 监控同步目录变化,调用 Rsync 同步数据 )

shell > tar zxf sersync2..4_64bit_binary_stable_final.tar.gz
shell > mv GNU-Linux-x86 /usr/local/sersync

# 安装完毕

二、节点服务器安装、配置 Rsync

shell > cd /usr/local/src
shell > wget http://rsync.samba.org/ftp/rsync/src/rsync-3.1.1.tar.gz
shell > tar zxf rsync-3.1..tar.gz
shell > cd rsync-3.1.
shell > ./configure; make; make install shell > vim /etc/rsyncd.conf uid = www-data
gid = www-data log file = /var/log/rsyncd.log list = false
read only = no
use chroot = no
ignore errors = yes
max connections = auth users = rsync
secrets file = /etc/rsync.pass # hosts allow = 192.168.1.80
# hosts deny = * # 认证的模块名
[web1]
comment = web1
path = /data/webroot/web1 [web2]
comment = web2
path = /data/webroot/web2 shell > useradd -r -s /sbin/nologin www-data
shell > mkdir -p /data/webroot/{web1,web2}
shell > chown -R www-data.www-data /data/webroot shell > echo "rsync:123456" > /etc/rsync.pass
shell > chmod /etc/rsync.pass shell > setenforce # 关闭 SELinux
shell > vim /etc/selinux/config # 永久
SELINUX=disabled # 原 enforcing
SELINUXTYPE=targeted # 另外防火墙开放 TCP shell > rsync - --daemon # 以守护进程方式启动,- 只监听 IPV4
shell > echo "/usr/local/bin/rsync -4 --daemon" >> /etc/rc.local # 加入开机启动

三、代码同步服务器测试 Rsync,配置 Sersync

1、测试 Rsync 数据同步

shell > rsync -av --delete /data/webroot/web1/ rsync@192.168.1.30::web1  # 将 web1 目录下的文件同步到 1.30 web1 模块指定的目录下
password:

# 输入密码:123456,采用下面的方法,不需要手动输入密码

shell > echo "" > /etc/rsyncd.pass
shell > chmod /etc/rsyncd.pass shell > rsync -av --delete --password-file=/etc/rsyncd.pass /data/webroot/web1/ rsync@192.168.1.30::web1

# 注意同步目录及子目录、文件权限,设为 www-data、注意认证密码文件。

2、配置 Sersync

shell > cd /usr/local/sersync
shell > cp confxml.xml web1.xml shell > vim web1.xml # 编辑配置文件 <sersync>
<localpath watch="/data/webroot/web1">
<remote ip="192.168.1.30" name="web1"/>
</localpath>
<rsync>
<commonParams params="-artuz"/>
<auth start="false" users="root" passwordfile="/etc/rsync.pas"/>
<userDefinedPort start="false" port=""/><!-- port= -->
<timeout start="false" time=""/><!-- timeout= -->
<ssh start="false"/>
</rsync>
<failLog path="/tmp/rsync_fail_log.sh" timeToExecute=""/><!--default every 60mins execute once-->
<crontab start="false" schedule=""><!--600mins-->
<crontabfilter start="false">
<exclude expression="*.php"></exclude>
<exclude expression="info/*"></exclude>
</crontabfilter>
</crontab>

# <localpath watch="/data/webroot/web1"> # 需要同步的目录
# <remote ip="192.168.1.30" name="web1"/> # 同步主机,认证模块名 ( 可以写多条 )
# <commonParams params="-artuz"/> # Rsync 同步参数
# <auth start="false" users="root" passwordfile="/etc/rsync.pas"/> # 是否开启认证,客户端开启认证,需设为 true,填写认证用户、密码文件路径
# <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/> # 失败日志记录
# <crontab start="false" schedule="600"> # 自带任务计划,多长时间自动同步数据,默认关闭

3、运行 Sersync

shell > nohup /usr/local/sersync/sersync2 -r -d -n  -o /usr/local/sersync/web1.xml > /usr/local/sersync/logs/rsync_web1.log >& &

# -r 启动监控前,将监控目录与远程主机同步一次
# -d 启用守护进程模式
# -n 开启同步进程的数量,默认 10 个
# -o 指定配置文件,默认 confxml.xml

# 多个监控目录,指定不同的配置文件,开启多个进程。

四、测试 Sersync + Rsync

# 代码分发服务器上,监控目录内创建文件(修改权限),增加文件内容,查看节点服务器有没有同步数据。
# 删除文件、创建目录、删除目录

# 测试发现,如果同步目录内文件权限不为 www-data,该文件可以同步到节点服务器,但是追加文件内容,则无法同步。
# 注意文件权限。

# 一个完整的流程:开发同事将代码提交到版本库-->点击上线-->数据同步到线上代码分发服务器-->通过 Sersync + Rsync 分发到-->节点服务器

Sersync + Rsync 代码分发的更多相关文章

  1. rsync+sersync实现代码同步

    APP02安装 rsync服务端 yum install rsync vim /etc/rsyncd.conf pid file=/var/rsynclog/rsyncd.pid log file=/ ...

  2. 【linux运维】rsync+inotify与sersync+rsync实时数据同步笔记

    Rsync(remote sync)远程同步工具,通过rsync可以实现对远程服务器数据的增量备份通过,但rsync自身也有缺陷,同步数据时,rsync采用核心算法对远程服务器的目标文件进行对比,只进 ...

  3. sersync + rsync 实现文件的实时同步

    这里有一点要特别注意了,就是在你完成备份之后,先不要把本地的文件都给删除了,先把服务停了之后再删除文件, 因为你已删除,检查到两边不一致,他又会把备份端给删除了.所以特别得注意了.这里吃过一次亏. 还 ...

  4. Sersync+Rsync实现触发式文件同步

    背景 通常我们在服务器上使用rsync加上crontab来定时地完成一些同步.备份文件的任务.随着业务和应用需求的不断扩大.实时性要求越来越高.一般rsync是通过校验所有文件后,进行差量同步,如果文 ...

  5. [sersync+rsync] centos6.5 远程文件同步部署记录

    针对本地文件的修改,自动同步到远程文件夹,远程备份很方面.研究了下大家的主流同步方案一般是 rsync+inotify和rsync+sersync, 我这里使用sersync的方案,当然大部分都是参照 ...

  6. CentOS 7 Sersync+Rsync 实现数据文件实时同步

    rsync+inotify-tools与rsync+sersync架构的区别? 1.rsync+inotify-tools inotify只能记录下被监听的目录发生了变化(增,删,改)并没有把具体是哪 ...

  7. sersync+rsync实现服务器文件实时同步

    sersync+rsync实现服务器文件实时同步 一.为什么要用rsync+sersync架构? 1.sersync是基于inotify开发的,类似于inotify-tools的工具 2.sersyn ...

  8. sersync+rsync原理及部署

    标签:sersync+rsync部署文档 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://liubao0312.blog.51ct ...

  9. sersync+rsync实时数据同步

    sersync+rsync实时数据同步 1.相关背景介绍 前面有关文章配置实现了rsync增量同步以及配置为定时同步,但是在实际生产环境中需要实时的监控数据从而进行同步(不间断同步),可以采取inot ...

随机推荐

  1. java大文件断点续传

    java两台服务器之间,大文件上传(续传),采用了Socket通信机制以及JavaIO流两个技术点,具体思路如下: 实现思路:1.服:利用ServerSocket搭建服务器,开启相应端口,进行长连接操 ...

  2. ssh/scp免密码登录传输

    # 本地服务器生成key(直接回车默认) ssh-keygen # 将key传输到要登录的服务器 ssh-copy-id -i /root/.ssh/id_rsa.pub root@IP地址 # 输入 ...

  3. 在 GitHub 公开仓库中隐藏自己的私人邮箱地址

    GitHub 重点在开方源代码,其本身还是非常注重隐私的.这一点与面向企业的 GitLab 很不一样. 不过,你依然可能在 GitHub 上泄露隐私信息,例如企业内部所用的电子邮箱. GitHub 对 ...

  4. andriod studio报错 Emulator: emulator: ERROR: x86 emulation currently requires hardware acceleration! Emulator: Process finished with exit code 1

    安装即可,再次运行svd,成功

  5. atom的设置

    1.隐藏Keybinding Resolver Packages->Keybinding Resolver->Toggle.

  6. 《DSP using MATLAB》示例Example 8.29

    %% ------------------------------------------------------------------------ %% Output Info about thi ...

  7. WPF自定义控件之图形解锁控件 ScreenUnLock

    ScreenUnLock 与智能手机上的图案解锁功能一样.通过绘制图形达到解锁或记忆图形的目的. 本人突发奇想,把手机上的图形解锁功能移植到WPF中.也应用到了公司的项目中. 在创建ScreenUnL ...

  8. linux 磁盘挂载操作

    1. fdisk  -l      查看磁盘   2. fisk  /dev/vdb   进行分区        依次输入  n  p  1   两次回车  wq   3. fdisk -l  查看分 ...

  9. as3 阻止后续侦听器

    public class Test1 extends Sprite { private var spr:Sprite; private var spr2:Sprite; public function ...

  10. geohash 精度

    关于地图的距离.  $list1=Db::name('museum')->where('id','in',$user['gz'])->order('ACOS(SIN(('.$lat.' * ...