Sersync是利用Inotify和Rsync技术实现的对服务器数据实时同步的解决方案

需求逻辑图

安装环境

角色 服务器配置 操作系统版本 IP地址 机器名
Sersync服务 VM CentOS 6.10(2.6.32-754.3.5.el6) 2.2.2.5 C64-5-S
Rsync服务 VM CentOS 6.10(2.6.32-754.3.5.el6) 2.2.2.6 C64-6-B
Rsync服务 VM CentOS 6.10(2.6.32-754.3.5.el6) 2.2.2.7 C64-7-C

配置服务

1.在Server端部署rsync服务

因为我们要把文件从Server同步到奥Client端,所以这里需要在Client端配置rsync的守护进程

首先在Client端编写rsync守护进程的配置文件

cat>/etc/rsyncd.conf<<EOF
#Create by Pual
uid = root
gid = root
use chroot = no
max conntions = 2000
timeout = 600
pid file = /var/run/rsyncd.pid
lock filr = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = false
hosts allow = 2.2.2.0/24
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync_s.password
[syner]
path = /home/syner
comment = syner by paul 2018
EOF
[root@C64-6-B ~]# less /etc/rsyncd.conf
#Rsync server
#Create by Pual
uid = root
gid = root
use chroot = no
max conntions = 2000
timeout = 600
pid file = /var/run/rsyncd.pid
lock filr = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = false
hosts allow = 2.2.2.0/24
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync_s.password
[syner]
path = /home/syner
comment = syner by paul 2018
[root@C64-7-C ~]# less /etc/rsyncd.conf
#Create by Pual
uid = root
gid = root
use chroot = no
max conntions = 2000
timeout = 600
pid file = /var/run/rsyncd.pid
lock filr = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = false
hosts allow = 2.2.2.0/24
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync_s.password
[syner]
path = /home/syner
comment = syner by paul 2018

配置密码文件

echo "rsync_backup:syner">>/etc/rsync_s.password
chmod 600 /etc/rsync_s.password
[root@C64-6-B ~]# echo "rsync_backup:syner">>/etc/rsync_s.password
[root@C64-6-B ~]# less /etc/rsync_s.password
rsync_backup:syner
[root@C64-6-B ~]# chmod 600 /etc/rsync_s.password
[root@C64-6-B ~]# ll /etc/rsync_s.password
-rw------- 1 root root 25 Sep 26 15:07 /etc/rsync_s.password
[root@C64-7-C ~]# echo "rsync_backup:syner">>/etc/rsync_s.password
[root@C64-7-C ~]# less /etc/rsync_s.password
rsync_backup:syner
[root@C64-7-C ~]# chmod 600 /etc/rsync_s.password
[root@C64-7-C ~]# ll /etc/rsync_s.password
-rw------- 1 root root 19 Sep 26 15:09 /etc/rsync_s.password

启动rsync守护进程

rsync --daemon
[root@C64-6-B ~]# rsync --daemon[root@C64-6-B ~]# ps -ef | grep rsync|grep -v grep
root     27202     1  0 15:31 ?        00:00:00 rsync --daemon[root@C64-6-B ~]# netstat -lnt | grep 873
tcp        0      0 0.0.0.0:873                 0.0.0.0:*                   LISTEN
tcp        0      0 :::873                      :::*                        LISTEN      [root@C64-6-B ~]# lsof -i:873
COMMAND   PID USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
rsync   27202 root    3u  IPv4 3887958      0t0  TCP *:rsync (LISTEN)
rsync   27202 root    5u  IPv6 3887959      0t0  TCP *:rsync (LISTEN)
[root@C64-7-C ~]# rsync --daemon[root@C64-7-C ~]# ps -ef | grep rsync| grep -v grep
root      4312     1  0 15:32 ?        00:00:00 rsync --daemon[root@C64-7-C ~]# netstat -lnt | grep 873
tcp        0      0 0.0.0.0:873                 0.0.0.0:*                   LISTEN
tcp        0      0 :::873                      :::*                        LISTEN   [root@C64-7-C ~]# lsof -i:873
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
rsync   4312 root    3u  IPv4  23469      0t0  TCP *:rsync (LISTEN)
rsync   4312 root    5u  IPv6  23470      0t0  TCP *:rsync (LISTEN)

添加到开机自启动服务中

