首页 > 其他 > 详细

rsync数据同步

时间:2018-07-30 14:34:16      阅读:231      评论:0      收藏:0      [点我收藏+]
实验环境:

技术分享图片

实验步骤:

一、手动同步

--------------------配置rsync源服务器---------------------------

vim /etc/rsyncd.conf

uid = nobody
  gid = nobody
  use chroot = yes
  address = 192.168.175.129
  port 873
  log file = /var/log/rsyncd.log
  pid file = /var/run/rsyncd.pid
  hosts allow = 192.168.175.0/24

[wwwroot]
  path = /var/www/html
  comment = www.kgc.cn
  read only = yes
  dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
  auth users = tom
  secrets file = /etc/rsyncd_users.db

vim /etc/rsyncd_users.db
   tom:123123

 


chmod 600 /etc/rsyncd_users.db

rsync –daemon

systemctl stop firewalld.service

setenforce 0

------------------------发起端---------------------------------------
格式一:
rsync -avz tom@192.168.43.128::wwwroot  /opt/   //密码abc123

格式二:
rsync -avz rsync://tom@192.168.43.128/wwwroot /opt/

二、免交互手动同步

vim /etc/server.pass

chmod 600 /etc/server.pass

#免交互
rsync -az --delete --password-file=/etc/server.pass tom@192.168.43.128::wwwroot /opt

---------------------------rsync+inotify(发起端)-------------------------------

注意:源端设置:read only = no

三、自动同步

vim /etc/sysctl.conf

fs.inotify.max_queued_events = 16384                 //表示调用inotify_init时分配给inotify instance中可排队的event的数目的最大值,超出这个值的事件被丢弃,

                                                                                             但会触发IN_Q_OVERFLOW事件

注意: max_queued_events 是inotify管理的队列的最大长度,文件系统变化越频繁,这个值就应该越大。如果你在日志中看到Event Queue Overflow,说明max_queued_events太小需要调整参数后再次使用。
fs.inotify.max_user_instances = 1024                    //表示每一个real user ID可创建的inotify instatnces的数量上限
fs.inotify.max_user_watches = 1048576              //表示同一用户同时可以添加的watch数目(watch一般是针对目录,决定了同时同一用户可以监控的目录数量)

sysctl -p

tar zxvf inotify-tools-3.14.tar.gz -C /opt/

cd /opt/inotify-tools-3.14

yum install gcc gcc-c++ -y

./configure

make && make install

inotifywait -mrq -e modify,create,move,delete /var/www/html/

另外再开启一个新的终端设置


vim /opt/inotify.sh

#!/bin/bash
INOTIFY_CMD="inotifywait -mrq -e modify,create,attrib,move,delete /var/www/html/"
RSYNC_CMD="rsync -azH --delete --password-file=/etc/server.pass /var/www/html/ tom@192.168.43.128::wwwroot/"
$INOTIFY_CMD | while read DIRECTORY EVENT FILE
do
     if [ $(pgrep rsync | wc -l) -le 0 ] ; then
         $RSYNC_CMD
     fi
done

//一定注意两边的同步目录权限都设置777

实验内容:

一、手动同步

--------------------配置rsync源服务器---------------------------

技术分享图片

技术分享图片

vim /etc/rsyncd_users.db
   tom:123123

chmod 600 /etc/rsyncd_users.db

使用格式1同步源端/var/www/html/ 中的内容

技术分享图片

技术分享图片

二、免密交互

vim /etc/server.pass

技术分享图片

技术分享图片

技术分享图片

三、自动同步

技术分享图片

yum install gcc gcc-c++ –y    注:在有网络的环境下安装

./configure

make && make install

技术分享图片

另开终端在发起端创建文件

技术分享图片

发起端运行脚本下显示信息

技术分享图片

文件1自动同步至源端

技术分享图片

rsync数据同步

原文:http://blog.51cto.com/13710287/2152085

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!