*******************************************
*172.21.50.8 rsync服务器
*******************************************
-启动rsync
———————-
1.
[root@mail02 ~]#usr/bin/rsync –daemon
(需要root权限运行)
如果你的rsync.conf是在/etc/rsyncd这个目录下,则用一下命令
[root@server ~]#usr/bin/rsync –daemon –config=/etc/rsyncd/rsyncd.conf
可以在/etc/rc.d/rc.local里加入这条命令让系统启动后rsync自动启动等.
2.编加/etc/xinetd.d/rsync
# vim /etc/xinetd.d/rsync
建立一个名为/etc/xinetd.d/rsync文件,输入以下内容:
service rsync
{
disable = no
socket_type = stream
wait = no
user = root
server = /usr/local/rsync/bin/rsync
server_args = –daemon
log_on_failure += USERID
}
保存后,就可以运行rsync服务了。输入以下命令:
[root@server ~]# /etc/rc.d/init.d/xinetd reload
检查rsync进程是否启动
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
xinetd 7642 root 5u IPv6 18880648 0t0 TCP *:rsync (LISTEN)
———————–
-rsyncd.conf文件
-rsync只使用一个配置文件就是/etc/rsyncd.conf 这个文件一般是没有的,需要自己建一个
———————–
[root@server ~]# cd /etc/rsyncd.conf
#[globale] //全局定义
strict modes = yes
port = 873 //指定运行端口,默认是873,您可以自己指定
#uid = root //服务器端传输文件时,使用哪个用户和用户组来执行
#gid = root
read only = yes //只读
use chroot = no //好处是保护系统被安装漏洞侵袭的可能,缺点是需要超级用户权限
address = 172.21.50.10 // 指定服务器IP地址
#hosts allow = 172.21.50.10 //允许访问的主机
#hosts deny = * //拒绝访问的主机
logfile = /var/log/rsyncd.log //rsync 服务器的日志
pidfile = /var/run/rsyncd.pid //告诉进程写到 /var/run/rsyncd.pid 文件中
max connections = 4 //客户端最多连接数
timeout = 300 //连接超时
#[modules]
[accounts] //模块名
ignore errors //忽略IO错误
path = /tmp/accounts //指定文件目录所在位置,这是必须指定的
list = yes //是否把rsync 服务器上提供同步数据的目录显示出来
auth users = rsyncuser //认证用户 ,是必须在服务器上存在的用户
uid = root
gid = root
secrets file = /etc/rsyncd.scrt //密码存在哪个文件
comment = This is RHEL 5.3 /tmp/accounts //注释
[conf]
ignore errors
path = /tmp/conf
list = yes
auth users = rsyncuser
uid = root
gid = root
secrets file = /etc/rsyncd.scrt
comment = This is /tmp/conf
———————–
-rsyncd.scrt文件
-密码格式如下:
-用户名:密码 (有个冒号哟)
———————–
[root@server ~]# cat /etc/rsyncd.scrt
rsyncuser:abcdefg123…
因为rsyncd.scrt存储了rsync服务的用户名和密码,所以非常重要,因此文件的属性必须设
为600,只有所有者可以读写:
[root@mail02 ~]# chmod 600 /etc/rsyncd.scrt
————————
-停止rsync进程
————————
[root@server ~]# kill `cat /var/run/rsyncd.pid`
***************************************************
*172.21.50.10 备份服务器
***************************************************
———————–
-rsync.scrt 文件
———————–
[root@backup /]# cat /etc/rsync.scrt
abcdefg123…
[root@backup ~]# chmod 600 /etc/rsync.scrt
———————–
-rsync.sh脚本文件
-增量备份
———————–
[root@backup etc]# cat /root/script/rsync.sh
#!/bin/sh
/usr/bin/rsync -auv –progress –delete –password-file=/etc/rsync.scrt rsyncuser@172.21.50.10::accounts /tmp/accounts
/usr/bin/rsync -auv –progress –delete rsyncuser@172.21.50.10::conf /tmp/conf –password-file=/etc/rsync.scrt
[root@backup etc]# chmod 755 /root/script/rsync.sh
————————
-crontab
-每天凌晨1点进行同步
————————
[root@backup etc]# crontab -l -u root
0 1 * * * root sh /root/script/rsync.sh
或
[root@backup etc]# vim /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
0 1 * * * root sh /root/script/rsync.sh
# For details see man 4 crontabs
# Example of job definition:
# .—————- minute (0 – 59)
# | .————- hour (0 – 23)
# | | .———- day of month (1 – 31)
# | | | .——- month (1 – 12) OR jan,feb,mar,apr …
# | | | | .—- day of week (0 – 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
***************************
*trouble shooting
***************************
rsync: connection unexpectedly closed (90 bytes read so far)
rsync error: error in rsync protocol data stream (code 12) at io.c(150)
continuing without password file
Password:
rsync: connection unexpectedly closed (75 bytes read so far)
rsync error: error in rsync protocol data stream (code 12) at io.c(150)
rsync: connection unexpectedly closed (0 bytes received so far) [receiver]
rsync error: error in rsync protocol data stream (code 12) at io.c(359)
hosts allow = 192.168.1.0/24
hosts allow = 192.168.1.0/24 192.168.2.0/24
rsync error: error in socket IO (code 10) at clientserver.c(104) [receiver=2.6.9]
对方没开机、防火墙阻挡、通过的网络上有防火墙阻挡,都有可能。关闭防火墙,其实就是把tcp udp 的873端口打开
rsync error: error starting client-server protocol (code 5) at main.c(1506) [Receiver=3.0.7]
client端没有设置/etc/rsync.pas这个文件,而在使用rsync命令的时候,加了这个参数–password-file=/etc/rsync.scrt
rsync: recv_generator: mkdir “/teacherclubBackup/rsync……” failed: No space left on device (28)
*** Skipping any contents from this failed directory ***
rsync error: error in rsync protocol data stream (code 12) at io.c(759) [receiver=3.0.5]
xnetid查找的配置文件位置默认是/etc下,在/etc下找不到rsyncd.conf文件
rsync error: error in socket IO (code 10) at clientserver.c(124) [receiver=3.0.5]
连接服务器超时,检查服务器的端口netstat –tunlp,远程telnet测试