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

[经验分享] rsync+sersync+nfs高可用

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-3-30 14:11:51 | 显示全部楼层 |阅读模式
环境:

HOSTIPOS
主机110001110.0.0.11CentOS6.6
主机210001210.0.0.12CentOS6.6
为了省事,直接关闭iptables,selinux,以下配置都为10.0.0.11上的配置,10.0.0.12也要做相同配置(个别地方须修改,如ip等)

一、安装配置rsync
1、安装
[iyunv@100011 /]#  yum install -y rsync xinetd
[iyunv@100011 /]#  service xinetd start&&chkconfig xinetd on
2、创建配置文件
[iyunv@100011 /]# mkdir /var/log/rsyncd  ##存放日志文件
[iyunv@100011 /]# vi /etc/rsyncd.conf
   
  ######内容######
       uid=root
       gid=root
       use chroot=no
       max connections=10
       strict modes=yes
       port=873
       address=10.0.0.11  ##本地要监听的IP地址
       [data]         ##数据同步模块名,可自定义名字
       path=/nfs-storage
       comment=nfs mirror
       ignore errors
       read only=no
       list=no
       secrets file=/etc/rsync.pas
       hosts allow=*
       pid file=/var/run/rsyncd.pid
       lock file=/var/run/rsync.lock
       log file=/var/log/rsyncd/rsyncd.log   
               
3、配置认证文件

[iyunv@100011 /]#  echo "abcd,.1234">/etc/rsync.pas
[iyunv@100011 /]#  chmod 600 /etc/rsync.pas
               rsync配置结束,不要添加开机启动,通过keepalived启动




二、安装配置sersync
  1、下载安装
wget http://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gz

wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/sersync/sersync2.5.4_64bit_binary_stable_final.tar.gz
[iyunv@100011 ~]#tar -zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz
    cd GNU-lINUX-x86/
    mkdir /usr/local/sersync
    mkdir /usr/local/sersync/conf
    mkdir /usr/local/sersync/bin
    mkdir /usr/local/sersync/log
    cp confxml.xml /usr/local/sersync/conf
    cp sersync2 /usr/local/sersync/bin/
   ln -s /usr/local/sersync/bin/sersync2 /usr/bin/sersync2
  2、配置
    vi /usr/local/sersync/conf/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="true">
        <exclude expression="^(.*)/Runtime/*"></exclude> 这是缓存目录,忽略掉,不监控
        <exclude expression="^\.(.*)"></exclude>     
        <exclude expression="(.*)\.tmp"></exclude>
        <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="false"/>
        <closeWrite start="true"/>
        <moveFrom start="false"/>
        <moveTo start="false"/>
        <attrib start="false"/>
        <modify start="false"/>
    </inotify>

    <sersync>
        <localpath watch="/nfs-storage">   本地监控目录
            <remote ip="10.0.0.12" name="data"/>  对端ip及rsync里面数据同步模块名
            <!--<remote ip="192.168.8.39" name="tongbu"/>-->
            <!--<remote ip="192.168.8.40" name="tongbu"/>-->
        </localpath>
        <rsync>
            <commonParams params="-artuz"/>
            <auth start="false" users="root" passwordfile="/etc/rsync.pas"/>
            <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="5"/><!--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">
        <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>
                 sersync配置结束,不要添加开机启动 ,通过keepalived启动  




三、安装本置keepalived
  1、安装
[iyunv@100011 /]#  yum install -y keepalived
  2、配置
   
[iyunv@100011 /]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id 100011   不能重复,我用的ip地址作为标识
}

vrrp_instance VI_1 {
    state BACKUP     两台都配置BACKUP
    interface eth0
    virtual_router_id 248   同一vrrp组要一样,我用的vip
   # use_vmac uvmac   开始想整vmac没成功
   # vmac_xmit_base
    priority 100   另一台上配置小于100
    advert_int 1
    nopreempt     另一台不需要   
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.0.0.248/24
    }
   notify_master /usr/local/sersync/tomaster.sh
   notify_backup /usr/local/sersync/tobackup.sh
}
}
四、安装配置nfs
1、服务器端,100012也要做相同配置
[iyunv@100011 /]#yum install -y nfs-utils rpcbind
[iyunv@100011 /]#vi /etc/exports
/nfs-storage/webdata    10.0.0.0/24(rw,no_root_squash)
[iyunv@100011 /]service rpcbind start&&service nfs start
[iyunv@100011 /]chkconfig nfs on&&chkconfig rpcbind on
[iyunv@100011 /]#exportfs
/nfs-storage/webdata
                10.0.0.0/24
2、客户端通过autofs挂载
[iyunv@100010 /]vi /etc/auto.nfs  假定100010为其中一台apache服务器
webdata  -rw,bg,soft,udp,rsize=524288,wsize=524288 10.0.0.248:/nfs-storage/webdata
[iyunv@100010 /]vi /etc/auto.master
#
# Sample auto.master file
# This is a 'master' automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
#
/misc   /etc/auto.misc
#
# NOTE: mounts done from a hosts map will be mounted with the
#       "nosuid" and "nodev" options unless the "suid" and "dev"
#       options are explicitly given.
#
/net    -hosts
#
# Include central master map if it can be found using
# nsswitch sources.
#
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.
#
+auto.master
/mydata /etc/auto.nfs --timeout=20   新加内容
service autofs restart
在/mydata下执行ls 发现为空,因通过autofs自动挂载配置,要有访问才会挂载,如执行cd webdata 便可发现挂载成功。上同的配置--timeout=20是说20秒空闲,就umount.
后记:过上一段时间,发现rsync的日志较大,通过logrotate分割rsync的日志,具体怎样使用,百度!!!
[iyunv@100011 /]#vi /etc/logrotate.d/rsyncd

/var/log/rsyncd/rsyncd.log {
notifempty
daily
rotate 7
}
部署过多次后后,我咋觉得要把这简单的事描述清楚,咋就这么困难呢,唉,语文没学好 j_0077.jpg ,。我的疑惑:比如挂载的时候通过udp(默认是tcp,我把它改成udp和把vmac固定,是为了看服务器端故障转移,看是不是要快些)。
重要东东在附件。checktb是根据官方脚本简单修改的,另也尝试rsync+sersync双向同步,但发现有点问题。(有兴趣自行测试吧)
脚本执行
[iyunv@100011 /]crontab -e

* * * * * /usr/local/sersync/checktb.sh
* * * * * sleep 10; /usr/local/sersync/checktb.sh
* * * * * sleep 20; /usr/local/sersync/checktb.sh
* * * * * sleep 30; /usr/local/sersync/checktb.sh
* * * * * sleep 40; /usr/local/sersync/checktb.sh
* * * * * sleep 50; /usr/local/sersync/checktb.sh


tomaster、tobackup、checktb.rar (1.72 KB, 下载次数: 0)

第一次写,由于我是菜鸟,简单的都还不懂,跟别说深层次的。肯定有疏漏不当之处,欢迎拍砖,拍了后但也请指正。


运维网声明 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-197691-1-1.html 上篇帖子: CentOS安装与自动化安装光盘配置 下篇帖子: CentOS6.5下安装rzsz
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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