server:10.5.26.132
client:10.5.26.121
server配置
1.修改配置文件
$sudo cp /usr/share/doc/rsync/examples/rsyncd.conf /etc
$sudo vim /etc/rsyncd.conf
# sample rsyncd.conf configuration file
# GLOBAL OPTIONS
#motd file=/etc/motd
log file=/var/log/rsyncd
# for pid file, do not use /var/run/rsync.pid if
# you are going to run rsync out of the init.d script.
pid file=/var/run/rsyncd.pid
syslog facility=daemon
#socket options=
# MODULE OPTIONS
[ftp] #名字可以任意命名,只要客户端的rsync命令一致
comment = public archive
path = /home/www #指定路径,如果没有这个目录自己建。
use chroot = no
# max connections=10
lock file = /var/lock/rsyncd
# the default for read only is yes…
read only = yes
list = yes
uid = nobody
gid = nogroup
# exclude =
# exclude from =
# include =
# include from =
auth users = rsync_user #rsync连接时的用户名,要和客户端rsync的命令一致,这里的用户和系统用户没有任何关系
secrets file = /etc/rsyncd.secrets #这里是保存密码的地方,如果屏蔽掉就不用密码了
strict modes = yes
hosts allow = 10.5.26.121 #运行的客户端ip
# 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
创建一个密码文件
$sudo vi /etc/rsyncd.secrets
rsync_user:123456
$sudo chmod 0600 /etc/rsyncd.secrets
启动rsync前修改下这个文件
$sudo vi /etc/default/rsync
RSYNC_ENABLE=true #false改true
启动rsync服务
sudo /etc/init.d/rsync start
client配置
我们再来看一下客户端的操作,一般客户端不需要进行特殊的配置,直接同步即可
rsync -vzrtopg –progress rsync_user@10.5.26.132::ftp .
我们把这个同步工作交给crontab去执行。首先我们要创建一个密码文件
$sudo vi /etc/rsync.pwd输入123456,保存 #密码要一致
!注意:下面这两步操作是必须的,没有足够权限同步就会不成功,ls -l 你所指向的目录
sudo chmod 0600 /etc/rsync.pwd
sudo chown 普通用户:普通用户组 /etc/rsync.pwd
然后我们打开crontab,使它自动同步
$crontab -e
sudo rsync -avzP –password-file=/etc/rsync.pwd rsync_user@10.5.26.132::ftp /home/bak