一、rsync+sersync实时同步数据
连接上边的nextcloud私人网盘搭建
IP | 服务 | 端口 |
192.168.1.134 | Sersync | |
192.168.1.150 | Rsync | 873 |
先关闭防火墙与SELinux
服务端部署(150)
1.检查软件是否安装
rpm -qa rsync
yum install -y rsync
2.编写配置文件(先做的工作)
vim /etc/rsyncd.conf
uid=root
gid=root
max connections=36000
use chroot=no
log file=/var/log/rsyncd.log
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock
[backup]
path=/u01/nextcloud/data/
comment = backup nextcloud
ignore errors
read only = no
hosts allow = 192.168.1.134/24
hosts deny = *
3.创建备份目录
mkdir /u01/nextcloud/data/ -p
4.创建认证密码文件
echo "rsync_backup:aiyouwei" >/etc/rsync.password
chmod 600 /etc/rsync.password
(umask 077;echo "rsync_backup:oldboy123" >/etc/rsync.password)
5.启动rsync守护进程
rsync --daemon
6.添加到开机自启动
vim /etc/rc.local
rsync –daemon
客户端部署(134)
1.创建认证密码文件,并进行授权
echo "aiyouwei" >/etc/rsync.password
chmod 600 /etc/rsync.password
2.进行免交互传输文件测试
touch /tmp/test.txt
rsync -avz /tmp/test.txt rsync_backup@192.168.1.150::backup --password-file=/etc/rsync.password
二、sersync安装配置(134)
1.安装包已上传百度网盘
链接:https://pan.baidu.com/s/1DUQPNVPdP0Dmtr6PjHax3A 密码:4hd4
2.下载安装包上传到
/usr/local/src
3.解压
unzip sersync_installdir_64bit.zip
4.移动目录
cd sersync_installdir_64bit/sersync
mv sersync_installdir_64bit/sersync/ ./../sersync
5.授权
cd /usr/local/sersync/bin/
chmod +x sersync
6.修改配置文件
vim /usr/local/sersync/conf/confxml.xml
7.设置sersync检查脚本
mkdir -p /home/crontab/
vim check_sersync.sh
chmod +x check_sersync.sh
#!/bin/sh
sersync="/usr/local/sersync/bin/sersync"
confxml="/usr/local/sersync/conf/confxml.xml"
status=$(psaux |grep 'sersync2'|grep -v 'grep'|wc -l)
if [$status -eq 0 ];
then
$sersync -d-r -o $confxml &
else
exit 0;
fi
8.设置定时任务
crontab -e
# 检查sersync是否运行
*/5 * * * * /bin/bash /home/crontab/check_sersync.sh >/dev/null 2>&1
9.加入到开机自启动
Vim /etc/rc.local
/usr/bin/rsync --daemon
/usr/local/sersync/bin/sersync -d -r -o /usr/local/sersync/confxml.xml
10.验证
在134上的同步目录下创建文件,到150上查看是否存在