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

[经验分享] ubuntu上安装rsync+sersync

[复制链接]

尚未签到

发表于 2018-5-2 13:34:20 | 显示全部楼层 |阅读模式
  

  服务器:数据从19--->12 和14
  172.16.1.12(rsync_server)
  172.16.1.14(rsync_server)
  172.16.1.19(rsync_client、sersync)
  172.16.1.12服务器:
  安装rsync server,rsync以xinetd方式运行
  #安装命令
apt-get install rsync xinetd  #创建存放文件目录,命令如下:
mkdir /data/res  #修改rsync启动方式
vim /etc/default/rsync  #修改下面这行
RSYNC_ENABLE=inetd  #rsync启动方式的配置文件
vim /etc/xinetd.d/rsync  #加入下面内容
service rsync
{
        disable         = no
        wait            = no
        socket_type     = stream
        user            = root
        server          = /usr/bin/rsync
        server_args     = --daemon
        log_on_failure += USERID
}  #rsync的配置文件
vim /etc/rsyncd.conf  #加入下面内容
max connections = 65535
log file = /var/log/rsync.log
timeout = 300
[res]
path = /data/res
read only = no
list = yes
uid = nobody
gid = nogroup
auth users = res
secrets file = /etc/rsyncd.secrets  #创建rsync传输过程中的认证文件
vim /etc/rsyncd.secrets  #内容如下,格式:用户名:密码
res:Gaw1sDnl!v$xZgg3  #此处密码修改成普通字母数字的,特殊符号不认
  #将认证文件权限修改成600
chmod 600 /etc/rsyncd.secrets  重启xinetd
/etc/init.d/xinetd restart  查看rsyncserver是否启动
netstat -ntpl|grep 873
tcp        0      0 0.0.0.0:873             0.0.0.0:*               LISTEN      24651/xinetd  测试:在19机器上执行
root@xxx:~# rsync res@172.16.1.12::res
Password:
drwxr-xr-x        4096 2014/08/15 10:23:14 .
-rw-r--r--           0 2014/08/15 10:23:14 test  

  172.16.1.14服务器的配置与172.16.1.12相同
  

  172.16.1.19服务器
  sersync下载地址
https://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gz  解压:
tar -zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz  #二进制文件直接放在/usr/local/sersync/目录下
mkdir -p /usr/local/sersync/{etc,bin,log}
mv GNU-Linux-x86/sersync2 /usr/local/sersync/bin
mv GNU-Linux-x86/confxml.xml /usr/local/sersync/etc  #修改sersync的配置文件
vim confxml.xml  ---------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
<!--##设置hostip和port,这个是针对插件保留的字段,对同步功能没有任何作用,默认即可-->
    <host hostip="localhost" port="8008"></host>
<!--##debug模式 默认:关闭,开启debug模式,会在sersync正在运行的控制台,打印inotify事件与rsync同步命令-->
    <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>
<!--##设置监控事件参数-->
<!--对于大多数应用,可以尝试把createFile(监控文件事件选项)设置为false来提高性能,减少 rsync通讯。因为拷贝文件到监控目录会产生create事件与close_write事件,所以如果关闭create事件,只监控文件拷贝结束时的事 件close_write,同样可以实现文件完整同步。
注意:必须将createFolder保持为true,如果将createFolder设为false,则不会对产生的目录进行监控,该目录下的子文件与子目录也不会被监控。所以除非特殊需要,请开启。默认情况下对创建文件(目录)事件与删除文件(目录)事件都进行监控,如果项目中不需要删除远程目标服务器的文件(目录),则可以将delete 参数设置为false,则不对删除事件进行监控-->
    <inotify>
        <delete start="true"/>
        <createFolder start="true"/>
        <createFile start="false"/>
        <closeWrite start="true"/>
        <moveFrom start="true"/>
        <moveTo start="true"/>
        <attrib start="true"/>
        <modify start="true"/>
    </inotify>
    <sersync>
<!--##设置本地的同步路径-->
        <localpath watch="/data/res.jinhui365.com">
<!--##远程ip和模块名称-->
            <remote ip="172.16.1.12" name="res"/>
            <remote ip="172.16.1.14" name="res"/>
            <!--<remote ip="192.168.8.40" name="tongbu"/>-->
        </localpath>
        <rsync>
<!--##rsync同步参数-->
            <commonParams params="-auvPz"/>
<!--##rsync同步认证-->
            <auth start="true" users="res" passwordfile="/etc/password.rsync"/>
<!--##设置rsync远程服务端口,远程非默认端口需打开自定义-->
            <userDefinedPort start="false" port="874"/><!-- port=874 -->
<!--##设置超时时间-->
            <timeout start="true" time="100"/><!-- timeout=100 -->
<!--##设置rsync+ssh加密传输模式 默认:关闭 ,开启需要设置SSH加密证书-->
            <ssh start="false"/>
        </rsync>
<!--##执行失败的语句存放在/tmp/rsync_fail_log.sh中,隔60分钟后会再次执行同步失败的语句-->
        <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
        <crontab start="false" schedule="600"><!--600mins-->
            <crontabfilter start="false">
                <exclude expression="*.php"></exclude>
                <exclude expression="info/*"></exclude>
            </crontabfilter>
        </crontab>
        <plugin start="false" name="command"/>
    </sersync>
    <plugin name="command">
<!--当文件同步完成后,会调用command插件,如同步文件是test.php,则test.php文件在改动之后,调用rsync同步到远程服务器后,调用command插件,执行/bin/sh test.php  suffix >/dev/null 2>&1  如果suffix设置了,则会放在inotify事件test.php之后,如果ignoreError为true,则会添加>/dev/null 2>&1当然还可以设置command的filter,当filter为ture,include可以只对正则匹配到的文件,调用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">
<!-- “refreshCDN”,就在同步过程中将文件发送到目的服务器后刷新cdn接口。如果不想使用,则将start属性设为false即可。如果需要使用其他插件,则查看其他plugin标签,将插件名称改为xml中其它插件的名称即可。该模块根据chinaCDN的协议,进行设计,当有文件产生的时候,就向cdn接口发送需要刷新的路径位置
其中 localpath watch 是需要监控的目录。
cdnifo标签制定了cdn接口的域名,端口号,以及用户名与密码。
sendurl标签是需要刷新的url的前缀。
regexurl标签中的,regex属性为true时候,使用match属性的正则语句匹配inotify返回的路径信息,并将正则匹配到的部分作为url一部分,-->
<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>  ---------------------------
  /usr/local/sersync/bin/sersync2 -r -d -o /usr/local/sersync/etc/confxml.xml
  

  2014.9.19补充rsync使用命令
本地copy
       rsync [OPTION]... SRC [SRC]... DEST
       rsync [OPTION]... SRC
shell模式
       rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST
       rsync [OPTION]... [USER@]HOST:SRC [DEST]
rsync daemon:
       rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST
       rsync [OPTION]... SRC [SRC]... rsync://[USER@]HOST[:PORT]/DEST
       rsync [OPTION]... [USER@]HOST::SRC [DEST]      
       rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]  

运维网声明 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.yunweiku.com/thread-454940-1-1.html 上篇帖子: 解决mysql在ubuntu安装出错 下篇帖子: fcitx无法输入英文( ubuntu14.04安装fcitx,fcitx
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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