Linux的上文件实时同步的inotify + rsyncd的
服务器1上的文件需要实时同步到服务器2上(服务器1称为主服务器,服务器2称为客户端)
1:主服务器上制作和发送秘钥
制作秘钥:
ssh-keygen(一路回车)
查看秘钥:
cd~ / .ssh /; ls
id_rsa id_rsa.pub
发送秘密:
ssh-copy-id客户端ip地址(默认发送给root用户)
或者:
ssh-copy-id www @客户端ip地址(发送给www用户)
验证:(能免秘钥登录就ok)
ssh客户端ip地址(默认使用root登录)
或者:
ssh www @客户端ip地址
注意事项:
1:使用秘密登录
vim / etc / ssh / sshd_config
PermitRootLogin yes(允许root登录)
PubkeyAuthentication yes(开启
秘书登录)重启shd服务:systemctl restart sshd
2:主服务器上安装inotify
tar -zxvf inotify-tools-3.13.tar.gz
cd inotify-tools-3.13
./configure
make && make install
ln -s /usr/local/lib/libinotifytools.so.0 / usr / lib64的/ libinotifytools.so.0
3:主服务器和客户端操作
yum -y重新安装rsync
systemctl restart rsyncd
systemctl enable rsyncd
4:实时同步脚本:,实现实时同步
cat rsync.sh
#!/斌/庆典
killall rsync
systemctl重启rsyncd
dir = / home / wwwroot /(自动定义,需要同步的文件夹或文件)
而inotifywait -rqq“$ dir”
做
##某一些不
同步chown www.www -R / home / wwwroot /
rsync -avz -e\'ssh -p 22\' - 删除“$ dir”--exclude-from“exclude.txt”www @客户端1 -ip:“$ dir”> / dev / null
rsync -avz -e\'ssh -p 22\' - 删除“$ dir”--exclude-from“exclude.txt”www @客户端2-ip:“$ dir“> / dev / null
##全部
同步#rsync -avz -e\'ssh -p 22\' - 删除“$ dir”www @客户端1-ip:“$ dir”> / dev / null
#rsync -avz -e\'ssh -p 22\' - 删除“$ dir”www @客户端2-ip:“$ dir”> / dev / null
DONE
备注:--
exclude-from“exclude.txt”(不需要同步的目录名称或者文件名称)
如果rsync.sh此脚本在/ mnt下,exclude.txt文件也直接写在/ mnt下
(如果exclude.txt在其他路径则写绝对路径列: - exclude-from“/opt/exclude.txt”)
cat exclude.txt(文件或者文件夹名称。换行写,不能写在一行)
缓存
上传
log.txt
证书
kaijiang
newk3.sql
继续阅读与本文标签相同的文章
微信的这个新功能你用了吗?到底方不方便?
职场疯传的4款高效办公软件,看一下你装了哪一款
-
GSMA首席执行官洪曜庄:5G时代中国在引领
2026-05-14栏目: 教程
-
猎户星空CEO傅盛:现在是AI发展最好时期,家庭服务机器人前景可期
2026-05-14栏目: 教程
-
5G远程驾驶和微公交首秀互联网大会
2026-05-14栏目: 教程
-
学宏程序编程,这些知识必不可少!
2026-05-14栏目: 教程
-
华为准备卖出“落后”的5G,多家美企极力竞争!任正非格局太大!
2026-05-14栏目: 教程
