soft:rsync-3.0.8.tar.gz inotify-tools-3.14.tar.gz
wget http://rsync.samba.org/ftp/rsync/rsync-3.0.8.tar.gz
wget http://cloud.github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
server:192.168.2.211
bakserver:192.168.2.67
bakserver(被同步端):ios
- rsync安裝
- tar xzvf rsync-3.0.8.tar.gz
- cd rsync-3.0.8
- ./configure
- make
- make install
- mkdir /etc/rsyncd
- vim rsyncd.conf
- uid = root
- gid = root
- user chroot = no
- max connections = 50
- timeout = 180
- pid file = /etc/rsyncd/rsyncd.pid
- lock file= /etc/rsyncd/rsyncd.lock
- log file = /var/log/rsyncd.log
- transfer logging = yes
- log format = %t %a %m %f %b
- syslog facility = local3
- secrets file = /etc/rsyncd/rsyncd.password
- [nagios]
- path=/usr/local/nagios/
- ignore errors
- hosts allow = 192.168.0.0/22
- hosts deny = 0.0.0.0/32
- secrets file = /etc/rsyncd/rsyncd.password
- read only = no
- list = no
- auth users = yunwei
保存退出。
echo "yunwei:123456" >/etc/rsyncd/rsyncd.password #yunwei:123456,前者爲認證用戶名,後者爲認證密碼。
chmod 600 /etc/rsyncd/rsyncd.password #安全考慮
啓動服務:rsync --daemon --config=/etc/rsyncd/rsyncd.conf
加入自啓動:ehoc "rsync --daemon --config=/etc/rsyncd/rsyncd.conf" >/etc/rc.d/rc.local
server:
git
- rsync安裝
- tar xzvf rsync-3.0.8.tar.gz
- cd rsync-3.0.8
- ./configure
- make
- make install
- tar xvzf inotify-tools-3.14.tar.gz
- cd inotify-tools-3.14
- ./configure
- make
- make install
- ll /usr/local/bin/inotifywa*
- -rwxr-xr-x 1 root root 37264 04-14 13:42 /usr/local/bin/inotifywait
- -rwxr-xr-x 1 root root 35438 04-14 13:42 /usr/local/bin/inotifywatch
- inotify-tools安裝完成後,會生成inotifywait和inotifywatch兩個指令,其中,
- inotifywait用於等待文件或文件集上的一個特定事件,它能夠監控任何文件和目錄設置,而且能夠遞歸地監控整個目錄樹。
- inotifywatch用於收集被監控的文件系通通計數據,包括每一個inotify事件發生多少次等信息。
- 建立認證密碼:
- mkdir /etc/rsyncd
- echo "123456" >/etc/rsyncd/rsyncd.password #此處只需密碼便可。
- chmod 600 /etc/rsyncd/rsyncd.password
客戶端運行腳本:github
- vim nagios_rsync.sh
- #!/bin/bash
- src=/usr/local/nagios/
- des=nagios #此處爲模塊名稱。
- ip=192.168.2.67
- /usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e modify,delete,create,attrib $src | while read file
- do
- rsync -vzrtopg --delete --progress $src yunwei@$ip::$des --password-file=/etc/rsyncd/rsyncd.password >/dev/null 2>&1
- done
- 保存,賦予執行權限。
- 後臺運行:
- nohup ./nagios_rsync.sh &
- 加入自啓動:
- echo "nohup ./nagios_rsync.sh &" >>/etc/rc.d/rc.local
測試:
在客戶端nagios目錄下建立,刪除文件,在服務端當即能夠看到,證實實施同步正常。vim