Rsync安装手册

Rsync安装手册

                      ---dxwang

什么是rsync

rsync,remote synchronize顾名思意就知道它是一款实现远程同步功能的软件,它在同步文件的同时,可以保持原来文件的权限、时间、软硬链接等附加信息。 rsync是用 “rsync 算法”提供了一个客户机和远程文件服务器的文件同步的快速方法,而且可以通过ssh方式来传输文件,这样其保密性也非常好,另外它还是免费的软件。

rsync 包括如下的一些特性:

  能更新整个目录和树和文件系统;
  有选择性的保持符号链链、硬链接、文件属于、权限、设备以及时间等;
  对于安装来说,无任何特殊权限要求;
  对于多个文件来说,内部流水线减少文件等待的延时;
  能用rsh、ssh 或直接端口做为传输入端口;
  支持匿名rsync 同步文件,是理想的镜像工具

检查rsync

rpm -qa|grep rsync

安装服务端

1、  在root用户操作

2、  添加两个文件/etc/rsync.pas和/etc/rsyncd.conf

rsyncd.conf

uid = root

gid = root

use chroot = no

max connections = 4

strict modes = yes

port = 873

 

 

[ext-lib]

path = /data/storm/ext-lib/

comment = try to realize file synchronization

ignore errors

read only = no

list = no

auth users = storm

secrets file = /etc/rsync.pas

hosts allow = 10.27.95.101 // 客户端的IP地址,多IP以逗号分隔

hosts deny = 0.0.0.0/0

rsync.pas

storm_bak

3、  安装inotify-tools

tar -zxvf inotify-tools-3.14.tar.gz

cd inotify-tools-3.14

./configure --prefix=/usr/local/inotify

make

make install

  

4、  启动rsync-monitor.sh(在/data/storm/rsync)

#!/bin/bash

ps -ef|grep "/usr/bin/rsync --daemon"|grep -v grep > /data/storm/rsync/rsync-info.log

num=`grep "/usr/bin/rsync --daemon" /data/storm/rsync/rsync-info.log|wc -l`

echo $num

if [ $num -eq 0 ];then

    echo "[$(date +'%F %T')] rsync is down,need restart"

    echo "-----" >> /data/storm/rsync/rsync-info-forever.log

    cat /data/storm/rsync/rsync-info.log >> /data/storm/rsync/rsync-info-forever.log

    /usr/bin/rsync --daemon

else

    echo "[$(date +'%F %T')] rsync is running"

fi

5、  启动rsync-inotify-monitor.sh(在/data/storm/rsync)

 #!/bin/bash

host=10.27.95.101,10.27.95.102 // 客户端IP

src=/data/storm/ext-lib/

des=ext-lib

user=storm

/usr/local/inotify/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $src | while read files

do

IFS=,

for each in $host

do

    /usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/rsync.pas $src $user@$each::$des

done

echo "${files} was rsynced" >> /data/storm/rsync/rsync-inotify.log 2>&1

done

安装客户端

1、  在目录/data/storm/rsync目录上传三个文件rsyncd.conf、rsync.pas和rsync-monitor.sh

rsyncd.conf

uid=root

gid=root

use chroot=no

max connections=4

strict modes=yes

 

 

[ext-lib]

path = /data/storm/ext-lib/

comment = try to realize file synchronization

ignore errors

read only = no

list = no

auth users = storm

secrets file = /data/storm/rsync/rsync.pas

hosts allow = 10.27.95.100 // 服务端IP

hosts deny = 0.0.0.0/0

rsync.pas,rsync.pas的权限是600

storm:storm_bak

rsync-monitor.sh

#!/bin/bash

num=`ps -ef|grep "/usr/bin/rsync --daemon"|wc -l`

if [ $num -eq 1 ];then

    echo "[$(date +'%F %T')] rsync is down,need restart"

    /usr/bin/rsync --daemon --config=/data/storm/rsync/rsyncd.conf

else

    echo "[$(date +'%F %T')] rsync is running"

fi

2、  启动rsync-monitor.sh

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值