rsync数据同步
1. 客户端脚本
#!/bin/bash
yum -y install rsync &>dev/null
echo "123456" > /etc/rsync.password
chmod 600 /etc/rsync.password
echo "ok ...."
测试:
2. 服务器端的脚本
#!/bin/bash
yum -y install rsync &>/dev/null
[ $? -eq 0 ] && echo "rsync install ok..."
systemctl start rsyncd &>/dev/null
systemctl enable rsyncd &>/dev/null
#配置文件
cat > /etc/rsyncd.conf <<EOF
uid = rsync
gid = rsync
port = 873
fake super = yes
use chroot = no
max connections = 200
timeout = 300
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 = 172.16.1.0/24
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password
[backup]
comment = "backup dir by yq"
path =/backup
EOF
#创建虚拟用户
useradd rsync -M -s /sbin/nologin
#创建备份服务器的密码
echo "rsync_backup:123456" > /etc/rsync.password
chmod 600 /etc/rsync.password
#创建备份目录
mkdir -p /backup
chown -R rsync.rsync /backup
systemctl restart rsyncd &>/dev/null
[ $? -eq 0 ] && echo "restart is ok ... "
测试:
rsync -avz /etc/hosts rsync_backup@192.168.80.31::backup --password-file=/etc/rsync.password
3. sersync2自动的数据同步
下载压缩包:https://pan.baidu.com/s/1PtOlqdFgOzqhWDCse-6fHA
链接:https://pan.baidu.com/s/1PtOlqdFgOzqhWDCse-6fHA
提取码:8dda
rz -E
tar xf
mv .. sersync
mv sersync /usr/local/
cd /usr/local/sersync
vim confxml.xml
wath | 客户端的要进行数据同步的目录 |
---|---|
ip | 备份服务器的ip地址,可以是内网 ,这里可以配置多个 |
name | rsync里边的模块 |
params | rsync的传输方式az就可以 |
start | true启动 |
user | rsync的密码文件的用户 |
password | 密码文件的位置 |
port | 默认端口号874,改为true与rsync的配置文件一致 |
time | 连接时间,超时 |
<sersync>
<localpath watch="/data">
<remote ip="192.168.80.31" name="backup"/>
<!--<remote ip="192.168.8.39" name="tongbu"/>-->
<!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
<rsync>
<commonParams params="-artuz"/>
<auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/>
<userDefinedPort start="false" port="873"/><!-- port=874 -->
<timeout start="true" time="100"/><!-- timeout=100 -->
<ssh start="false"/>
</rsync>
启动
cp /usr/local/sersync/sersync2 /usr/bin
启动
sersync2 -dro /usr/loacl/sersync/confxml.xml
关闭
ps -ef | grep sersync2
kill -9