说明:系统环境CentOS release 6.5 (Final)  2.6.32-431.el6.x86_64

rsync server:配置步骤


1、vi /etc/rsyncd.conf

#Rsync server

#created by lijianfeng 18:26 2017-9-24

#rsyncd.conf start#

uid = rsync

gid = rsync

use chroot = no

max connections = 2000

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 = true

hosts allow = 172.16.1.0/24

#hosts deny = 0.0.0.0/32

auth users = rsync_backup

secrets file = /etc/rsync.password

################################################

[backup]

comment = backup by lijianfeng  18:29 2017-09-24

path = /backup

2、创建rsync用户,共享目录/backup

useradd rsync -s /sbin/nologin -M

id rsync

mkdir /backup

chown -R rsync /backup/

3、创建密码文件

echo "rsync_backup:oldboy" >/etc/rsync.password

chmod 600 /etc/rsync.password

cat /etc/rsync.password


4、启动服务并加入开机自启动rsync --daemon

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

rsync --daemon

netstat -lntup|grep rsync

ps -ef|grep rsync|grep -v grep

5、关闭防火墙

/etc/init.d/iptables  stop

ntpdate time.nist.gov

6、关闭SELINUX


rsync客户端配置

1、创建密码文件

echo "oldboy" >/etc/rsync.password

chmod 600 /etc/rsync.password

ls -l /etc/rsync.password

cat /etc/rsync.password

2、关闭防火墙,关闭SELINUX

/etc/init.d/iptables  stop

ntpdate time.nist.gov

3、定时执行同步命令push:

备份脚本

mkdir  /server/scripts -p

cd /server/scripts 

vim rsync_client.sh


#!/bin/sh

path=/backup

dir="`ifconfig eth0|awk -F '[ :]+' 'NR==2 {print $4}'`_$(date +%F)"

mkdir $path/$dir -p &&\

/bin/cp /var/spool/cron/root $path/$dir/cron_root_$(date +%F) &&\

/bin/cp /etc/rc.local /$path/$dir/rc.local_$(date +%F)

rsync -az $path/ rsync_backup@172.16.1.5::backup  --password-file=/etc/rsync.password


说明:全路径试运行脚本

/bin/sh /server/scripts/rsync_client.sh


定时任务每天19:00执行脚本rsync_client.sh

crontab -e


############time sync by lijianfeng at 2017-09-27


*/5 * * * *  /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1

############################Rsync backup#################

00 19 * * *  /bin/sh /server/scripts/rsync_client.sh >/dev/null 2>&1