一、环境部署
一台做rsync的备份源
一台做rsync的发起端
二、在备份端配置配置文件
- 首先查看软件是否安装
rpm -qa rsync
rsync-3.1.2-6.el7_6.1.x86_64
- 配置配置文件
vim /etc/rsyncd.conf
uid = nobody
gid = nobody
use chroot = yes
address = 192.168.200.113 #监控地址,监控本机地址
port = 873 #监听的端口
log file = /var/log/rsyncd.log #日志文件位置
pid file = /var/run/rsyncd.pid #pid文件位置
hosts allow = 192.168.200.0/24 #授权那些IP地址可以访问
[ftp] #共享目录名
path = /data #共享目录位置
read only = yes #只读模式
dont compress = *.gz *.bz2 *.zip #设置那些文件不用压缩
auth users = backuper #设置访问使得用户名
secrets file = /etc/rsyncd_user.db #设置用户名和密码文件的存放位置
用户名密码存放文件
vim /etc/rsyncd.conf
backuper:pwd123
- 重启rsync服务
rsync --daemon
注:如果重启的话,要先删除pid文件
三、在发起端测试
rsync -avz backuper@192.168.200.113::ftp /data
Password:
receiving incremental file list
sent 20 bytes received 215 bytes 15.16 bytes/sec
total size is 0 speedup is 0.00
四、编写rsync启停脚本
cat /etc/init.d/rsyncd
#!/bin/bash
#rsync启停服务脚本
start(){
/usr/bin/rsync --daemon
}
stop(){
killall -9 rsync &> /dev/null
}
status(){
netstat -lnupt |grep -q :873
if [ $? -eq 0 ];then
echo "Rsyncd is running"
else
echo "Rsyncd is dead"
fi
}
case $1 in
"start")
start
;;"stop")
stop
;;"restart"|"reload")
stop
sleep 2
rm -fr /var/run/rsyncd.pid
start
;;"status")
status
;;*)
echo "用法:{start|stop|restart|reload}"
esac
四、解决客户端在下载时需要手动输入密码的问题
- 方式一
#声明全局变量
export RSYNC_PASSWORD=密码
- 方式二
vim /etc/rsync.pwd
密码
--------------------------
chmod 600 /etc/rsync.pwd
#同步时加入 --password-file=/etc/rsync.pwd