1、主機slave
注:沒有包的可以去下載
yum -y install gcc gcc-c++
上傳包 rsync-3.1.3.tar.gz
使用tar命令解壓
使用gcc gcc-c++編譯
./configure --prefix=/usr/local/rsync && make && make install
編譯完成后修改配置文件:
vim rsyncd.conf
uid = nobody gid = nobody use chroot = no max connections = 10 strict modes = yes pid file = /var/run/rsyncd.pid lock file = /var/run/rsync.lock log file = /var/run/rsyncd.log [web1] path = /var/lib/mysql/ comment = web1 file ignore errors read only = no write only = no hosts allow = 192.168.80.129 #hosts deny = list = false uid = root pid = root auth users = web secrets file = /etc/server.pass ~
保存退出;
加權限;chmod 600 rsyncd.conf
啟動服務:
編寫用戶和密碼:
保存退出;
chmod 600 /etc/server.pass
增加權限
關閉防火牆:
2、主master服務配置;
vim /etc/server.pass
保存退出;
chmod 600 /etc/server.pass
上傳包
解壓文件;
tar xf inotify-tools-3.13.tar.gz tar xf rsync-3.1.3.tar.gz
編譯安裝rsync:
./configure --prefix=/usr/local/rsync && make && make install
在主服務器上只需要安裝不需要啟動!!!!!!!!!!!!!!!!!!!!!!!
編譯安裝inotify:
./configure --prefix=/usr/local/inotify && make && make install
關閉防火牆后測試!!!!!!!!!
/usr/local/rsync/bin/rsync -av /var/lib/mysql/ web@192.168.80.133::web1 --password-file=/etc/server.pass
如果成功則編寫腳本
#!/bin/bash host1=192.168.80.133 src=/var/lib/mysql/ dst1=web1 user=web /usr/local/inotify/bin/inotifywait -mrq --timefmt "%d%m%y%H:%M" --format "%T%w%f%e" -e modify,delete,create,attrib $src \ | while read files do /usr/local/rsync/bin/rsync -vzrtopgq --delete --progress --password-file=/etc/server.pass $src $user@$host1::$dst1 echo "${files} web is ok" >>/tmp/rsync.log 2>&1 done
執行腳本測試
最后查看一下日志: