1. 文件同步
https://pkgs.org/download/inotify-tools如果遇到notify-tools 无法通过指令安装时,可以下载对应的操作系统版本进行安装
1.1. 主服务器
实时同步
#sudo yum -y install notify-tools
同步账号
#sudo echo "123456" > /etc/rsyncd.secrets
#sudo chmod 600 /etc/rsyncd.secrets
用那个用户权限启动,对应的文件必须当前用户一致
#sudo chown root:root /etc/rsyncd.secrets
同步脚本
#sudo vim inotify.sh
#!/bin/bash
#监听文件变化
INOTIFY_CMD="inotifywait -mrq -e modify,create,attrib,move,delete /home/mcms/"
$INOTIFY_CMD | while read DIRECTORY EVEVT FILE
do
#同步文件
rsync -azH --delete --password-file=/etc/rsyncd.secrets --exclude-from=/home/ceshi/Soft/sh/exclude.list /home/mcms/ rsync@172.16.1.95::mcms
done
exclude.list 格式
*.yml
*.jar
后台启动
#sudo sh ./inotify.sh&
停止
#sudo ps -ef | grep inotify | grep -v "grep" | awk '{print $2}' | xargs sudo kill -9
1.2. 从服务器
同步账号
#sudoecho"rsync:123456" > /etc/rsyncd.secrets
同步配置
#sudo vim /etc/rsyncd.conf
uid = root
gid = root
use chroot = no
max connections = 2
pid file = /var/run/rsyncd.pid
log file = /var/log/rsyncd.log
lock file = /var/run/rsyncd.lock
[mcms]
path = /home/mcms
read only = no
auth users = rsync
secrets file = /etc/rsyncd.secrets
list = no
启动同步
#sudo rsync --daemon
重启同步
#sudo rm /var/run/rsyncd.pid
#ps -ef | grep rsync | grep -v grep |awk '{print $2}'| xargs sudo kill -9