源服务器IP:192.168.8.51

目标服务器IP:192.168.8.79

安装前源服务器及目标服务器均需关闭FIREWALLD\SELINUX防火墙

sestatus | grep status

systemctl disable firewalld.service

setenforce 0

一、源服务器安装

源服务器需要安装inotify-tools、rsync 服务,inotify脚本服务放置此主机上监控源文件目录变化:

安装inotify-tools

yum -y intsll inotify-tools

安装rsync并配置开机启动

yum -y intsll inotify-tools
systemctl enable --now rsyncd.service

密码配置文件rsync.pas 放置在/etc目录下,并修改权限为600

123456
chmod 600 /etc/rsync.pas

重启rsync服务

systemctl restart rsyncd

准备inotify_rsync.sh 脚本来监控源文件目录

#!/bin/bash
# chkconfig: 2345 10 90
# description: resind SRC='/wwwroot/web/ma_tm_system/'
DEST='rsyncuser@192.168.8.79::backup'
rpm -q rsync &> /dev/null || yum -y install rsync
inotifywait -mrq --exclude=".*\.swp" --timefmt '%Y-%m-%d %H:%M:%S' --format '%T %w %f' -e create,delete,moved_to,close_write,attrib ${SRC} |while read DATE TIME DIR FILE;do
FILEPATH=${DIR}${FILE}
rsync -az --delete --password-file=/etc/rsync.pas $SRC $DEST && echo "At ${TIME} on ${DATE}, file $FILEPATH was backuped up via rsync" >> /var/log/changelist.log
done

脚本放置在 /etc/init.d/下,并增加可执行权限,并配置开机启动。

chmod +x /etc/init.d/inotify_rsync.sh
chkconfig --add inotify_rsync.sh

二、目标服务器:192.168.8.79安装:

1、安装inotify-tools

yum -y intsll inotify-tools

2、安装rsync并配置开机启动

yum -y intsll inotify-tools
systemctl enable --now rsyncd.service

3、备份rsync原配置文件及密码文件,并用准备好的配置文件覆盖。

cp /etc/rsyncd.conf  /etc/rsyncd.conf.bak

准备好的 rsyncd.conf 配置文件

# /etc/rsyncd: configuration file for rsync daemon mode

# See rsyncd.conf man page for more options.

# configuration example:

# uid = nobody
# gid = nobody
# use chroot = yes
# max connections = 4
# pid file = /var/run/rsyncd.pid
# exclude = lost+found/
# transfer logging = yes
# timeout = 900
# ignore nonreadable = yes
# dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2 # [ftp]
# path = /home/ftp
# comment = ftp export area
uid = root
gid = root
max connections = 0
ignore errors
exclude = lost+found/
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
reverse lookup = no [backup]
path = /wwwroot/web/ma_tm_system/
comment = backup dir
read only = no
auth users = rsyncuser
secrets file = /etc/rsync.pas

4、密码配置文件rsync.pas 放置在/etc目录下,并修改权限为600

rsyncuser:123456
chmod 600 /etc/rsync.pas

重启rsync服务

systemctl restart rsyncd

5、目标服务器增加脚本用于监控WEB目录发生变化重启Core 服务。

inotify_resetCore.sh

#!/bin/bash
# chkconfig: 2345 10 90
# description: resind
SRC='/wwwroot/web/ma_tm_system/'
inotifywait -mrq --exclude=".*\.swp" --timefmt '%Y-%m-%d %H:%M:%S' --format '%T %w %f' -e create,delete,moved_to,close_write,attrib ${SRC} |while read DATE TIME DIR FILE;
do
systemctl restart Core.service
done

脚本放置在 /etc/init.d/下,并增加可执行权限,并配置开机启动。

chmod +x /etc/init.d/inotify_resetCore.sh
chkconfig --add inotify_rsync.sh

