rsync是开源、高速的、可实现本地以及远程,全量以及增量的数据复制(拷贝)工具。
服务端配置
1.关闭防火墙
systemc stop firewalld
systemc disable firewalld
setenforce 0
2.关闭selinux
vim /etc/selinux/config
SELINUX=disabled
3.rsync服务端配置详解(web01“ip 10.160.1.15”)
(1)rsync配置文件详解
cat /etc/rsyncd.conf
rsync_config_______________start
uid = rsync
gid = rsync
use chroot = no
fake super = yes
max connections = 200
timeout = 600
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = false
hosts allow = 10.160.1.0/24
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password
[date]
comment = welcome to oldboyedu backup!
path = /date/
(2)创建rsync目录和用户
mkdir /date
useradd rsync
chown -R rsync:rsync
(3)配置rsync密码文件
cat /etc/rsync.password
rsync_backup:oldboy
chmod 600 /etc/rsync.password
4.配置rsync客户端(web02)
配置rsync密码认证文件
方法一:
cat /etc/rsync.password
oldboy
chmod 600 /etc/rsync.password
方法二:
echo ' export RSYNC_PASSWORD=oldboy' >>/etc/bashrc
. /etc/bashrc
5.生产案例
每天晚上00点整在web服务器A(web02)上打包备份网站程序目录并通过rsync命令推送到服务器B(web01)上备份保留(备份思路可以是先在本地按日期大包,然后再利用rsync推到备份服务器上)
web01脚本
cat /scripts/rsync.sh
!/bin/bash
backup conf and /etc/hosts
mkdir /date/html_(date +%F)/html_$(date +%F -d "-1day").tar.gz hosts
md5
mkdir /date/md5sum_(date +%F)/hosts_md5_$(date +%F)
rsync
rsync -avz /date/ rsync_backup@10.160.1.15::date --password-file=/etc/rsync.password
web01 定时任务
- 0 * * * /usr/bin/sh /scripts/rsync.sh &>/dev/null