rsync 同步  A主服务器192.168.1.4   B备用服务器192.168.1.5   把A的web目录同步到B 的web 目录

A:

新建 rsync.conf    server.pas 

vi /etc/rsync.conf

 

uid = root

gid = root

use chroot = no

hosts allow =192.168.1.5

max connections = 10

pid file = /var/run/rsyncd.pid

lock file = /var/run/rsync.lock

log file = /var/log/rsyncd.log

[web]

path =/opt/web

comment = dwg file

ignore errors

read only = true

list = false

auth users = user1

secrets file = /etc/server.pas

 

vi /etc/server.pas   同步帐号密码文件

user1:backMe3uFdHS

chmod 600 /etc/server.pas   (注意这个必须是600的权限)

然后启动rsync服务,以守护进程的方式启动 

rsync --daemon

B:vi  /etc/password.pas    新建密码文件  

 backMe3uFdHS

   vi /root/shell/rsync.sh   新建同步脚本

   rsync -vzrt -u --delete --progress --password-file=/etc/password.pas user1@192.168.1.4::web /opt/web

   给执行权限 chmod o+x /root/shell/rsync.sh

启动rsync服务

rsync --daemon

然后添加到自动任务

crontab  -e 

01 18 * * * /root/shell/rsync.sh   (每天18点01分执行同步,这个时间看自己的需要设置)

OK 完成配置