centos7下rsync+inotify脚本实现文件同步,.NET CORE客户端文件更新后自动重启服务的更多相关文章

  1. CentOS7下Rsync+sersync实现数据实时同步

    近期公司要上线新项目,后台框架选型我选择当前较为流行的laravel,运行环境使用lnmp. 之前我这边项目tp32+apache,开发工具使用phpstorm. 新建/编辑文件通过phpstorm配 ...

  2. CentOS7之Rsync+Inotify架构实现实时同步文件和文件夹

    简介:rsync是用来同步文件和文件夹的,inotify是用来实现监听变动而自动同步的 OS:Centos7.3 服务器端:172.16.13.157 客 户 端  :172.16.13.156 目  ...

  3. Linux下Rsync+sersync实现数据实时同步

    inotify 的同步备份机制有着缺点,于是看了sersync同步,弥补了rsync的缺点.以下转自:http://www.osyunwei.com/archives/7447.html 前言: 一. ...

  4. Linux下Rsync+Inotify-tools实现数据实时同步

    Linux下Rsync+Inotify-tools实现数据实时同步 注意:下面的三个案例都是rsync 每次都是全量的同步(这就坑爹了),而且 file列表是循环形式触发rsync ,等于有10个文件 ...

  5. CentOS 6.5 rsync+inotify实现数据实时同步备份

    CentOS 6.5 rsync+inotify实现数据实时同步备份 rsync    remote sync 远程同步,同步是把数据从缓冲区同步到磁盘上去的.数据在内存缓存区完成之后还没有写入到磁盘 ...

  6. sersync基于rsync+inotify实现数据实时同步

    一.环境描述 需求:服务器A与服务器B为主备服务模式,需要保持文件一致性,现采用sersync基于rsync+inotify实现数据实时同步 主服务器A:192.168.1.23 从服务器B:192. ...

  7. svn版本库更新后自动同步到www

    注意:www目录一定要用SVN服务器 checkout出Repositories的代码 步骤: (1)新建www根目录 mkdir -p /data/www/lehuo (2)在www根目录下检出(c ...

  8. py脚本修改后自动重启

    在用socket.io, pika之类启动一个脚本死循环做server或者client的时候: 1脚本被编辑之后,是不会自动重启 2当代码报错的时候,会立即退出, 只能手动重新运行 python ap ...

  9. linux下rsync+inotify实现服务器之间文件实时同步

    先介绍一下rsync与inotify. 1.rsync 与传统的cp.tar备份方式相比,rsync具有安全性高.备份迅速.支持增量备份等优点,通过rsync可以解决对实时性要求不高的数据备份需求,例 ...

随机推荐

  1. 原生js获取子元素

    感谢原文作者:归一山人 原文链接:https://www.cnblogs.com/guiyishanren/p/12214757.html 获取子元素的方法有 //获取第一个demo类 dom = d ...

  2. bom-页面加载事件

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. vue中mapGetters和...mapGetters

    vuex中的...mapGetters(['name'])如何实现的 vuex vue.js 根据文档介绍 https://vuex.vuejs.org/zh-cn/... 和看了 http://ww ...

  4. nginx启动失败:Redirecting to /bin/systemctl start nginx.service Failed to start nginx.service: Unit not found.

    解决方法: 是因为nginx没有有添加到系统服务,手动手动添加一个即可. 在 /etc/init.d/下创建名为nginx的启动脚本即可,内容如下: #!/bin/bash # # chkconfig ...

  5. 云端iclound使用-陈棚

    使用NSmetadataQuery查询文档,增加,删除,编辑 界面设计完成后效果如图: 程序清单:FKDiary.h @interface FKDiary : UIDocument @property ...

  6. Xcode 插件失效,启动崩溃解决

    升级6.4点击 Alcatraz PackageManager 崩溃解决 进入插件安装目录 cd ~/Library/Application\ Support/Developer/Shared/Xco ...

  7. Kubernetes GitOps 工具

    Kubernetes GitOps Tools 译自:Kubernetes GitOps Tools 本文很好地介绍了GitOps,并给出了当下比较热门的GitOps工具. 简介 在本文中,将回顾一下 ...

  8. Typora如何上传图片到gitee

    Typora是一款非常好用的Markdown文本编辑器,深受广大程序员的青睐,那么在使用过程中,当我们插入图片的时候,其实是默认放在一个相对路径文件夹下的,这就导致,一旦我们移动文件,或者发送给别人, ...

  9. 对已有的docker容器增加新的端口映射

    一般在运行容器时,我们都会通过参数 -p(使用大写的-P参数则会随机选择宿主机的一个端口进行映射)来指定宿主机和容器端口的映射,例如 docker run -it -d --name [contain ...

  10. async同步异步

    1.同步:var async = require("async"); async.series([step1, step2, step3],function(err, values ...