rpm安装

1. 直接使用yum命令安装即可

yum -y install rsync

2. 测试安装结果

rsync -h

3. 配置开机自启

#rpm安装方式默认安装到/usr/bin目录
echo "/usr/bin/rsync --daemon">>/etc/rc.local
源码安装

1.获取安装包

rsycn下载地址 https://download.samba.org/pub/rsync/,选择rsync-X.X.X.tar.gz文件下载。

wget https://download.samba.org/pub/rsync/rsync-3.2.3.tar.gz #该链接无法使用的话请自行到官网寻找最新下载地址

2.解压并安装

tar -zxvf rsync-3.2.3.tar.gz #解压缩

3.准备gcc编译环境(已安装跳过这一步)

yum -y install gcc

4.编译安装

cd rsync-3.2.3

./configure --disable-openssl --disable-xxhash --disable-zstd --disable-lz4
#--disable-openssl --禁用openssl
#--disable-xxhash --禁用xxhash
#--disable-zstd --禁用zstd
#--disable-lz4 --禁用-lz4

make &&make install #编译安装
#若出现 make: *** 没有指明目标并且找不到 makefile。 停止。现象
#cp Makefile.in Makefile

5. 测试是否安装成功

#源码安装自动安装到/usr/local目录
/usr/local/bin/rsync -h

# 以下提示代表安装成功
#rsync  version 3.2.3  protocol version 31
#Copyright (C) 1996-2020 by Andrew Tridgell, Wayne Davison, and others.
#Web site: https://rsync.samba.org/
#Capabilities:
#    64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,
#    socketpairs, hardlinks, hardlink-specials, symlinks, IPv6, atimes,
#    batchfiles, inplace, append, no ACLs, xattrs, optional protect-args,
#    iconv, symtimes, prealloc, stop-at, no crtimes
#Optimizations:
#    no SIMD, asm, no openssl-crypto
#Checksum list:
#    md5 md4 none
#Compress list:
#    zlibx zlib none

6.配置开机自启

echo "/usr/local/bin/rsync --daemon" >> /etc/rc.local
rsync配置

1.rsync服务器端配置

1. /etc/rsyncd.conf文件内容

uid = rsync
gid = rsync
use chroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors 
read only = false
truelist = false
#hosts allow = 192.168.253.0/24
#hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password

[test] 
comment = "这里是描述"
path = /test

2. rsync.password配置

#配置用户名密码,用户client端连接(账号:密码)
echo "rsync_backup:123456" > /etc/rsync.password
chmod 600 /etc/rsync.password

3. 配置同步路径权限

mkdir /test
chown -R rsync:rsync /backup
useradd rsync

2.rsync客户端配置

#client端连接服务器密码文件(文件只写密码内容)
echo "123456" > /etc/rsync_passwd
chmod 600 /etc/rsync_passwd

3. 测试

#在服务器启动rsync
rsync --daemon

#在client执行同步命令
#推送123文件到服务器,rsync_backup为登录用户名
echo "test" >> 123
rsync -avz -P  123  rsync_backup@服务器iP::test --password-file=/etc/rsync_passwd

#同步文件到本地
rsync -avz -P  rsync_backup@服务器iP::test ./ --password-file=/etc/rsync_passwd

rsync配置说明

不要直接复制此配置使用,文件中的注释内容会影响使用

uid = rsync     #rsync使用的用户,默认nobody
gid = rsync     #rsync使用的gid 默认nobody
use chroot = no    #是否限定在该目录下,默认为true,当有软连接时,需要改为fasle,如果为true就限定为模块默认目录,通常都在内网使用rsync所以不配也可以
max connections = 200 #设置最大连接数
timeout = 300 #超时时间 建议300-600
pid file = /var/run/rsyncd.pid    #pid文件位置
lock file = /var/run/rsync.lock  #指定lock文件用来支持“max connections ”参数使总连接不会超过限制
log file = /var/log/rsyncd.log #日志文件路径
ignore errors #忽略io错误
read only = false #指定客户端是否可以上传文件,默认
truelist = false #是否允许客户端查看可用模块 
#hosts allow = 192.168.253.0/24 #允许连接的ip段或个别ip,默认任何人都可以连接
#hosts deny = 0.0.0.0/32 #不允许连接的IP段或个别ip
auth users = rsync_backup #指定以空格或逗号分隔用户,他们可以使用这个模块,用户不需要再本系统存在,默认所有用户都可以无密码登录
secrets file = /etc/rsync.password #指定用户名和密码文件 格式: 用户名:密码 密码不超过8位这个是密码文件  全线最好是600
[test] #模块名称,可以有多个,自定义
comment = "this is a comment" #此参数指定在客户端获取可用模块列表时显示在模块名称旁边的描述字符串,默认没有这个参数
path = /opt #模块在服务端的绝对路径