摘要:采用rsync实现
采用两台服务器,主服务器A,从服务器B 将数据从A同步到从属服务器B中
本次所有服务均在用户家目录 cd ~ 可直接进入
yum -y install rsync
ln -s /etc/rsync.conf
cp /etc/rsyncd.conf rsyncd.conf.back (备份一个,防止安装错误造成不可恢复的问题)
vim rsyncd.conf
# /etc/rsyncd: configuration file for rsync daemon mode
# See rsyncd.conf man page for more options.
# configuration example:
uid = root
gid = root
use chroot = yes
read only = no
list = no
max connections = 4
pid file = /var/run/rsyncd.pid
# exclude = lost+found/
# transfer logging = yes
timeout = 900
motd file = /etc/rsyncd/rsyncd.motd
log file = /var/log/rsyncd.log
lock file = /var/run/rsync.lock
# ignore nonreadable = yes
# dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
# 此处backup为对应模块名,从属服务器需要使用
[backup]
# path = /home/ftp
# comment = ftp export area
comment = this is module for backup sam
path = /www/wwroot/test.samaterials.com
ignore errors
auth users = root
secrets file = /etc/rsyncd.pass
echo "root:123" > /etc/rsyncd.pass
root为自定义用户名,123 自定义密码
chomd 600 /etc/rsyncd.pass
systemctl restart resyncd
netstat -tunlp
看到873 端口被占用,需要开放
yum -y install rsync
echo "123" > /etc/rsyncd/rsyncd.pass
1、进入A服务器
ssh-keygen -t dsa -b 1024
后面会让输入对应的密码名称,可以自定义,生成后会生成一个秘钥文件以及一个公钥文件,公钥后缀.pub
2、进入B服务器
将A服务器中获取的公钥文件.pub 复制到B服务器
赋值公钥信息到key中
cat /root/.ssh/id_dsa.pub >> authorized_keys
#!bin/bash
rsync -auv --password-file=/etc/rsyncd.pass root@64.202.187.175::backup /www/wwwroot/www.samaterials.com
bash rsyncd.sh
可以查看对应的信息,有错误会直接报出可以对应调整
crontab -l 查看当前任务
crontab -e 新增任务
30 21 * * * bash /etc/rsyncd.sh
每天的21点30 执行一次备份