rsync(remote synchronizetion) 意为远程数据同步。
服务器配置
#开启xinetd.d下服务
service rsync
{
disable = on
flags = IPv6
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
[root@ton ~]#chkconfig --list
atd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
auditd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
...
xinetd based services:
echo-dgram: off
echo-stream: off
rsync: on
tcpmux-server: off
telnet: on
time-dgram: off
time-stream: off
[root@ton ~]#
[root@ton ~]#useradd rsync -s /sbin/nologin -M
[root@ton ~]#chown rsync.rsync ./backup/ #目标目录
[root@ton ~]#echo "tom_backup:test12" > /etc/rsync.password #配置密码文件
[root@ton ~]#chmod 600 /etc/rsync.password
rsyncd.conf配置
rsync服务器端
[root@ton bin]#cd /etc/xinetd.d/
[root@ton xinetd.d]#vim rsync
[root@ton xinetd.d]#service xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
[root@ton xinetd.d]# lsof -i tcp:873
[root@ton xinetd.d]# rsync --daemon
[root@ton xinetd.d]# lsof -i tcp:873
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
rsync 2107 root 4u IPv4 13354 0t0 TCP *:rsync (LISTEN)
rsync 2107 root 5u IPv6 13355 0t0 TCP *:rsync (LISTEN)
[root@ton ~]#ps -ef |grep rsync
root 1677 1 0 23:22 ? 00:00:00 rsync --daemon
root 1679 1643 0 23:22 pts/1 00:00:00 grep rsync
[root@ton xinetd.d]#netstat -lnutp |grep rsync
tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 2107/rsync
tcp 0 0 :::873 :::* LISTEN 2107/rsync
rsync客户端
[root@paly ~]#echo "tontom" > /etc/rsync.password #配置密码
[root@paly ~]#rsync -avz test.txt tom_backup@192.168.31.223::backup --password-file=/etc/rsync.password
sending incremental file list
test.txt
sent 79 bytes received 27 bytes 212.00 bytes/sec
total size is 10 speedup is 0.09
报错
未到达对方主机,这里简单关闭iptabls[root@paly ~]#rsync -avz test.txt root@192.168.31.223::backup --password-file=/etc/rsync.password
rsync: failed to connect to 192.168.31.223: No route to host (113)
rsync error: error in socket IO (code 10) at clientserver.c(124) [sender=3.0.6]
[root@ton ~]#service iptables stop
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
使用服务器端配置文件中的用户,上面我设置的为tom_backup
[root@paly ~]#rsync -avz test.txt root@192.168.31.223::backup --password-file=/etc/rsync.password
@ERROR: auth failed on module backup
rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6]
查看日志
/var/log/rsyncd.log