一、主機slavemysql
注:沒有包的能夠去下載c++
yum -y install gcc gcc-c++
上傳包 rsync-3.1.3.tar.gzweb
使用tar命令解壓sql
使用gcc gcc-c++編譯vim
./configure --prefix=/usr/local/rsync && make && make install
編譯完成後修改配置文件:bash
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
啓動服務:測試
編寫用戶和密碼:ui
保存退出;spa
chmod 600 /etc/server.pass
增長權限
關閉防火牆:
二、主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
執行腳本測試
最後查看一下日誌: