linux实时同步工具sersync
版权声明:原创作品,请勿转载!
1.服务介绍
Sersync是一款开源的实时文件同步工具,主要用于服务器同步、web镜像等功能。可以保证数据的连续性, 减少人力维护成本,解决nfs单点故障
2.服务器规划
角色 | IP1 | IP2 | 主机名 | 安装软件 |
backup | 10.0.0.41/24 | 172.16.1.41/24 | backup | rsync |
NFSserver | 10.0.0.31/24 | 172.16.1.31/24 | nfs | sersync |
3.配置
3.1 nfs端操作
3.1.1 安装软件
[root@nfs01 ~]# yum install -y inotify-tools rsync
[root@nfs01 sersync]# wget https://raw.githubusercontent.com/wsgzao/sersync/master/sersync2.5.4_64bit_binary_stable_final.tar.gz
3.1.2 解压软件
[root@nfs01 sersync]# ll
total 712
-rw-r--r-- 1 root root 727290 Jun 24 01:22 sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@nfs01 sersync]# tar -xf sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@nfs01 sersync]# ll
total 712
drwxr-xr-x 2 root root 41 Oct 26 2011 GNU-Linux-x86
-rw-r--r-- 1 root root 727290 Jun 24 01:22 sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@nfs01 sersync]# mv GNU-Linux-x86/ sersync
[root@nfs01 sersync]# ll
total 712
drwxr-xr-x 2 root root 41 Oct 26 2011 sersync
-rw-r--r-- 1 root root 727290 Jun 24 01:22 sersync2.5.4_64bit_binary_stable_final.tar.gz
3.1.3 修改配置文件
[root@nfs01 sersync]# vim confxml.xml
[root@nfs01 sersync]# grep -E "createFile|localpath watch|remote ip|commonParams params|auth start|users" confxml.xml<createFile start="true"/><localpath watch="/data"><remote ip="172.16.1.41" name="data"/><commonParams params="-avz"/><auth start="true" users="rsync_backup" passwordfile="/etc/rsync.pas"/>
3.1.4 创建密码文件并授权
[root@nfs01 sersync]# echo 123456 > /etc/rsync.pas
[root@nfs01 sersync]# chmod 600 /etc/rsync.pas
[root@nfs01 sersync]# ll -R /etc/rsync.pas
-rw------- 1 root root 7 Jun 24 22:01 /etc/rsync.pas
3.1.5 启动sersync守护进程
[root@nfs01 sersync]# /sersync/sersync/sersync2 -dro /sersync/sersync/confxml.xml
set the system param
execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches
execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events
parse the command param
option: -d run as a daemon
option: -r rsync all the local files to the remote servers before the sersync work
option: -o config xml name: /sersync/sersync/confxml.xml
daemon thread num: 10
parse xml config file
host ip : localhost host port: 8008
will ignore the inotify createFile event
daemon start,sersync run behind the console
use rsync password-file :
user is rsync_backup
passwordfile is /etc/rsync.pas
config xml parse success
please set /etc/rsyncd.conf max connections=0 Manually
sersync working thread 12 = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads)
Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads)
please according your cpu ,use -n param to adjust the cpu rate
------------------------------------------
rsync the directory recursivly to the remote servers once
working please wait...
execute command: cd /data && rsync -avz -R --delete ./ rsync_backup@172.16.1.41::data --password-file=/etc/rsync.pas >/dev/null 2>&1
run the sersync:
watch path is: /data
3.2 备份端
3.2.1 安装软件
[root@backup ~]# yum install -y rsync
3.2.2 修改配置文件
[root@backup ~]# vim /etc/rsyncd.conf
[root@backup ~]# cat /etc/rsyncd.conf
uid = rsync
gid = rsync
port = 873
fake super = yes
use chroot = no
max connections = 200
timeout = 600
ignore errors
read only = false
list = false
auth users = rsync_backup
secrets file = /etc/rsync.passwd
log file = /var/log/rsyncd.log
#####################################
[backup]
path = /backup
[data]
path = /data
3.2.3 建立对应密码文件并授权
[root@backup ~]# echo "rsync_backup:123456" > /etc/rsync.passwd
[root@backup ~]# chmod 600 /etc/rsync.passwd
3.2.4 创建对应同步目录并授权
[root@backup ~]# mkdir /data
[root@backup ~]# chown rsync.rsync /data
3.2.5 启动rsync
[root@backup ~]# systemctl start rsyncd
[root@backup ~]# systemctl enable rsyncd
4.测试
4.1 新建文件测试
[root@nfs01 sersync]# touch /data/3.txt
[root@nfs01 sersync]# ll /data
total 0
-rw-r--r-- 1 root root 0 Jun 24 22:26 3.txt[root@backup data]# ll
total 0
-rw-r--r-- 1 rsync rsync 0 Jun 24 2025 3.txt
4.2 删除文件测试
[root@nfs01 sersync]# touch /data/rm-test.txt
[root@nfs01 sersync]# ll /data
total 0
-rw-r--r-- 1 root root 0 Jun 24 22:26 3.txt
-rw-r--r-- 1 root root 0 Jun 24 22:28 rm-test.txt[root@backup data]# ll
total 0
-rw-r--r-- 1 rsync rsync 0 Jun 24 2025 3.txt
-rw-r--r-- 1 rsync rsync 0 Jun 24 2025 rm-test.txt[root@nfs01 sersync]# rm -f /data/rm-test.txt
[root@nfs01 sersync]# ll /data
total 0
-rw-r--r-- 1 root root 0 Jun 24 22:26 3.txt[root@backup data]# ll
total 0
-rw-r--r-- 1 rsync rsync 0 Jun 24 2025 3.txt
[root@backup data]#
实时同步服务就介绍到这里啦~