Rsyncd 服务器配置

Posted by Sunday on 2018-03-29

安装rsync

1
yum install rsync -y

环境

server:192.168.10.100
client:192.168.10.101

配置rsyncd.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
address = 0.0.0.0
uid = nobody
gid = nobody
use chroot = no
max connections = 10
strict modes = yes
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log

ignore errors
read only = no
write only = no
hosts allow = 113.105.17.232/29,192.168.10.0/24
hosts deny = *
list = false
#uid = root
#gid = root
auth users = www
secrets file = /etc/rsyncd.pas


[backup]
path = /data/bak
comment = backup

[web]
path = /data/web
comment = site code

mkdir /mydata/data

server配置passwd

1
2
echo "myuser:mypass" > /etc/rsyncd.passwd
chmod 600 /etc/rsyncd.passwd

client配置

1
2
echo "mypass" /etc/rsyncd.passwd
chmod 600 /etc/rsyncd.passwd

修改防火墙策略

允许873端口(tcp/udp)

1
2
iptables -A INPUT -s 192.168.10.0 -p tcp -m state --state NEW -m tcp --dport 873 -j ACCEPT
service iptables save

启动服务器端 #也可以以xinetd运行。

1
/usr/bin/rsync --daemon --config=/etc/rsyncd.conf

开机自启动

1
echo '/usr/bin/rsync --daemon --config=/etc/rsyncd.conf'  >> /etc/rc.local

client上传测试

1
2
3
4
5
6
/usr/bin/rsync -avzP --delete  --progress --password-file=/etc/rsyncd.passwd /home/testfile myuser@192.168.10.100::mydata 

客户端传输文件到mydata中
rsync install.log.syslog myuser@192.168.10.100::mydata #没加--password-file就需要输入密码
客户端从服务器下载文件
rsync myuser@192.168.10.100::mydata/* ./

crontab任务

1
2
crontab -e
rsync --password-file=/etc/rsyncd.passwd install.log.syslog myuser@192.168.10.100::mydata

rsync参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
-a –archive归档模式,表示以递归方式传输文件,并保持所有文件属性,等于-rlptgoD
-r –recursive 对子目录以递归模式处理
-l –links 保留软链
-p –perms 保持文件权限
-t –times 保持文件时间信息
-g –group 保持文件属组信息
-o –owner 保持文件属主信息
-D –devices 保持设备文件信息
-z –compress 对备份的文件在传输时进行压缩处理
-P –partial 保留那些因故没有完全传输的文件,以是加快随后的再次传输
-v –verbose 详细模式输出
-e –rsh=COMMAND 指定替代rsh的shell程序
-u –update 仅仅进行更新,也就是跳过所有已经存在于DST,并且文件时间晚于要备份的文件。(不覆盖更新的文件)
–progress 显示备份过程
–delete 是指如果服务器端删除了这一文件,那么客户端也相应把文件删除,保持真正的一致。

CentOS 配置rsync xinetd运行
xinetd运行就不此操作 启动服务器端 开机自启动
只需修改/etc/xinetd.d/rsync后重启xinetd服务即可

1
2
3
4
5
vim /etc/xinetd.d/rsync

disable = no
service xinetd restart
chkconfig xinetd on

xinetd模式 ss-tunlp 是不会看到873的

查看日志:tail /var/log/rsyncd.log
密码正确,但还是提示密码错误
@ERROR: auth failed on module monitor27_bak
日志:auth failed on module monitor27_bak from unknown (192.168.10.27): missing secret for user “rsyncdemo”
解决:rsync服务器修改/etc/rsync.pas必须为600,若640则依旧报错。