设为首页 收藏本站
查看: 634|回复: 0

[经验分享] rsync+sersync 实时同步安装配置

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-12-31 08:17:40 | 显示全部楼层 |阅读模式

环境搭建:(服务器,客户端)

首先关闭selinux与iptables

# vi /etc/sysconfig/selinux

SELINUX=disabled

# setenforce 0

# service iptables stop

在使用sersync之前,我们必须安装配置好rsync服务器


rsync (客户端)

一.安装rsync

# yum install rsync -y

# yum install xinetd -y

二.启动rsync依赖服务

# service xinetd start

# chkconfig xinetd on

三.配置:

# vi /etc/rsyncd.conf

uid = root

gid = root

use chroot = no

max connections = 4

port = 873

[test]     # rsync模块名,后面配置sersync会用到

path = /home/ftp

comment = ftp     #自定义

ignore errors

read only = no

list = no

auth users = user

secrets file = /etc/rsync.pas

hosts allow = *

# hosts deny = 0.0.0.0/0

pid file = /var/run/rsyncd.pid

lock file = /var/run/rsync.lock

log file = /var/log/rsyncd.log

四.创建同步目录

# mkdir -p /home/ftp

五.配置认证文件

# echo "user:123456" > /etc/rsync.pas

# chmod 600 /etc/rsync.pas

# rsync --daemon --config=/etc/rsyncd.conf

六.重启xinetd使其配置生效:

# /etc/init.d/xinetd restart

七.设置开机启动:

# echo "rsync --daemon --config=/etc/rsyncd.conf" >> /etc/rc.local


sersync (服务器端)

一.下载sersync源码包

# wget http://sersync.googlecode.com/fi ... stable_final.tar.gz

二.安装sersync

# tar zxvf sersync2.5_32bit_binary_stable_final.tar.gz

# mv GNU-Linux-x86/ /usr/local/sersync/

三.配置sersync

1.首先创建连接rsyncd的密码文件

# echo "123456" >/etc/rsync.pas

# chmod 600 /etc/rsync.pas

2.配置confxml.xml

# vim /usr/local/sersync/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/ftp">

   # 远程IP和rsync模块名  

           <remote ip="10.10.0.255" name="test"/>  

           <!--<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="user" passwordfile="/etc/rsync.pas"/>

   # 设置rsync远程服务端口,远程非默认端口则需打开自定义

           <userDefinedPort start="false" port="874"/><!-- 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="xxxx"/>

           <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.创建服务器端sersync同步目录

# mkdir -p /home/ftp

4.设置环境变量:

# echo "export PATH=$PATH:/usr/local/sersync/" >> /etc/profile

# source /etc/profile

5.启动sersync

# sersync2 -r -d -o /usr/local/sersync/confxml.xml

重启操作如下:

# killall sersync2

# sersync2 -r -d -o /usr/local/sersync/confxml.xml

6.设置开机启动

# echo "sersync2 -r -d -o /usr/local/sersync/confxml.xml" >> /etc/rc.local


验证:

(服务器端)

# cd /home/ftp

# touch 1

# echo "test" > 1

(客户端)

# cd /hoem/ftp

# ls

1

# cat 1

test



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-39974-1-1.html 上篇帖子: Linux-vimrc(vim显示行号、语法高亮、自动缩进的设置 ) 下篇帖子: ubuntu如何设置开机启动默认命令行界面
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表