rsync+inotify配置案例

1、系统光盘yum源安装:yum install rsync

2、创建需要同步的文件夹/common

/home : 表示将整个 /home 目录复制到目标目录
/home/ : 表示将 /home 目录中的所有内容复制到目标目录

2、在/etc/下创建rsyncd.conf文件
添加以下内容:
#/etc/rsyncd.conf
motd file = /etc/rsyncd.motd
transfer logging = yes
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
port = 873
address = 192.168.17.130
uid = nobody
gid = nobody
use chroot = no
read only = yes
max connections = 10
[common]
comment = web content
path = /common
ignore errors
auth users = tom,jerry
secrets file = /etc/rsyncd.secrets
hosts allow = 192.168.17.0/255.255.255.0
hosts deny = *
list = false

	4、echo "tom:pass" > /etc/rsyncd.secrets
	echo "jerry:111" >> /etc/rsyncd.secrets
	
	5、chmod 600 /etc/rsyncd.secrets
	
	6、 echo "welcome to access" > /etc/rsyncd.motd
	
	7、rsync --daemon
	
	8、echo "/usr/bin/rsync --daemon"  >> /etc/rc.local
	
	9、firewall-cmd --permanent --add-port=873/tcp
	
	---------------------客户端--------------------------------
	1、yum install rsycn
	
	2、访问:rsync -vzrtopg --progress tom@192.168.17.130::common /test
	
	3、echo "pass" > /etc/rsync.pass   把密码定义这里下面访问不用输入密码了(这个文件的权限一下要600不然报错)
	
	4、rsync -avz --delete --password-file=rsync.pass tom@192.168.17.130::common /dest
	所服务器上的common里的文件都弄过来test下面(以服务器common为准来变)
	
	5、写个脚本自动处理
	#!/bin/bash
	SRC=common
	DEST=/data
	Server=192.168.17.130
	User=tom
	Passfile=/root/rsync.pass
	[ ! -d $DEST ] && mkdir $DEST
	[ ! -d $Passfile ] && exit 2
	rsync -az --delete --password-file=$Passfile ${User}@${Server}::$SRC $DEST/$(date +%Y%m%d)
	-----------------------rsync+inotify双剑合并时时同步----------------------------------------------
	https://github.com/rvoicilas/inotify-tools.git  下载地址
	yum install rsync
	 yum install automake libtool
	下来解压文件完后进入文件夹,先bash autogen.sh运行出来configure文件
	再运行configure再make 再make install
	echo "pass" >/root/rsync.pass
	chmod 600 rsync.pass
	写个脚本实时监控:
	#!/bin/bash
	SRC=/web_data/
	DESR=common
	Client=192.168.17.130
	User=tom
	Passfile=/root/rsync.pass
	[ ! -e $Passfile ] && exit 2
	/local/src/inotifys/bin/inotifywait -mrq --timefmt '%y-%m-%d %H:%M' --format '%T %w%f %e' --event modify,create,move,delete,attrib \
	$SRC|while read line
	do
	echo "$line" > /var/log/inotify_web 2>&1
	/usr/bin/rsync -avz --delete --progress --password-file=/root/rsync.pass $SRC \
	${User}@${Client}::$DESR >> /var/log/rsync_web 2>&1
	done &
	
	给脚 本755权限,并加入开机启动
	-----------------------------------------------------------------------------------
	被监控端(web前端)
	yum install rsync
	mkdir -p /common
	chmod 755 /common
	chown nobody.nobody /common
	
	vim /etc/rsyncd.conf
	
	#/etc/rsyncd.conf
	transfer logging = yes
	log file = /var/log/rsyncd.log
	pid file = /var/run/rsyncd.pid
	lock file = /var/run/rsync.lock
	uid = nobody
	gid = nobody
	use chroot = no
	read only = no
	ignore errors
	
	[common]
	comment = web content
	path = /common
	auth users = tom
	secrets file = /etc/rsyncd.secrets
	hosts allow = 192.168.17.131
	hosts deny = *
	list = false
	
	
	echo "tom:pass" > /etc/rsyncd.secrets
	chmod 600 /etc/rsyncd.secrets
	rsync --daemon
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

项目工程师余工

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值