Web主機web
1.rsync使用的是xinet做爲其守護進程,咱們首先配置其爲開啓vim
# vim /etc/xinetd.d/rsync service rsync { disable = no //改成no flags = IPv6 socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon log_on_failure += USERID }
2,配置rsync服務bash
編輯文件/etc/rsyncd.conf服務器
uid = nobody gid = nobody use chroot = no max connections = 3 strict modes = yes pid file = /var/run/rsyncd.pid lock file = /var/run/rsyncd.lock log file = /var/log/rsyncd.log [web1] path = /www/htdocs ignore errors = yes read only = no write only = no hosts allow = 172.16.0.0/16 //容許能夠同步過來的主機 hosts deny = * list = false uid = root gid = root auth users = cyb //認證的用戶名 secrets file = /etc/rsync.passwd //使用的祕鑰文件所在的地方
3,建立密碼文件socket
#vim /etc/rsync.passwd cyb:123 //同步須要的用戶名和密碼 # chmod 600 /etc/rsync.passwd
啓動rsyncide
# service xinetd start
兩臺web 主機配置內容近似ui
SOURCE主機:spa
這邊也安裝rsync ,rsync 以服務器模式運行orm
安裝inotify-tools 和inotify-develserver
# yum install inotify*
書寫密碼文件
# vim /etc/rsync_client.pwd 123 # chmod 600 /etc/rsync_client.pwd
建立腳本
# vim rsync.sh #!/bin/bash host1=172.16.11.10 host2=172.16.11.11 src=/www/web/ dst1=web1 dst2=web2 user1=cyb user2=lyn /usr/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/bin/rsync -vzrtopg --delete --progress --password-file=/etc/rsync_client.pwd $src $user1@$host1::$dst1 /usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/rsync_client.pwd $src $user2@$host2::$dst2 echo "${files} was rsynced" >>/tmp/rsync.log 2>&1 done ~
在後臺運行
# bash /tmp/rsync.sh
最後,將此腳本加入系統自啓動文件開機本身啓動
echo「/tmp/rsync.sh&」>>/etc/rc.local
至此兩遍已經同步