zoukankan      html  css  js  c++  java
  • [Linux]-Rsync同步

    构建rsync远程同步


    -------------同步源-----------------发起端------------
              192.168.1.1            192.168.1.10
    1、配置IP地址并保证互通
    2、确定备份源
    [root@localhost ~]# mkdir /www
    [root@localhost ~]# touch /www/{1..50}.html
    3、创建备份账号
    [root@localhost ~]# vim /etc/rsyncd_users.db
    [root@localhost ~]# chmod 600 /etc/rsyncd_users.db //必须设置为600,否则客户端认证失败。
    添加:
    cheney:123.com
    4、创建rsync配置文件
    [root@localhost ~]# vim /etc/rsyncd.conf //系统中无此文件,需手动创建。
    添加:

    uid = nobody
    gid = nobody
    use chroot = yes
    address = 192.168.1.1
    port 873
    log file = /var/log/rsyncd.log
    pid file = /var/run/rsyncd.pid
    hosts allow = 192.168.1.0/24
    [www]
        path = /www
        comment = cheney
        read only = yes
        dont compress = *.gz *.bz2 *.tgz *.zip *.rar *.z
        auth users = cheney
        secrets file = /etc/rsyncd_users.db


    5、启动(终止)rsync
    [root@localhost ~]# rsync --daemon
    [root@localhost ~]# netstat -anpt | grep rsync
    [root@localhost ~]# rsync --daemon
    [root@localhost ~]# netstat -anpt | grep rsync
         
    [root@localhost ~]# kill -9 PID号(例如:kill -9  9290)
    注意:如果重新启动失败时,先删除pid文件,然后再启动。
    [root@localhost ~]# rm -rf /var/run/rsyncd.pid
    6、验证:
    1)本地验证:(类似复制)
    [root@localhost ~]# rsync -rl /etc/httpd/ /tmp/
    2)发起端验证:( 把同步源的重要文件同步到发起端,作为备份)
    [root@localhost ~]#mkdir /www
    [root@localhost ~]#rsync -avz cheney@192.168.1.1::www /www/
    或者
    [root@localhost ~]#rsync -avz rsync://cheney@192.168.1.1/www /www/
    增量:
    [root@localhost ~]#rsync -avz --delete cheney@192.168.1.1::www /www/
    注:之前学习的内容为下行同步(类似于下载)

    上行同步:(类似于上传)
    [root@localhost ~]# rsync -avz --delete /www cheney@192.168.1.1::www
    注意:
    1、同步源中的权限:要把 read only 改写成 no;
    2、同步源中/www/的权限改为757
    7、设置计划任务自动远程同步
    在发起端作如下操作:
    [root@localhost ~]# vim /etc/cheney.password
    [root@localhost ~]# chmod 600 /etc/cheney.password
    [root@localhost ~]# crontab -e root
    添加:
    30 22 * * *     /usr/bin/rsync -az --delete --password-file=/etc/cheney.password
    cheney@192.168.1.1::www /www/
    [root@localhost ~]# service crond restart
    [root@localhost ~]# chkconfig crond on
    配置rsync+inotify实时同步
    1、调整内核参数
    [root@localhost ~]#cat /proc/sys/fs/inotify/max_queued_events
    [root@localhost ~]#cat /proc/sys/fs/inotify/max_user_instances
    [root@localhost ~]#cat /proc/sys/fs/inotify/max_user_watches
    [root@localhost ~]#vim /etc/sysctl.conf
    添加:
    fs.inotify.max_queued_events = 16384
    fs.inotify.max_user_instances = 1024
    fs.inotify.max_user_watches = 1048576
    [root@localhost ~]#sysctl -p
    2、安装inotify软件
    [root@localhost ~]#tar -zxvf inotify-tools-3.14.tar.gz -C /usr/src/
    [root@localhost ~]#/usr/src/inotify-tools-3.14/
    [root@localhost inotify-tools-3.14]#./configure && make && make install
    3、验证监控效果
    [root@localhost ~]#inotifywait -mrq -e modify,create,move,delete /var/www/html
    在另一个终端上进行增删改查的操作。
    4、编写触发式同步脚本
    [root@localhost ~]# vim inotify_rsync.sh
    添加:

    #!/bin/bash
    INOTIFY_CMD="inotifywait -mrq -e modify,create,attrib,move,delete /var/www/html/"
    RSYNC_CMD="rsync -azH --delete --password-file=/etc/hehe.password /var/www/html/
    cheney@192.168.1.1:/var/www/html"
    $INOTIFY_CMD | while read DIRECTORY EVENT FILE
    do
        if [ $(pgrep rsync | wc -l) -le 0 ] ; then
            $RSYNC_CMD
        fi
    done
  • 相关阅读:
    开源项目之Android Afinal框架
    DateTimePicker——开源的Android日历类库
    Android 教你打造炫酷的ViewPagerIndicator
    Android UI-仿微信底部导航栏布局
    Android 下拉刷新框架实现
    Android-设置PullToRefresh下拉刷新样式
    Android-PullToRefresh下拉刷新库基本用法
    android 在使用ViewAnimationUtils.createCircularReveal()无法兼容低版本的情况下,另行实现圆形...
    Android5.0新特性——兼容性(support)
    求訪问啊啊啊啊
  • 原文地址:https://www.cnblogs.com/chenwz/p/7531430.html
Copyright © 2011-2022 走看看