温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

rsync同步文件

发布时间:2020-02-26 09:22:47 来源:网络 阅读:176 作者:vicxiang 栏目:系统运维
一.服务端(需要被同步文件的主机)
    1. 安装rsync
            yum install -y rsync

    2. 配置,新增配置文件/etc/rsyncd.conf

[global]
uid = root
gid = root
use chroot = no
max connections = 10
list = yes
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
hosts allow = 192.168.217.130 //白名单,允许同步的机器IP地址

[data] //数据目录别名,同步时需要用到
path = /usr/local/src //别名对应的同步目录
ignore errors
read only = yes
auth users = vicxiang //同步时用到的用户名
secrets file = /etc/sery.pass //同步时用到的账号密码配置文件

    3. 配置,新增配置文件/etc/sery.pass

vicxiang:123456

         修改文件权限
         chmod 600 /etc/sery.pass

    4. 启动rsync服务
       rsync --daemon --config=/etc/rsyncd.conf

    5. 防火墙设置,端口需要开放tcp 873

二.客户端(文件同步到的目的机器)
    1. 配置密码文件/etc/sery_client.pass

123456

            修改文件权限
            chmod 600 /etc/sery_client.pass
    2. 同步命令
            rsync -avr -P  vicxiang@192.168.217.128::data /usr/local/src/ --password-file=/etc/sery_client.pass
            其中vicxiang是同步时使用的用户名;
            192.168.217.128是服务端IP;
            data是服务端配置的数据目录别名;
             /usr/local/src/是同步到本机的目录;
             /etc/sery_client.pass是配置密码文件

三.配合crontab定时同步 
        编写脚本rsync.sh

log_file=rsync.log

function sync(){
ip=${1}
path=${2}
t=date +%Y%m%d-%H%M%S
echo "${t} start to sync data from ${ip}..." >> ${log_file}
rsync -avr -P vicxiang@${ip}::data ${path} --password-file=/etc/sery_client.pass
echo "done" >> ${log_file}
}

sync ip path

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI