centos7搭建rsync

两台主机(centos7):

  172.16.0.109  server

  172.16.0.106  client

一、在172.16.0.109上

yum -y install rsync    #安装

mkdir -p /home/bcqf/rsync    #创建同步的目录

vim /etc/rsyncd.conf      #修改配置文件,先把文件清空,再写入以下内容

motd file = /etc/rsyncd.motd
transfer logging = yes
pid file = /var/run/rsyncd.pid

lock file = /var/run/rsyncd.lock

log file = /var/log/rsyncd.log
port = 873
address = 172.16.0.109
uid = root
gid = root
use chroot = no
read only = no
max connections = 10            #最大连接的客户端数

timeout = 300                #超时
[common]                  #模块名,可以写多个
comment = rsync bcqf
path = /home/bcqf/rsync/            #存放文件的目录(共享目录)
ignore errors                 #忽略错误
auth users = bcqf               #推拉文件时的虚拟用户
secrets file = /etc/rsyncd.secrets        #密码文件
hosts allow = 172.16.0.106,172.16.0.109    #允许的地址
hosts deny = *                #拒绝的地址
list = false

#[common]                  #又一个模块, 这就是多模块
#path = /home/xxx/data/

echo  "bcqf:123456"  >/etc/rsyncd.secrets    #创建用户  密码,

chmod  600  /etc/rsyncd.secrets        #调整权限

echo  "rsync bcqf"  >/etc/rsyncd.motd      #创建提示信息文件

rsync  --daemon                #启动

lsof -i :873                   #查看启动情况

#如果有开防火墙,要把873端口打开

echo "/usr/bin/rsync --daemon" >>/etc/rc.local    #添加开机启动

二、在172.16.0.106上

yum  -y  install  rsync

mkdir -p /home/bcqf/rsync

echo "123456" >/root/passwd

chmod 600 /root/passwd

rsync命令一定是在client上执行的,server端只有守护进程

拉取:

在172.16.0.109的 /home/bcqf/rsync/目录下创建一个文件;

在172.16.0.106上执行以下命令:

rsync  -avz  --password-file=/root/passwd  bcqf@172.16.0.109::common  /home/bcqf/rsync/    

注:/root/passwd :密码文件; bcqf:用户;common:模块名; /home/bcqf/rsync/:拉取到172.16.0.106的此目录下

在106上: ls /home/bcqf/rsync/    #查看是否已有在109上创建的文件

推送:

在172.16.0.106的 /home/bcqf/rsync/目录下创建一个文件;

在172.16.0.106上执行以下命令:

rsync  -avz  --password-file=/root/passwd  /home/bcqf/rsync/  bcqf@172.16.0.109::common   

注:/root/passwd :密码文件; bcqf:用户;common:模块名; /home/bcqf/rsync/:推送172.16.0.106此目录下的文件到172.16.0.109上,如果是“ /home/bcqf/rsync”这样(最后没/),就是直接把rsync这个目录也推过去;

在109上: ls /home/bcqf/rsync/    #查看是否已有在106上推送过来的的文件

客户端排除:

--exclude:

排除单个文件:--exclude=a

排除多个文件(不连续):--exclude={a,b}

排除多个文件(连续):--exclude={a..g}

--exclude-from:

seq 10 >paichu.log    #把要排除的文件名写进log文件中

--exclude-from=paichu.log    #排除log文件中写的文件

服务端排除:

在配置文件中写(不灵活)

 

原文地址:https://www.cnblogs.com/weiyiming007/p/9598250.html