首页 > 运维 > linux运维 > 正文

linux如何实现网页自动同步

PHPz
发布: 2023-05-15 16:58:21
转载
1102人浏览过

使用多个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

以上就是linux如何实现网页自动同步的详细内容,更多请关注php中文网其它相关文章!

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:亿速云网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号