Rsync部署环境1、服务器准备| Host | IP | ----------|| Server | 192.168.60.110 | ----------|| client | 192.168.60.80 | ----------|
2、Server 2.1、ubuntu ?16.04默认已安装rsync,直接修改它的配置文件即可。
sudo vim /etc/default/rsync
RSYNC_ENABLE=true #false改true
3、修改配置文件3.1、 rsync佩在文件默认在/usr/share/doc/rsync/examples/下,需要手动将配置文件拷贝到/etc目录下,sudo cp /usr/share/doc/rsync/examples/rsyncd.conf /etc 3.2、修改conf配置文件。sudo vim /etc/rsyncd.conf
#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.
#The init.d script does its own pid file handling,
#so omit the "pid file" line completely in that case.
pid file=/var/run/rsyncd.pid
syslog facility=daemon
#socket options=
#MODULE OPTIONS
[ftp]
comment = public archive
path = /home/zy/ftp
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 = liu_rsync
secrets file = /etc/rsyncd.secrets
strict modes = yes
hosts allow = 192.168.60.110
#hosts deny =
ignore errors = no
ignore nonreadable = yes
transfer logging = no
#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
4、创建一个密码文件vim /etc/rsyncd.pwd内容为:rsync:123sudo chmod 0600 /etc/rsyncd.pwd5、启动rsyncsudo /etc/init.d/rsync start如果启动成功,那么server端酒配置成功了。
Client1、客户端不需要进行特殊的配置,直接同步即可rsync -vzrtopg --progress rsync@192.168.60.80::my_rsync_bk . 1.1、此时rsync只能将Server端现有的数据同步下来,如果Server新添加数据却不能同步下来,这有点难受。1.2、所以需要创建一个密码文件(和server端做免密钥也可以的)sudo vim /etc/rsync.pwd输入123 #密码要一致sudo chmod 0600 /etc/rsync.pwdsudo chown 普通用户:普通用户组 /etc/rsync.pwd1.3、自动执行:命令行终端输入:crontab -e 添加以下内容,/1 rsync -a --password-file=/etc/rsync.pwd rsync@192.168.60.80::my_rsync_bk /data//1 为一分钟同步一次 只要Server端添加了新文件、1分钟内就会自动同步到客户端。1.5、删除文件需要同步 需要添加 --delete 参数 /1 * rsync -a --password-file=/etc/rsync.pwd --delete rsync@192.168.60.80::my_rsync_bk /data/rsync同步配置完成
一、从本地同步文件到远程服务器rsync -avz /home/ftp root@192.168.6.8:home/ftp 二、将远程服务器的文件同步到本地crontab -ersync -avz root@192.168.6.8:home/ftp /home/ftp
远程PC同步到本地PC.每十分钟执行一次
rsync-a --delete root@192.168.6.8:/home/ftp /home/s*2/4/zy sleep 10; rsync-a --delete root@192.168.6.8:/home/ftp /home/s*2/4/zy sleep 20; rsync-a --delete root@192.168.6.8:/home/ftp home/s*2/4/zy sleep 40; rsync-a --delete root@192.168.6.8:/home/ftp home/s*2/4/zy sleep 50; rsync-a --delete root@192.168.6.8:/home/ftp /home/s*2/4/zy