A为rsync server,启动为守护进程,B为备份机,做为rsync client,最后用crontab做一个简单的作业,定时在B上执行同步文件的功能
A的安装和配置如下:
1. apt-get install rsync 可能提示系统已经安装有了
2. 配置文件/etc/rsyncd.conf
默认安装时是不会有这个配置文件的,但是可以 cp /usr/share/doc/rsync/examples/rsyncd.conf /etc 把它示例中的配置文件拷贝过来
vi /etc/rsyncd.conf 这里参数有点多,但是有些可以先不管,关注重点的
[ftp] 这里是模块,可以配置多个,这个是系统默认给出的一个配置,下面给一个本机上的配置示例:
--------------------------------------------------------------------------------------------------
# so omit the "pid file" line completely in that case.
pid file=/var/run/rsyncd.pid
#syslog facility=daemon
#socket options=
# MODULE OPTIONS
[share]
comment = public archive
path = /var/www/pub
use chroot = no
max connections=2
#lock file = /var/lock/rsyncd
# the default for read only is yes...
read only = no
list = yes
uid = nobody
gid = nogroup
#exclude =
#exclude from =
#include =
#include from =
auth users = rsync
secrets file = /etc/rsyncd.secrets
strict modes = yes
hosts allow = 192.168.1.222
#hosts deny =
ignore errors = yes
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
---------------------------------------------------------------------------------------------
这里,最上面的是pid文件位置。然后配置了一个模块名叫做share,最大连接数是2,read only = no,指定为非只读(不然同步时会有权限问题)
而后面的auth users = rsync 是指定一个同步的账户名叫做rsync,这个账户的认证文件是/etc/rsyncd.secrets,当然我们要创建这个文件