• centos6上yum安装drbd(内核:2.6.32.696)


    author:headsen  chen 

    date: 2017-11-20  15:11:21

    notice: 个人原创,转载请注明,否则依法追究法律责任

    前期准备:

     两台机器:配置主机名分别为: local.aaa.com 和local2.aaa.com

                      配置IP地址分别为:   192.168.115.143 和 192.168.115.180 并且能上网

                      配置时间服务:ntpdate ,使得两台主机的时间都准确并一致

                      配置两台主机的hosts文件,使得都能相互ping通主机名

                      

     1,安装(两台都要)

    [root@client 桌面]# wget http://www.elrepo.org/elrepo-release-6-8.el6.elrepo.noarch.rpm

     [root@client 桌面]# yum -y install elrepo-release-6-8.el6.elrepo.noarch.rpm

     [root@client 桌面]# yum -y install drbd84-utils kmod-drbd84

    [root@client 桌面]# modprobe drbd
    [root@client 桌面]# lsmod | grep drbd
    drbd 374888 0
    libcrc32c 1246 1 drbd
    [root@client 桌面]#

    2,分区(但不格式化和挂载,两台都要)(两台服务器的同步分区要一样大)

    [root@local2 桌面]# lsblk

    [root@local2 桌面]# fdisk /dev/sdb

    [root@local2 桌面]# lsblk
    。。。
    sdb 8:16 0 5G 0 disk
    ├─sdb1 8:17 0 2G 0 part
    └─sdb2 8:18 0 2G 0 part
    sr0 11:0 1 1024M 0 rom
    [root@local2 桌面]#

    3,配置

    3.1.参数配置:(两台都要)

    vim /usr/local/drbd/etc/drbd.conf
    清空里面的配置,添加如下配置:

    resource r0{
    protocol C;
    startup { wfc-timeout 0; degr-wfc-timeout 120;}
    disk { on-io-error detach;}
    net{
    timeout 60;
    connect-int 10;
    ping-int 10;
    max-buffers 2048;
    max-epoch-size 2048;
    }
    syncer { rate 100M;}
    on local.aaa.com{
    device /dev/drbd0;
    disk /dev/sdb1;
    address 192.168.115.143:7788;
    meta-disk internal;
    }
    on local2.aaa.com{
    device /dev/drbd0;
    disk /dev/sdb1;
    address 192.168.115.180:7788;
    meta-disk internal;
    }
    }

    将这个配置文件传到另外一台服务器上,要求两台服务器的这个配置文件要一模一样。

    3.2.创建DRBD设备并激活r0资源:两台都要)

    # mknod /dev/drbd0 b 147 0
    
    # drbdadm create-md r0
    
    等待片刻,显示success表示drbd块创建成功
    ----------------
    Writing meta data...
    initializing activity log
    NOT initializing bitmap
    New drbd meta data block successfully created.
                   --== Creating metadata ==--
    As with nodes, we count the total number of devices mirrored by DRBD
    at http://usage.drbd.org.
    The counter works anonymously. It creates a random number to identify
    the device and sends that random number, along with the kernel and
    DRBD version, to usage.drbd.org.
    http://usage.drbd.org/cgi-bin/insert_usage.pl?
    nu=716310175600466686&ru=15741444353112217792&rs=1085704704
    * If you wish to opt out entirely, simply enter 'no'.
    * To continue, just press [RETURN]        //出现[RETURN]按回车
    success
    ----------------
    再次输入该命令:
    # drbdadm create-md r0
    成功激活r0
    ----------------
    [need to type 'yes' to confirm] yes
    Writing meta data...
    initializing activity log
    NOT initializing bitmap
    New drbd meta data block successfully created.
    

    3.3 启动DRBD服务:(两台都要)

    # service drbd start
    

    注:需要主从共同启动方能生效

    3.4.查看状态:(两台都要)

    cat /proc/drbd
    
    version: 8.4.3 (api:1/proto:86-101)
    GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by root@drbd1.example.com,
    2013-05-27 20:45:19
    0: cs:Connected ro:Secondary/Secondary ds:Inconsistent/Inconsistent C r-----
       ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:1060184
    
    或者
    
    service drbd status
    
    drbd driver loaded OK; device status:
    version: 8.4.3 (api:1/proto:86-101)
    GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by root@drbd1.example.com,
    2013-05-27 20:45:19
    m:res  cs         ro                   ds                         p  mounted  fstype
    0:r0   Connected  Secondary/Secondary  Inconsistent/Inconsistent  C
    

    注:这里ro:Secondary/Secondary表示两台主机的状态都是备机状态ds是磁盘状态,显示的状态内容为“不一致”,这是因为DRBD无法判断哪一方为主机,应以哪一方的磁盘数据作为标准。

    3.5.将drbd1主机配置为主节点:(node1)

    # drbdsetup /dev/drbd0 primary --force

    分别查看主从DRBD状态:

    (node1)
    
    service drbd status
    
    drbd driver loaded OK; device status:
    version: 8.4.3 (api:1/proto:86-101)
    GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by root@local.aaa.com,
    2013-05-27 20:45:19
    m:res  cs         ro                 ds                 p  mounted  fstype
    0:r0   Connected  Primary/Secondary  UpToDate/UpToDate  C
    
    (node2)
    
    service drbd status
    
    drbd driver loaded OK; device status:
    version: 8.4.3 (api:1/proto:86-101)
    GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by root@local2.aaa.com,
    2013-05-27 20:49:06
    m:res  cs         ro                 ds                 p  mounted  fstype
    0:r0   Connected  Secondary/PrimaryUpToDate/UpToDate  C
    

    注:ro在主服务器上显示 Primary/Secondary , ds显示UpToDate/UpToDate;

          ro在从服务器上显示 Secondary/Primary  , ds显示UpToDate/UpToDate表示主从配置成功。

    3.6 挂载DRBD:(node1)

    从刚才的状态上看到mounted和fstype参数为空,所以我们这步开始挂载DRBD到系统目录
    
    # mkfs.ext4 /dev/drbd0
    
    # mount /dev/drbd0 /data
    
    注:Secondary节点上不允许对DRBD设备进行任何操作,包括只读,所有的读写操作只能在Primary节点上进行,只有当Primary节点挂掉时,Secondary节点才能提升为Primary节点继续工作。
    
     
    4、模拟故障

    (node1)

    cd /data
    touch 1 2 3 4 5
    cd ..
    umount /data
    drbdsetup /dev/drbd0 secondary
    

    注:这里实际生产环境若DRBD1宕机,在DRBD2状态信息中ro的值会显示为Secondary/Unknown,只需要进行DRBD提权操作即可。 (node2)

    drbdsetup /dev/drbd0 primary
    mount  /dev/drbd0 /data
    cd /data
    touch 6 7 8 9 10
    ls
    --------------
    1  10  2  3  4  5  6  7  8  9  lost+found
    

    查看(node1)(node2)DRBD状态:

    (node2)
    service drbd status
    
    drbd driver loaded OK; device status:
    version: 8.4.3 (api:1/proto:86-101)
    GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by root@local2.aaa.com,
    2013-05-27 20:49:06
    m:res  cs         ro                 ds                 p  mounted  fstype
    0:r0   Connected  Primary/Secondary  UpToDate/UpToDate  C  /data    ext4
    
    
    (node1)
    service drbd status
    
    drbd driver loaded OK; device status:
    version: 8.4.3 (api:1/proto:86-101)
    GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by root@local.aaa.com,
    2013-05-27 20:45:19
    m:res  cs         ro                 ds                 p  mounted  fstype
    0:r0   Connected  Secondary/Primary  UpToDate/UpToDate  C
  • 相关阅读:
    mysql主从延迟高的原因
    OpenStack云平台网络模式及其工作机制
    maps.reg
    dnion的remap.conf文件
    linux的tar命令
    traffic server文件目录
    records.config文件参数解释
    VNC配置
    KVM详情
    cache.config文件配置模板
  • 原文地址:https://www.cnblogs.com/kaishirenshi/p/7867725.html
Copyright © 2020-2023  润新知