4-综合-小规模全网实时同步

一,lsync实时同步

  1. 安装部署lsync实时同步工具
    yum install -y lsyncd

  2. 编写配置文件
    vim /etc/lsyncd.conf

settings {
logfile = "/var/log/lsyncd/lsyncd.log",
statusFile = "/var/log/lsyncd/lsyncd.status",
inotifyMode = "CloseWrite",
maxProcesses = 8,
}
sync {
default.rsync,
source = "/data",
target = "rsync_backup@172.16.1.41::backup",
delete= true,
exclude = { ".*" },
delay = 1,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true,
password_file = "/etc/rsync.password",
_extra = {"--bwlimit=200"}
}
}

  1. 启动服务
    systemctl start lsyncd
    https://www.jianshu.com/p/55922068567e

二,sersync软件二进制部署。

接收机上的操作:
Backup服务器

1)安装rsync
[root@backup ~]# yum install rsync -y

2)配置rsync

[root@backup ~]# cat /etc/rsyncd.conf
uid = www
gid = www
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]
comment = welcome to oldboyedu backup!
path = /backup

3)根据配置完成对应初始化操作

[root@backup ~]# groupadd -g 666 www
[root@backup ~]# useradd -u 666 -g666 www
[root@backup ~]# mkdir /backup /data
[root@backup ~]# chown -R www.www /backup/ /data/
[root@backup ~]# echo "rsync_backup:123456" > /etc/rsync.passwd   
[root@backup ~]# chmod 600 /etc/rsync.passwd

4)重启Rsync服务
[root@backup ~]# systemctl restart rsyncd

推送源机上的操作:
NFS服务器:

1.下载并解压sersync软件包

如果大家网络不好上不去git,这里下载好的sersync二进制软件包。
https://files.cnblogs.com/files/hypj/sersync2.5.4_64bit_binary_stable_final.tar.gz

[root@nfs ~]# tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@nfs ~]# mv GNU-Linux-x86/ /usr/local/sersync

2.配置confxml.xml

[root@localhost conf]# cat confxml.xml 
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
   # 设置本地IP和端口
   <host hostip="localhost" port="8008"></host>
   # 开启DUBUG模式  
   <debug start="false"/>
   # 开启xfs文件系统
   <fileSystem xfs="false"/>
   # 同步时忽略推送的文件(正则表达式),默认关闭
   <filter start="false">
       <exclude expression="(.*)\.svn"></exclude>
       <exclude expression="(.*)\.gz"></exclude>
       <exclude expression="^info/*"></exclude>
       <exclude expression="^static/*"></exclude>
   </filter>
   <inotify>
   # 设置要监控的事件
       <delete start="true"/>
       <createFolder start="true"/>
       <createFile start="true"/>
       <closeWrite start="true"/>
       <moveFrom start="true"/>
       <moveTo start="true"/>
       <attrib start="true"/>
       <modify start="true"/>
   </inotify>
   <sersync>
   # 本地同步的目录路径
       <localpath watch="/home/data">
   # 远程IP和rsync模块名 
           <remote ip="192.168.1.35" name="rsyncmysql"/>  
           <!--<remote ip="192.168.8.39" name="tongbu"/>-->
           <!--<remote ip="192.168.8.40" name="tongbu"/>-->
       </localpath>
       <rsync>
   # rsync指令参数
           <commonParams params="-auvzP"/>
   # rsync同步认证
           <auth start="true" users="rsync" passwordfile="/etc/rsync.pas"/>
   # 设置rsync远程服务端口,远程非默认端口则需打开自定义
           <userDefinedPort start="false" port="873"/><!-- port=874 -->
   # 设置超时时间
           <timeout start="true" time="100"/><!-- timeout=100 -->
   # 设置rsync+ssh加密传输模式,默认关闭,开启需设置SSH加密证书
           <ssh start="false"/>
       </rsync>
    # sersync传输失败日志脚本路径,每隔60会重新执行该脚本,执行完毕会自动清空。
       <failLog path="/usr/local/sersync/log/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
    # 设置rsync+crontab定时传输,默认关闭
       <crontab start="false" schedule="600"><!--600mins-->
           <crontabfilter start="false">
               <exclude expression="*.php"></exclude>
               <exclude expression="info/*"></exclude>
           </crontabfilter>
       </crontab>
   # 设置sersync传输后调用name指定的插件脚本,默认关闭
       <plugin start="false" name="command"/>
   </sersync>
   # 插件脚本范例
   <plugin name="command">
       <param prefix="/bin/sh" suffix="" ignoreError="true"/>  <!--prefix /opt/tongbu/mmm.sh suffix-->
       <filter start="false">
           <include expression="(.*)\.php"/>
           <include expression="(.*)\.sh"/>
       </filter>
   </plugin>
   # 插件脚本范例
   <plugin name="socket">
       <localpath watch="/opt/tongbu">
           <deshost ip="192.168.138.20" port="8009"/>
       </localpath>
   </plugin>
   <plugin name="refreshCDN">
       <localpath watch="/data0/htdocs/cms.xoyo.com/site/">
           <cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxx"/>
           <sendurl base="http://pic.xoyo.com/cms"/>
           <regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>
       </localpath>
   </plugin>
</head>

3.启动
[root@nfs ~]# /usr/local/sersync/sersync2 -h
[root@nfs ~]# /usr/local/sersync/sersync2 -dro /usr/local/sersync/confxml.xml

4.重启操作如下:
killall sersync2 && sersync2 -dro /usr/local/sersync/conf/confxml.xml
(ps 无法由systemctl启动,只能手动/脚本启停,pkill sersync2,sersync2 -dro /usr/bin/xxxxx
可以通过多个配置文件实现,不同目录的备份服务)

5.配置开机启动
`echo "rsync --daemon --config=/etc/rsyncd.conf" >> /etc/rc.d/rc.local`
`echo "sersync2 -dro /usr/local/sersync/conf/confxml.xml" >> /etc/rc.local`

https://blog.51cto.com/13707680/2124855

排错经验: 首先看提示信息error
配置文件出错:
01.. 书写信息错误
02. 文件语法错误
03. 配置参数缺失

posted @ 2020-06-20 20:41  HSping  阅读(120)  评论(0编辑  收藏  举报