依上图所示,架构分为Server端和客户端
实现目的:Server 端A 放置tomcat应用,Client 端B 为备份端,要实现把A端指定目录下的内容同步到B端
Server 端配置如下:
1.安装rsync
[root@localhost ~]# yum -y install rsync
2.编辑配置文件
[root@localhost ~]# vim /etc/rsyncd.conf
uid = nobody
gid = nobody
use chroot = no
max connections = 10
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[tomcat1]
uid = root
gid = root
path = /www/webapp/RedHorse
comment = test
ignore errors
read only = no
write only = no
list = yes
hosts allow = 192.168.0.2/24
hosts dengy = *
auth users = backup
secrets file = /etc/server.pass
3.创建server.pass
[root@localhost ~]# vim /etc/server.pass
backup:123456
4.启动rsync
[root@localhost ~]# rsync --daemon --config=/etc/rsyncd.conf
5.检查rsync是否启动
[root@localhost ~]# ps -ef | grep rsync
root 8086 1 0 15:05 ? 00:00:00 rsync --daemon --config=/etc/rsyncd.conf
root 9583 6224 0 15:58 pts/3 00:00:00 grep rsync
Client 端配置
1.创建客户端验证文件
[root@localhost ~]# more/etc/rsync.client.pass
123456
2.创建同步脚本
[root@localhost ~]# more sync.sh
#!/bin/bash
/usr/bin/rsync -vzrtopg --delete --exclude=index.do --exclude "content" --exclude "META-INF" --exclude "static" --exclude "upload" --exclude "WEB-INF" --password-file=/etc/rsync.client.pass backup
@192.168.0.1::tomcat1 /www/webapp/RedHorse
3.验证
目的实现
注意:
过滤目录的时候 目录名双引号引起来便可
例如: --exclude "content"