centos下rsync同步数据

1、 安装rsync

yum -y installrsync

2、 无密码命令行同步

客户端操作

ssh-keygen -trsa

    ssh-copy-id -i /root/.ssh/[email protected]

ssh [email protected]

 

mkdir -pv/data/shell

rsync -az--delete [email protected]:/data/rsyncdata/ /data/shell/

3、 用密码服务方式同步

由于rsync属于xinetd的服务,因为需要先安装xinetd

yum -y installxinetd

vi/etc/xinetd.d/rsync

distable 改为 no

 

启动服务

/etc/init.d/xinetdstart

netstat -tunpl |grep 873

创建用户

useraddrsyncuser

echo '123456' |passwd --stdin rsyncuser

 

创建备份目录

mkdir -pv/data/rsyncdata

建立配置文件

vi/etc/rsyncd.conf

uid=nobody

gid=nobody

address=192.168.1.181

port=873

hostsallow=192.168.1.186

use chroot=yes

maxconnections=5

pidfile=/var/run/rsyncd.pid

lockfile=/var/run/rsync.lock

log file=/var/log/rsyncd.log

motdfile=/etc/rsyncd.motd

 

[backdata]

path=/data/rsyncdata

comment=rsyncbackup

read only=yes

list=yes

authusers=rsyncuser

secretsfile=/etc/rsyncd.passwd

 

建立提醒文件和密码文件

echo 'welcome tobackup server' > /etc/rsyncd.motd

vi/etc/rsyncd.passwd

rsyncuser:123456

chmod 600/etc/rsyncd.passwd

service xinetdrestart

 

客户端无密码同步

exportRSYNC_PASSWORD=123456

rsync [email protected]::backdata /data/shell/



rsync+inotify实时同步

 

1、 安装

tar xfinotify-tools-3.13.tar.gz

cdinotify-tools-3.13

./configure

make -j 4

make install

2、 修改配置文件

vi/etc/sysctl.conf

fs.inotify.max_queued_events= 32768

fs.inotify.max_user_instances  = 1024

fs.inotify.max_user_watches= 900000000

 

3、 生效

      sysctl –p

4、 生成密钥传到客户端面

ssh-keygen -trsa

[email protected]

ssh 192.168.1.186

 

5、 服务端面做一个脚本

#!/bin/bash

 

SDIR=/data/shell/

[email protected]

DDIR=/data/shell/

 

inotifywait -mrq-e create,delete,modify,move ${SDIR} | while read dir op file

do

        rsync -azP --delete ${SDIR}${USERIP}:${DDIR}

done

 

cp rsync.sh/etc/profile.d/rsync.sh

chmod +x/etc/profile.d/rsync.sh


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章