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