zoukankan      html  css  js  c++  java
  • sersync+rsync做实时同步

    (1).实验环境

      源主机:youxi1  192.168.5.101

      目的主机:youxi2  192.168.5.102

      目的:实时同步数据

      sersync默认端口874,rsync默认端口873

    (2).实验

    1)下载sersync

      wegt https://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gz

      或者Windows下载再上传源主机youxi1。

    2)解压

    [root@youxi1 ~]# ls
    anaconda-ks.cfg  sersync2.5.4_64bit_binary_stable_final.tar.gz
    [root@youxi1 ~]# tar xvf sersync2.5.4_64bit_binary_stable_final.tar.gz  //解压
    GNU-Linux-x86/
    GNU-Linux-x86/sersync2
    GNU-Linux-x86/confxml.xml
    [root@youxi1 ~]# ls
    anaconda-ks.cfg  GNU-Linux-x86  sersync2.5.4_64bit_binary_stable_final.tar.gz
    [root@youxi1 ~]# mv GNU-Linux-x86 sersync  改名
    [root@youxi1 ~]# ls
    anaconda-ks.cfg  sersync  sersync2.5.4_64bit_binary_stable_final.tar.gz
    

    3)在目标主机youxi2上修改/etc/rsyncd.conf配置文件,以及密码文件

    [root@youxi2 ~]# cat /etc/rsyncd.conf 
    uid = root
    gid = root
    address = 192.168.5.102
    port = 873
    hosts allow = 192.168.5.101/24
    use chroot = yes
    max connections = 5
    pid file = /var/run/rsyncd.pid
    lock file = /var/run/rsync.lock
    log file = /var/log/rsyncd.log
    motd file = /etc/rsyncd.motd
    [backupwwwhtml]
    path = /backup/www/html
    comment = backup /www/html/
    read only = false
    list = yes
    auth users = rsync2
    secrets file = /etc/rsync.passwd
    [root@youxi2 ~]# cat /etc/rsync.passwd 
    rsync2:102102
    [root@youxi2 ~]# chmod 600 /etc/rsync.passwd

      启动指定配置文件的rsync的守护进程

    [root@youxi2 ~]# rsync --daemon --config=/etc/rsyncd.conf
    [root@youxi2 ~]# ps aux | grep rsync
    root       1478  0.0  0.0 114740   564 ?        Ss   11:10   0:00 rsync --daemon --config=/etc/rsyncd.conf
    root       1485  0.0  0.0 112720   980 pts/0    R+   11:12   0:00 grep --color=auto rsync
    

    4)源主机youxi1上修改sersync的配置文件

    [root@youxi1 sersync]# vim confxml.xml 
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <head version="2.5">
        <host hostip="localhost" port="8008"></host>
        <debug start="false"/>
        <fileSystem xfs="false"/>
        <filter start="false">
            <exclude expression="(.*).svn"></exclude>
            <exclude expression="(.*).gz"></exclude>
            <exclude expression="^info/*"></exclude>
            <exclude expression="^static/*"></exclude>
        </filter>
        <inotify>
            <createFile start="false"/>
            <closeWrite start="true"/>
            <moveFrom start="true"/>
            <moveTo start="true"/>
            <attrib start="false"/>
            <modify start="false"/>
        </inotify>
    
        <sersync>
            <localpath watch="/www/html">
                <remote ip="192.168.5.102" name="backupwwwhtml"/>  //修改为目标主机IP地址和模块名
            </localpath>
            <rsync>
                <commonParams params="-artuz"/>
                <auth start="true" users="rsync2" passwordfile="/etc/rsync.passwd"/>  //开启,修改用户名和密码文件地址
                <userDefinedPort start="false" port="874"/><!-- port=874 -->
                <timeout start="false" time="100"/><!-- timeout=100 -->
                <ssh start="false"/>
            </rsync>
            <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default e
    very 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>
    

      添加密码文件

    [root@youxi1 sersync]# vim /etc/rsync.passwd
    102102
    [root@youxi1 html]# chmod 600 /etc/rsync.passwd

    5)开启源主机youxi1的sersync的守护进程

    [root@youxi1 sersync]# /root/sersync/sersync2 -dro /root/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:  /root/sersync/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 rsync2
    passwordfile is         /etc/rsync.passwd
    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 /www/html && rsync -artuz -R --delete ./ rsync2@192.168.5.102::backupwwwhtml --password-file=/etc/rsync.passwd >/dev/null 2>&1 
    run the sersync: 
    watch path is: /www/html
    

    6)测试

      现在的目的主机youxi2情况如下

    [root@youxi2 ~]# ls /backup/www/html/
    adm    crash  empty  gopher    lib    lock  mail  opt       run    tmp
    cache  db     games  kerberos  local  log   nis   preserve  spool  yp
    

      对源主机youxi1的/www/html/目录下文件进行操作

    [root@youxi1 sersync]# cd /www/html/
    [root@youxi1 html]# ls
    adm    crash  empty  gopher    lib    lock  mail  opt       run    tmp
    cache  db     games  kerberos  local  log   nis   preserve  spool  yp
    [root@youxi1 html]# rm -rf adm/
    [root@youxi1 html]# touch 1.txt
    [root@youxi1 html]# ls
    1.txt  crash  empty  gopher    lib    lock  mail  opt       run    tmp
    cache  db     games  kerberos  local  log   nis   preserve  spool  yp
    

      回到目的主机查看情况

    [root@youxi2 ~]# ls /backup/www/html/
    1.txt  crash  empty  gopher    lib    lock  mail  opt       run    tmp
    cache  db     games  kerberos  local  log   nis   preserve  spool  yp
    

      

  • 相关阅读:
    Python(二)
    Python(三)
    Python(一)
    shell(计算机壳层)(一)
    web.xml中 /和/*的区别
    dubbo-admin监控搭建2.6.0版本
    Centos7安装maven
    Dubbo启动时qos-server can not bind localhost:22222错误解决
    Centos7安装zookeeper
    mysql5和mysql8连接数据库的配置
  • 原文地址:https://www.cnblogs.com/diantong/p/10875045.html
Copyright © 2011-2022 走看看