which rsync
echo "/usr/bin/rsync --daemon">>/etc/rc.local
[root@C64-6-B ~]# which rsync
/usr/bin/rsync[root@C64-6-B ~]# echo "/usr/bin/rsync --daemon">>/etc/rc.local
[root@C64-6-B ~]# grep daemon /etc/rc.local
/usr/bin/rsync --daemon
[root@C64-7-C ~]# which rsync
/usr/bin/rsync[root@C64-7-C ~]# echo "/usr/bin/rsync --daemon">>/etc/rc.local
[root@C64-7-C ~]# grep daemon /etc/rc.local
/usr/bin/rsync --daemon

2.在client端配置rsync

echo "syner">>/etc/rsync_c.password
chmod 600 /etc/rsync_c.password
cat /etc/rsync_c.password
ll /etc/rsync_c.password 
[root@C64-5-S ~]# echo "syner">>/etc/rsync_c.password
[root@C64-5-S ~]# chmod 600 /etc/rsync_c.password
[root@C64-5-S ~]# cat /etc/rsync_c.password
syner
[root@C64-5-S ~]# ll /etc/rsync_c.password
-rw------- 1 root root 25 Sep 26 15:49 /etc/rsync_c.password

3.测试rsync

rsync -avzP ./data1.txt rsync_backup@2.2.2.6::syner --password-file=/etc/rsync_c.password
rsync -avzP ./data1.txt rsync_backup@2.2.2.7::syner --password-file=/etc/rsync_c.password 
[root@C64-5-S syner]# rsync -avzP ./data1.txt rsync_backup@2.2.2.6::syner --password-file=/etc/rsync_c.password
sending incremental file list
data1.txt10240 100%    0.00kB/s    0:00:00 (xfer#1, to-check=0/1)sent 110 bytes  received 27 bytes  91.33 bytes/sec
total size is 10240  speedup is 74.74
[root@C64-5-S syner]# rsync -avzP ./data1.txt rsync_backup@2.2.2.7::syner --password-file=/etc/rsync_c.password
sending incremental file list
data1.txt10240 100%    0.00kB/s    0:00:00 (xfer#1, to-check=0/1)sent 110 bytes  received 27 bytes  91.33 bytes/sec
total size is 10240  speedup is 74.74

检查是否同步过去了

[root@C64-6-B syner]# ll /home/syner/| grep data1.txt
-rw-rw-r-- 1 syner syner   10240 Sep 25 21:01 data1.txt
[root@C64-7-C ~]# ll /home/syner/| grep data1.txt
-rw-rw-r-- 1 syner syner 10240 Sep 25 21:01 data1.txt

4.安装Sersync

wget --no-check-certificate https://raw.githubusercontent.com/orangle/sersync/master/release/sersync2.5.4_64bit_binary_stable_final.tar.gz
tar zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz 

规范目录名称

mv GNU-Linux-x86/ sersync
cd sersync
mkdir conf bin log backup
mv confxml.xml conf
mv sersync2 bin/sersync
tree
[root@C64-5-S tool]# cd sersync
[root@C64-5-S sersync]# mkdir conf bin log backup
[root@C64-5-S sersync]# mv confxml.xml conf
[root@C64-5-S sersync]# mv sersync2 bin/sersync
[root@C64-5-S sersync]# tree
.
├── backup
├── bin
│   └── sersync
├── conf
│   └── confxml.xml
└── log4 directories, 2 files

5.配置Sersync

备份配置文件

/bin/cp conf/confxml.xml backup/confxml.xml.bak.$(date +%F)
[root@C64-5-S sersync]# /bin/cp conf/confxml.xml backup/confxml.xml.bak.$(date +%F)
[root@C64-5-S sersync]# ll backup
total 4
-rwxr-xr-x 1 root root 2214 Sep 26 20:51 confxml.xml.bak.2018-09-26

更改配置文件

     24   <localpath watch="/home/syner">25       <remote ip="2.2.2.6" name="syner"/>26       <remote ip="2.2.2.7" name="syner"/>27   </localpath>
     28   <rsync>29       <commonParams params="-aruz"/>30       <auth start="true" users="rsync_backup" passwordfile="/etc/rsync_c.password"/>31       <userDefinedPort start="false" port="874"/><!-- port=874 -->32       <timeout start="false" time="100"/><!-- timeout=100 -->33       <ssh start="false"/>34   </rsync>
35   <failLog path="/home/syner/tool/sersync/log/rsync_fail_log.sh" timeToExecute="60"/><        !--default every 60mins execute once-->

6.开启Sersync守护进程同步数据

echo 'export PATH=$PATH:/home/syner/tool/sersync/bin'>>/etc/profile
tail -1 /etc/profile
source /etc/profile
which sersync
[root@C64-5-S ~]# echo 'export PATH=$PATH:/home/syner/tool/sersync/bin'>>/etc/profile
[root@C64-5-S ~]# tail -1 /etc/profile
export PATH=$PATH:/home/syner/tool/sersync/bin
[root@C64-5-S ~]# source /etc/profile
[root@C64-5-S ~]# which sersync
/home/syner/tool/sersync/bin/sersync
sersync -rdo /home/syner/tool/sersync/conf/confxml.xml 
[root@C64-5-S ~]# sersync -rdo /home/syner/tool/sersync/conf/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: -r      rsync all the local files to the remote servers before the sersync work
option: -d      run as a daemon
option: -o      config xml name:  /home/syner/tool/sersync/conf/confxml.xml
daemon thread num: 10
parse xml config file
host ip : localhost     host port: 8008
daemon start,sersync run behind the console
use rsync password-file :
user is rsync_backup
passwordfile is         /etc/rsync_c.password
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: 32 = 12(Thread pool nums) + 20(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 /home/syner && rsync -aruz -R --delete ./ rsync_backup@2.2.2.6::syner --password-file=/etc/rsync_c.password >/dev/null 2>&1 

这时我们发现B、C客户端机器的syner目录已经被同步了

[syner@C64-6-B ~]$ ll
total 4040
-rw-rw-r-- 1 syner syner   10240 Sep 25 21:01 data1.txt
-rw-rw-r-- 1 syner syner   30720 Sep 25 21:01 data2.txt
-rw-rw-r-- 1 syner syner   51200 Sep 25 21:01 data3.txt
-rw-r--r-- 1 syner syner     230 Sep 25 17:08 inotify.log
-rw-r--r-- 1 root  root        0 Sep 25 15:11 inotify.txt
drwxrwxr-x 2 syner syner 4022272 Sep 25 21:25 r_inotify
-rw-rw-r-- 1 syner syner      17 Sep 25 16:58 s_inotify
-rw-rw-r-- 1 syner syner       0 Sep 25 16:26 s_test.txt
-rw-rw-r-- 1 syner syner       0 Sep 26 16:28 syner
-rw-rw-r-- 1 syner syner       0 Sep 26 15:54 test_rsync.dat
drwxrwxr-x 3 syner syner    4096 Sep 26 17:36 tool
[syner@C64-7-C ~]$ ll
total 1636
-rw-rw-r-- 1 syner syner   10240 Sep 25 21:01 data1.txt
-rw-rw-r-- 1 syner syner   30720 Sep 25 21:01 data2.txt
-rw-rw-r-- 1 syner syner   51200 Sep 25 21:01 data3.txt
-rw-r--r-- 1 syner syner     230 Sep 25 17:08 inotify.log
-rw-r--r-- 1 root  root        0 Sep 25 15:11 inotify.txt
drwxrwxr-x 2 syner syner 1560576 Sep 26 21:15 r_inotify
-rw-rw-r-- 1 syner syner      17 Sep 25 16:58 s_inotify
-rw-rw-r-- 1 syner syner       0 Sep 25 16:26 s_test.txt
-rw-rw-r-- 1 syner syner       0 Sep 26 16:28 syner
-rw-rw-r-- 1 syner syner       0 Sep 26 15:54 test_rsync.dat
drwx------ 2 root  root     4096 Sep 26 21:14 tool

将命令加到rc.local中,开机自启动

cat >>/etc/rc.local<<EOF
sersync -do /home/syner/tool/sersync/conf/confxml.xml
EOF
[root@C64-5-S conf]# cat >>/etc/rc.local<<EOF
> sersync -do /home/syner/tool/sersync/conf/confxml.xml
> EOF
[root@C64-5-S conf]# less /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.touch /var/lock/subsys/local
#NFS and RPC services config by test 20180910
/etc/init.d/rpcbind start
/etc/init.d/nfs start
/usr/bin/rsync --daemon
sersync -do /home/syner/tool/sersync/conf/confxml.xml 

Linux-14-Sersync相关推荐

  1. Slackware Linux 14.0 RC5 发布

    Slackware Linux 发布 14.0 RC5 版本,下载地址: slackware-current-install-dvd.iso (2,320MB, MD5) slackware64-cu ...

  2. linux 14.04安装方法,Ubuntu 14.04 安装配置GNOME经典界面

    Ubuntu 14.04上基本完美支持GNOME经典界面,安装配置步骤如下: 1. 安装gnome-session-flashback sudo apt-get install gnome-sessi ...

  3. Linux(14)-正则表达式

    正则表达式 demo1:在某个文件中寻找命令sed demo2:寻找8位电话号码 正则表达式:用来描述或者匹配某一系列符合某个句法队则的字符串或者单个字符串. 最初正则表达式,出现在自动控制理论和形式 ...

  4. linux 14.04 lts eclipse c++,Ubuntu 14.04下安装eclipse搭建C++开发环境

    安装过程分为两部分:1.JAVA开发环境,即JDK的安装:2.eclipse的安装: 一.安装包下载 1.JDK官网下载地址: http://www.oracle.com/technetwork/ja ...

  5. linux 14.04 最新源,ubuntu14.04 trusty的源在此奉上

    #-------------------ubuntu14.04 trusty(上海交通大学)--------------------------# deb http://ftp.sjtu.edu.cn ...

  6. linux 14.04安装qt5.9,Ubuntu20.04安装Qt5.9.9+Qt creator

    官网下载Qt4.99版本安装包 进入安装界面 一直点击下一步直到选择插件 选择插件 安装直至安装完毕 打开终端 输入命令 sudo gedit /usr/bin/qtcreator 插入以下内容并保存 ...

  7. sersync+rsync实现实时同步

    在分布式应用中会遇到一个问题,就是多个服务器间的文件如何能始终保持一致.一种经典的办法是将需要保持一致的文件存储在NFS上,这种方法虽然简单方便但却将本来多点的应用在文件存储上又变成了单点,这违背了分 ...

  8. Symantec Backup Exec 2012 Agent For Linux安装

    Backup Exec 2012 介绍 Backup Exec 2012 是一种为虚拟和物理环境提供保护的集成产品,能够简化备份和灾难恢复,并提供了无可匹敌的恢复功能.借助于强大的 Symantec ...

  9. 超级计算机性能调查,调查:多数超级计算机使用Linux操作系统

    过去,开发人员为超级计算机定制各种各样的操作系统,超级计算机在操作系统的使用上没有形成统一规定.近年来,这种情况有所改变.Linux系统越来越受欢迎,被很多超级计算机采用.但Linux在超级计算机中究 ...

  10. linux 基础命令总结

    1.mkdir 创建目录 -p 创建多级目录 mkdir -p /data/test -m, --mode=模式 设置权限模式(类似chmod),而不是rwxrwxrwx 减umask -p, --p ...

最新文章

  1. centreon问题总结
  2. 小而美的个人博客——前端——tags
  3. python程序语法元素分析_Python程序语法元素分析(2)
  4. 爆款互联网人, 28岁的财富自由?
  5. 【通知】2020年有三AI-CV夏季划升级,更多项目,更高难度,更加落地
  6. 效果过度transition:all
  7. 57.Linux/Unix 系统编程手册(下) -- SOCKET : Unix domain
  8. ubuntu开机启动+图标配置
  9. 使用boost中的线程池
  10. 【ceph】vdbench的使用教程——裸盘测试和文件系统测试vdbanch
  11. 操作系统进程调度算法总结
  12. SPSS基本数据处理(一)
  13. 冰点下载器手机版apk_冰点文库下载器下载|冰点文库下载器手机版安卓版 3.1.7_ - 极光下载站...
  14. python实现ddos防护_python实现的防DDoS脚本
  15. 如何把pdf拆分成一页一页的图片?
  16. 如何实现在 Vue 中嵌入代码编辑器 ?
  17. Linux运维笔记-日常操作命令总结(1)
  18. 如何在Ubuntu 20.04上安装和使用TimescaleDB
  19. python 视频下载中国大学慕课_下载视频
  20. 10个预训练模型开始你的深度学习(计算机视觉部分)

热门文章

  1. java中如何输入名字配对情侣网名_好听的英文情侣昵称配对 亲密备注就用它
  2. C语言【求最大公约数、最小公倍数】详解
  3. @Html.DropDownListFor 下拉框绑定(选择默认值)
  4. java的向下转型_浅谈Java向下转型的意义
  5. 软件测试工程师-CSS
  6. HDU 4081 最小生成树(或者次小生成树)
  7. 2、pr的转场效果(切换、过渡)
  8. Map接口以及Collections工具类
  9. 2020和2021外贸行业出路?
  10. easyui filebox 浏览图片(亲测有效)