一、环境介绍
有IP地址末尾分别为*.*.*.3,*.*.*.4,*.*.*.5,*.*.*.6的4台主机,要求在*.*.*.6上部署一个新版本,*.*.*.3,*.*.*.4,*.*.*.5实时同步*.*.*.6上的新版本,
二、实施
1 在*.*.*.6上安装inotify
wget
tar zxvf inotify-tools-3.14.tar.gz
cd inotify-tools-3.14
./configure
make
make install
2 后天运行实时监控脚本./.in_rsyncd.sh &
vim .in_rsyncd.sh
- #!/bin/bash
- #---------------------------------------------------------------
- PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
- export PATH
- auth_user=nazca
- remote_ip_3=*.*.*.3
- remote_ip_4=*.*.*.4
- remote_ip_5=*.*.*.5
- remote_module=themis
- local_dir=/themis/glassfish3/glassfish/domains/domain1/themis-dist/
- auth_file=/etc/rsyncd.pwd
- rsync_path=/usr/bin/rsync
- inotify=/usr/local/bin/inotifywait
- $inotify -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w %f' -e modify,move,delete,create,attrib $local_dir | while read date time dir file;do
- FILECHANGE=${dir}${file}
- $rsync_path -avrop --delete $local_dir $auth_user@$remote_ip_3::$remote_module --password-file=$auth_file
- $rsync_path -avrop --delete $local_dir $auth_user@$remote_ip_4::$remote_module --password-file=$auth_file
- $rsync_path -avrop --delete $local_dir $auth_user@$remote_ip_5::$remote_module --password-file=$auth_file
- echo "At ${time} on ${date},file $FILECHANGE was backed up via rsync"
- done
3 配置rsync,分别在.3,.4,.5上配置rsync,启动rsyncd服务,
vim /etc/xinetd.d/rsync
- # default: off
- # description: The rsync server is a good addition to an ftp server, as it \
- # allows crc checksumming etc.
- service rsync
- {
- disable = no
- socket_type = stream
- wait = no
- user = root
- server = /usr/bin/rsync
- server_args = --daemon
- log_on_failure += USERID
- }
vim /etc/rsyncd.conf
- # Global Settings
- uid = root
- gid = root
- use chroot = no
- max connections = 80
- secrets file=/etc/rsyncd.pwd
- log file=/var/log/rsyncd.log
- pid file=/var/run/rsyncd.pid
- lock file=/var/run/rsyncd.lock
- [themis]
- path = /themis/glassfish3/glassfish/domains/domain1/themis-dist
- read only = no
- ignore errors
- list = no
注:ignore errors可以忽略,因为在同步的时候会产生如下报错:
params.c:Parameter() - Ignoring badly formed line in configuration file: ignore errors 配置完成重启/etc/init.d/xinetd restart
阅读(455) | 评论(0) | 转发(0) |