Centos6.5下实现Rsync同步

 	批量同步、批量更新,这应该是做运维的朋友们经常做的工作,rsync是linux下一款非常强大的同步工具,采用差异同步的方法,只上传文件/文件夹的不同部分,同时可以对上传部分先进行压缩,所以rsync的传输效率是很高的但rsync也有缺点,最大的问题就是每次执行rsync命令都会遍历目标目录,当文件不多时,这没什么问题,一旦文件数到了一定规模,那么每次遍历都会消耗很多资源

环境:Centos6.5 32位
服务端:10.1.1.9
客户端:10.1.1.10

由于Centos6一般安装系统时候默认已经安装了Rsync了,所以我们只要配置就行了

服务端:

第一步:创建rsync配置文件

vim /etc/rsyncd.conf

uid = nobody    gid = nobody    use chroot = no  max connections = 100    timeout = 600    pid file = /var/run/rsyncd.pid     lock file = /var/run/rsyncd.lock     log file = /var/log/rsyncd.log     [data]    path = /data/mrtg/     ignore errors     read only = no    list = no    hosts allow = 10.1.1.0/24   auth users = rsync    secrets file = /etc/rsync.passwd

第二步:创建密码文件
	 vim /etc/rsync.passwd 
		rsync:123		#格式为 用户名:密码
	chmod 600 /etc/rsync.passwd
第三步:启动rsync
	rsync --daemon

第四步:添加防火墙
	iptables -I INPUT -p tcp --dport 873 -j ACCEPT

客户端:

第一步:添加密码文件
		vim /etc/rsync.passwd 
		123
	chmod 600 /etc/rsync.passwd 

第二步:同步命令
	/usr/bin/rsync -vzrtopg --delete --progress [email protected]::data /data/ --password-file=/etc/rsyncd.passwd 	#这是将服务器data内容同步到客户端
	
	/usr/bin/rsync -vzrtopg --delete --progress /data [email protected]::data --password-file=/etc/rsyncd.passwd 	#这是将/data/内容同步到服务端

第三步:添加计划任务,每五分钟同步一次
	vim /etc/crontab
	*/5 * * * * root /usr/bin/rsync -vzrtopg --delete --progress [email protected]::data /data/ --password-file=/etc/rsyncd.passwd



你可能感兴趣的:(linux技术类)