linux网页自动化,linux系统中通过rsync+inotify实现网页自动同步

使用多个web服务器实现负载均衡,为了保持前端web服务器上资源的一致性可以通过rsync在主服务器上(可写入数据)将更新过的文件同步到其他从服务器(只读服务器),但是不能自动的进行实时同步,使用inotify可以实现实时同步

主服务器:192.168.6.205 inotify

从服务器:192.168.6.36 rsync

1、在从服务器上配置rsync,开启rsync服务,让主服务可以将资源同步到该服务器上

vim /etc/rsyncd.conf

uid = nginx

gid = nginx

port = 873

host all = 192.168.6.205

use chroot = on

max connections = 4

timeout = yes

[wordpress]

path = /usr/local/nginx/html/wordpress

comment = rsync files

ignore errors

read only = no

list = yes

auth users = rsync

secrets file = /etc/rsync.passwd

创建/etc/rsync.passwd密码配置文件

vim /etc/rsync.passwd

#用户:密码

rsync:rsync

2、在主服务器上安装inotify-tools

tar -zxvf inotify-tools-3.14.tar.gz

cd inotify-tools-3.14

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

make && make install

在主服务器上配置rsync密码文件,用于将数据同步到从服务器

vim /etc/rsync.passwd

#密码

rsync

创建脚本

vim inotifyrsync.sh

#!/bin/bash

host=192.168.6.36

src=/usr/local/nginx/html/wordpress/

dst=wordpress

user=rsync

inotifywait=/usr/local/inotify/bin/inotifywait

rsync=/usr/bin/rsync

$inotifywait -mrq –timefmt '%d/%m/%y %H:%M' –format '%T %w%f' -e modify,delete,create,attrib  $src  | while read files

do

$rsync -vzrtopg –delete –progress –password-file=/etc/rsync.passwd $src $user@$host::$dst

echo "${files} was rsynced" >>/tmp/rsync.log 2>&1

done

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值