安装
server和client端都需要安装rsync,只不过client端不需要配置:
# apt install rsync
2、配置server端的/etc/rsyncd.conf文件
拷贝示例配置文件到/etc目录
# cp /usr/share/doc/rsync/examples/rsyncd.conf /etc/
查看rsyncd.conf文件,按需要修改即可
# more /etc/rsyncd.conf
# sample rsyncd.conf configuration file
# GLOBAL OPTIONS
#motd file=/etc/motd
log file=/var/log/rsyncd.log
# for pid file, do not use /var/run/rsync.pid if
# you are going to run rsync out of the init.d script.
pid file=/var/run/rsyncd.pid
#syslog facility=daemon
#socket options=
# MODULE OPTIONS
[www] # 这里是认证的模块名,在client端需要指定
comment = source high app archive
path = /data/webroot/rsynctest # 需要同步的目录
use chroot = yes
# max connections=10
lock file = /var/lock/rsyncd
# the default for read only is yes...
read only = no
list = yes
uid = www-data
gid = www-data
# exclude =
# exclude from =
# include =
# include from =
auth users = appbackup # 认证的用户名,如果没有这行,则表明是匿名
secrets file = /etc/rsyncd.secrets # 认证密码文件
strict modes = yes
# hosts allow = 192.168.206.200 #充许任何主机连接
# hosts deny =
ignore errors = no # 可以忽略一些无关的IO错误
ignore nonreadable = yes
transfer logging = yes
# log format = %t: host %h (%a) %o %f (%l bytes). Total %b bytes.
timeout = 600
refuse options = checksum dry-run
dont compress = *.gz *.tgz *.zip *.z *.rpm *.deb *.iso *.bz2 *.tbz
3、在server端创建密码文件/etc/rsyncd.secrets,权限必须是0600
# nano /etc/rsyncd.secrets
username:password
user:123456
#chmod 600 /etc/rsyncd.secrets
4、设置rsync 开机启动
systemctl enable rsync