CentOS7通过rsync+crontab实现两台服务器文件同步

centos7系统中已经默认安装rsync

1:主服务器配置

(1)修改rsyncd.conf 配置文件

[root@localhost app]# vi /etc/rsyncd.conf
motd file = /etc/rsyncd.motd
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
port = 873
address = 192.168.0.24
uid = wzh
gid = wzh
use chroot = no
read only = no
max connections = 10
timeout = 900
ignore nonreadable = yes

[common]
comment = rsync data
path = /data/imgs/
ignore errors
auth users = wzh
secrets file = /etc/rsyncd.secrets
hosts allow = 192.168.0.0/255.255.255.0
hosts deny = *
list = false

(2)创建用户密码

echo "wzh:wzh" > /etc/rsyncd.secrets
chmod 600 /etc/rsyncd.secrets

(3)创建提示信息文件

echo "rsync data" > /etc/rsyncd.motd

 (4)配置防火墙

firewall-cmd --zone=public --add-port=873/tcp --permanent
firewall-cmd --reload

(5)启动服务

rsync --daemon
echo "rsync --daemon" >> /etc/rc.local

 2:备服务器配置

(1)创建密码文件

echo "wzh" > /home/wzh/passwd
chmod 600 /home/wzh/passwd

(2)拉取

[wzh@localhost ~]$ rsync -avz --password-file=/home/wzh/passwd wzh@192.168.0.24::common /data/imgs/
rsync data

receiving incremental file list
./

sent 58 bytes received 121 bytes 358.00 bytes/sec
total size is 0 speedup is 0.00

 (3)将命令加入到定时任务中,每1分钟执行同步一次


$ vi /home/wzh/rsync_data_imgs.sh

#!/bin/bash
rsync -avz --password-file=/home/wzh/passwd wzh@192.168.0.24::common /data/imgs/ > /dev/null 2>&1 &

$ crontab -e
*/1 * * * * /home/wzh/rsync_data_imgs.sh

$ crontab -l

 

转载于:https://www.cnblogs.com/yshyee/p/10716521.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值