Redhat中安装rsync
1、
2、
或者:rpm –q rsync
3、
4、
配置rsync服务器端
5、
可以看到rysnc服务是关闭的(disable = yes),这里把它开启,把disable的值改为no
6、
[root@hyj etc]# vim /etc/
uid = root
gid = root
hosts allow = 192.168.0.204, 192.168.1.205
#hosts deny = 0.0.0.0/32
use chroot =
max connections =
timeout=
## 下面这些绿色文件是安装完RSYNC服务后自动生成的文件,当然也可以手动配置到指定路径
pid file = /var/run/
lock file = /var/run/
log file = /var/log/
#motd file = /etc/
## 上面这段是全局配置,下面的模块可以有
ignore errors
read only = yes
secrets file = /etc/
7、
[root@hyj etc]# vim /etc/
(名字随便写,只要和上边配置文件里的“auth users”参数一致即可),格式(一行一个用户)
账号:密码
(2)、把密码文件的权限改成600
[root@hyj etc]# chmod 600 /etc/
8、
[root@hyj etc]# vim /etc/
启动rsync
9、
10、 防火墙设置:
如果服务器上装有防火墙,需在服务器中设置iptables将837端口开放。
[root@hyj ~]# iptables -A INPUT -p tcp --dport 873 -j ACCEPT
11、 如果rsync进程没有运行,在server端将rsync启动:
(1)、启动rsync服务端(以守护进程形式,独立启动)
#/usr/bin/rsync –daemon
说明启动成功。
(切记:命令行启动的最后是daemon,而不是deamon,否则回报如下错误:
rsync: --deamon: unknown option
rsync error: syntax or usage error (code 1) at (1231) [client=2.6.8])
(2)、启动rsync服务端 (以xinetd超级进程启动)
# /etc///xinetd reload(reload是网上的说法,但是我试了一下报错,start可以)
12、 设置自动启动:
本机安装的Redhat中rsync已经是开机自动启动的,网上说的那两种方法,配置文件中都没有找到相应的配置,通过用chkconfig 命令查看和修改开机启动服务.
[root@hyj ~]# chkconfig
(结果部分省略),可以看出rsync处于on的状态。
配置rsync客户端
13、用安装服务器端的方式安装rsync。
14、启动rsync,如果报如下错误,是因为在etc下没有配置文件:
15、[root@hyj etc]# vi /etc/
文件内容为空就行。然后启动rsync,可以启动:
命令和实例
16、Rsync的命令格式可以为以下六种:
rsync [OPTION]... SRC DEST
rsync [OPTION]... SRC [USER@]HOST:DEST
rsync [OPTION]... [USER@]HOST:SRC DEST
rsync [OPTION]... [USER@]HOST::SRC DEST
rsync [OPTION]... SRC [USER@]HOST::DEST
rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]
17、常用为以下两种:
(4)、rsync [OPTION]... [USER@]HOST::SRC
从远程rsync服务器中拷贝文件到本地机。当SRC路径信息包含"::"分隔符时启动该模式。
如:rsync -av root@172.16.78.192::www /databack
(5)、rsync [OPTION]... SRC
从本地机器拷贝文件到远程rsync服务器中。当DST路径信息包含"::"分隔符时启动该模式。
如:rsync -av /databack root@172.16.78.192::www
18、下面为实例:
19、
[root@hyj ~]# /usr/bin/rsync -vzrtopg --delete
/etc/中模块的内容:
path = /home/hyj/workspace/test
comment = rsync files
ignore errors
read only = yes
list = no
auth users = rsync
secrets file = /etc/
上面这个命令行中-vzrtopg里的v是verbose,z是压缩,r是recursive,topg都是保持文件原有属性如属主、时间的参数(也可以用直接用a来代替rtopg, a为 --archive 归档模式,表示以递归方式传输文件,并保持所有文件属性,等于-rlptgoD)。--progress是指显示出详细的进度情况,--delete是指如果服务器端删除了这一文件,那么客户端也相应把文件删除,保持真正的一致。
(2)、上面的命令需要在备份的时候需要输入密码,可以在客户端建立一个密码文件,在命令中把密码文件作为参数带入:
[root@hyj rsync_backup]# vim /etc/
密码文件中不用输入用户名,只需输入密码即可:
这份密码文件权限属性要设得只有root可读,不然会报错,修改属性:
[root@hyj rsync_backup]# chmod 600 /etc/,
20、
把服务器上的/home/hyj/workspace/test文件夹中的内容备份到客户端的/usr/local/share/rsync_backup中,但不包括:res目录和文件:
/usr/bin/rsync -vzrtopg --delete --exclude "res/" --exclude "" --progress rsync@192.168.8.126::test /usr/local/share/rsync_backup --password-file=/etc/
Here are some exclude/include examples:
--include "foo/" --include "foo/" --exclude "*" would include only foo/
21、
此时服务器的配置文件/etc/内容为:
[test]
[clientdata]
path = /usr/local/share/rsync_backup
定时计划备份
22、
说明还没有为root这个账号提供crontab。执行crontab –e 创建一个crontab:
23、
24、
25、
20 9 * * *
26、附时间设置:
(1)、查看当前时区 :
(2)、查看时间和日期:date
(3)、设置时间和日期:
(4)、将当前时间和日期写入BIOS,避免重启后失效:hwclock -w
FAQ
27、我需要在防火墙上开放哪些端口以适应rsync?
A:视情况而定
或者
rsync -e 'ssh -p 2002' otherhost:
28、
A:rsync -av --include '*/' --exclude '*' source-dir dest-dir
常见错误
29、rsync: failed to connect to 218.107.243.2: No route to host (113)
rsync error: error in socket IO (code 10) at (104) [receiver=2.6.9]
解决:对方没开机、防火墙阻挡、通过的网络上有防火墙阻挡,都有可能。关闭防火墙,其实就是把tcp udp 的873端口打开:
注:最后一条规则(REJECT
本机测试通过的方法,打开服务器 873 端口:
(1)、[root@duoduo ~]# iptables -I INPUT -p tcp --dport 873 -j
( 2 )、上面提到的,插入规则到最后一条的前面:
#iptables -I RH-Firewall-1-INPUT 10 -p tcp -m state --state NEW -m tcp --dport 873 -j ACCEPT
#iptables -I RH-Firewall-1-INPUT 10 -p udp -m state --state NEW -m udp --dport 873 -j ACCEPT
插入规则:
插入规则后:
30、password file must not be other-accessible
continuing without password file
Password:
解决:这是因为 的权限不对,应该设置为600。如:chmod 600
31、@ERROR: auth failed on module xxxxx
rsync: connection unexpectedly closed (90 bytes read so far)
rsync error: error in rsync protocol data stream (code 12) at (150)
解决:这是因为密码设置错了,无法登入成功,检查一下,看客服是否匹配。还有服务器端没启动rsync 服务也会出现这种情况。
32、@ERROR: chroot failed
rsync: connection unexpectedly closed (75 bytes read so far)
rsync error: error in rsync protocol data stream (code 12) at (150)
解决:这是因为你在 中设置的 path 路径不存在,要新建目录才能开启同步。
33、[root@hyj rsync_backup]# /usr/bin/rsync -vzrtopg --delete --exclude "res/" --exclude "" --progress rsync@192.168.8.126::test /usr/local/share/rsync_backup --password-file=/etc/
@ERROR: chdir failed
rsync error: error starting client-server protocol (code 5) at (1516) [Receiver=3.0.9]
原因及解决办法:
34、ERROR: module is read only
rsync: read error: Software caused connection abort (113)
rsync error: error in rsync protocol data stream (code 12) at (769) [sender=3.0.8]
解决:这是因为服务器端配置文件中read only = yes,为只读,即不允许客户端上传文件,改成no就可以了。
参考网址:./443306/
详细配置:
转自:/s/blog_5eda2dda01015fcs.html