美文网首页Linux技术分享
EAM系统架构之一:主从服务器DRBD数据同步

EAM系统架构之一:主从服务器DRBD数据同步

作者: 素白流殇 | 来源:发表于2016-09-05 10:31 被阅读81次
    1. 关闭iptables,修改selinux,时间同步等
    [root@mysql_node1 ~]# /etc/init.d/iptables stop
    [root@mysql_node1 ~]# chkconfig iptables off
    [root@mysql_node1 ~]# vim /etc/selinux/config
    # This file controls the state of SELinux on the system.
    # SELINUX= can take one of these three values:
    #     enforcing - SELinux security policy is enforced.
    #     permissive - SELinux prints warnings instead of enforcing.
    #     disabled - No SELinux policy is loaded.
    SELINUX=disabled
    # SELINUXTYPE= can take one of these two values:
    #     targeted - Targeted processes are protected,
    #     mls - Multi Level Security protection.
    SELINUXTYPE=targeted
    设置每两分钟进行一次时间同步
    crontab -e
    */2 * * * * /usr/sbin/ntpdate cn.pool.ntp.org > /tmp/ntp_log.txt
    
    2. 升级内核模块

    升级完成后,需要重新启动CentOS

    [root@mysql_node1 ~]# yum install kernel* -y
    
    Kernel
    3. 添加磁盘,进行磁盘分区

    例如添加2GB的磁盘sdb,其中分区sdb1作为drbd的元数据交换区(不需要格式化),分区sdb2作为数据的交换区(需要格式化文件系统)

    [root@mysql_node1 ~]# fdisk /dev/sdb
    [root@mysql_node1 ~]# fdisk -l
    Disk /dev/sdb: 2147 MB, 2147483648 bytes
    22 heads, 16 sectors/track, 11915 cylinders
    Units = cylinders of 352 * 512 = 180224 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00045fd1
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1               1        5959     1048776   83  Linux
    /dev/sdb2            5960       11915     1048256   83  Linux
    
    4. 安装DRBD

    4.1 上传安装drbd的yum源,和drbd内核模块

    [root@mysql_node1 ~]# yum install elrepo-release-6-6.el6.elrepo.noarch.rpm
    [root@mysql_node1 ~]# yum install drbd kmod-drbd84 -y
    

    4.2 加载drbd内核模块,并且检查是否加载成功

    [root@mysql_node1 ~]# modprobe drbd
    [root@mysql_node1 ~]# lsmod | grep drbd
    drbd                  372759  0 
    libcrc32c               1246  1 drbd
    
    5. 修改drbd的配置文件

    5.1 由drbd.conf文件可知可以编辑.res结尾的配置文件到drbd.d文件夹下

    [root@mysql_node1 ~]# cat /etc/drbd.conf 
    # You can find an example in  /usr/share/doc/drbd.../drbd.conf.example
    include "drbd.d/global_common.conf";
    include "drbd.d/*.res";
    

    5.2 可以参考drbd.conf.example文件进行配置

    [root@mysql_node1 ~]# cat /etc/drbd.d/mysqldata.res 
    resource mysqldata {
            protocol C;
            options {
                    on-no-data-accessible suspend-io;
            }
            
            net {   
                    cram-hmac-alg "sha1";
                    shared-secret "secret_string";
            }
            disk {  
                    # If you have a resonable RAID controller
                    # with non volatile write cache (BBWC, flash)
                    disk-flushes no;
                    disk-barrier no;
                    md-flushes no;
            }
            
            on mysql_node1 {
                    address 192.168.10.98:7780;
                           
                           device /dev/drbd0;
                           disk /dev/sdb2;
                           meta-disk /dev/sdb1;
            }
            on mysql_node2 {
                    address 192.168.10.99:7780;
                           
                           device /dev/drbd0;
                           disk /dev/sdb2;
                           meta-disk /dev/sdb1;
            }
    }
    

    5.3 在主备节点上同时启动drbd服务

    [root@mysql_node1 drbd.d]# /etc/init.d/drbd start
    

    5.4 查看drbd节点状态,发现两者都为secondary状态

    [root@mysql_node1 ~]# /etc/init.d/drbd status
    drbd driver loaded OK; device status:
    version: 8.4.7-1 (api:1/proto:86-101)
    GIT-hash: 3a6a769340ef93b1ba2792c6461250790795db49 build by mockbuild@Build64R6, 2016-01-12 13:27:11
    m:res        cs         ro                   ds                 p  mounted  fstype
    0:mysqldata  Connected  Secondary/Secondary  Diskless/Diskless  C
    

    5.5 配置元数据区,设置主节点

    [root@mysql_node1 ~]# drbdadm create-md mysqldata
    initializing activity log
    NOT initializing bitmap
    Writing meta data...
    New drbd meta data block successfully created.
    success
    [root@mysql_node1 ~]# drbdadm -- --overwrite-data-of-peer primary all
    

    5.6 观察drbd状态,发现一个为primary,另一个为secondary

    [root@mysql_node1 ~]# cat /proc/drbd 
    version: 8.4.7-1 (api:1/proto:86-101)
    GIT-hash: 3a6a769340ef93b1ba2792c6461250790795db49 build by mockbuild@Build64R6, 2016-01-12 13:27:11
     0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
        ns:1355768 nr:0 dw:307512 dr:1348649 al:83 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
    

    5.7 挂载drbd0到/data目录下。之后存放到data下的数据就会自动同步到从服务器

    [root@mysql_node1 ~]# mount /dev/drbd0 /data/
    

    5.8 drbd备份的数据无法在从服务器上直接观察到,可以用过关闭从服务器的drbd服务,挂载sdb2到/data目录下查看备份过来的数据

    相关文章

      网友评论

        本文标题:EAM系统架构之一:主从服务器DRBD数据同步

        本文链接:https://www.haomeiwen.com/subject/kokcettx.html