成都创新互联网站制作重庆分公司

rsync同步文件

一.服务端(需要被同步文件的主机)
    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地址

创新互联建站是专业的文成网站建设公司,文成接单;提供成都网站建设、成都网站制作,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行文成网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

[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


本文题目:rsync同步文件
网站URL:http://cxhlcq.com/article/iioodp.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部