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


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