rsync 同步

依上图所示,架构分为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" 


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值