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

[经验分享] DRBD with heartbeat

[复制链接]

尚未签到

发表于 2015-11-21 08:18:09 | 显示全部楼层 |阅读模式
  

Prerequisites
  - Setup Minimal CentOS 5
  - be sure that both nodes can resolve correctly names (either through dns or /etc/hosts)
  - yum update (as usual ... DSC0000.png )
  - yum install heartbeat drbd kmod-drbd (available in the extras repository)
  Current situation :


  • node1.yourdomain.org        172.29.156.20/24 , source disc /dev/sdb that will be replicated
  • node2.yourdomain.org        172.29.156.21/24 , target disc /dev/sdb
  

DRBD Configuration
  We'll
configure DRBD so that /dev/sdb will be replicated from one node to the
other (roles can be changed at any time though) The name of the drbd
resource will be "repdata" (you can of course use the name you want).
Here is the content of the /etc/drbd.conf file :
  

#
# please have a a look at the example configuration file in
# /usr/share/doc/drbd/drbd.conf
#
global { usage-count no; }
resource repdata {
  protocol C;
  startup { wfc-timeout 0; degr-wfc-timeout     120; }
  disk { on-io-error detach; } # or panic, ...
  net {  cram-hmac-alg "sha1"; shared-secret "Cent0Sru!3z"; } # don't forget to choose a secret for auth !
  syncer { rate 10M; }
  on node1.yourdomain.org {
    device /dev/drbd0;
    disk /dev/sdb;
    address 172.29.156.20:7788;
    meta-disk internal;
  }
  on node2.yourdomain.org {
    device /dev/drbd0;
    disk /dev/sdb;
    address 172.29.156.21:7788;
    meta-disk internal;
  }
}

  - replicate this config file (/etc/drbd.conf) to the second node
  

scp /etc/drbd.conf root@node2:/etc/

  - Initialize the meta-data area on disk before starting drbd (! on both nodes!)
  

[iyunv@node1 etc]# drbdadm create-md repdata
v08 Magic number not found
v07 Magic number not found
About to create a new drbd meta data block on /dev/sdb.
. ==> This might destroy existing data! <==
Do you want to proceed? [need to type 'yes' to confirm] yes
Creating meta data... initialising activity log NOT initialized bitmap (256 KB) New drbd meta data block sucessfully created.

  - start drbd on both nodes (service drbd start)
  

[iyunv@node1 etc]# service drbd start
Starting DRBD resources:    [ d0 n0 ]. ......
[iyunv@node1 etc]# cat /proc/drbd
version: 8.0.4 (api:86/proto:86) SVN Revision: 2947 build by buildsvn@c5-i386-build, 2007-07-31 19:17:18
. 0: cs:Connected st: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
   . resync: used:0/31 hits:0 misses:0 starving:0 dirty:0 changed:0 act_log: used:0/257 hits:0 misses:0 starving:0 dirty:0 changed:0
[iyunv@node1 etc]# ssh root@node2 cat /proc/drbd  version: 8.0.4 (api:86/proto:86) SVN Revision: 2947 build by buildsvn@c5-i386-build, 2007-07-31 19:17:18
. 0: cs:Connected st: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
   . resync: used:0/31 hits:0 misses:0 starving:0 dirty:0 changed:0 act_log: used:0/257 hits:0 misses:0 starving:0 dirty:0 changed:0

  As
you can see , both nodes are secondary, which is normal. we need to
decide which node will act as a primary now (node1) : that will
initiate the first 'full sync' between the two nodes :
  

[iyunv@node1 etc]# drbdadm -- --overwrite-data-of-peer primary repdata
[iyunv@node1 etc]# watch -n 1 cat /proc/drbd  version: 8.0.4 (api:86/proto:86) SVN Revision: 2947 build by buildsvn@c5-i386-build, 2007-07-31 19:17:18
. 0: cs:SyncTarget st:Primary/Secondary ds:Inconsistent/Inconsistent C r---
  . ns:0 nr:68608 dw:68608 dr:0 al:0 bm:4 lo:0 pe:0 ua:0 ap:0
   . [>...................] sync'ed:  0.9% (8124/8191)M finish: 0:12:05 speed: 11,432 (11,432) K/sec resync: used:0/31 hits:4283 misses:5 starving:0 dirty:0 changed:5 act_log: used:0/257 hits:0 misses:0 starving:0 dirty:0 changed:0

  - we can now format /dev/drbd0 and mount it on node1 :  mkfs.ext3 /dev/drbd0 ; mkdir /repdata ; mount /dev/drbd0 /repdata  
  - create some fake data on node 1 :


  •   [iyunv@node1 etc]# for i in {1..5};do dd if=/dev/zero of=/repdata/file$i bs=1M count=100;done  

  - now switch manually to the second node :
  

[iyunv@node1 /]# umount /repdata ; drbdadm secondary repdata
[iyunv@node2 /]# mkdir /repdata ; drbdadm primary repdata ; mount /dev/drbd0 /repdata
[iyunv@node2 /]# ls /repdata/ file1  file2  file3  file4  file5  lost+found

  Great, data was replicated .... now let's delete/add some file :
  [iyunv@node2 /]# rm /repdata/file2 ; dd if=/dev/zero of=/repdata/file6 bs=100M count=2
  - Now switch back to the first node :
  

[iyunv@node2 /]# umount /repdata/ ; drbdadm secondary repdata
[iyunv@node1 /]# drbdadm primary repdata ; mount /dev/drbd0 /repdata
[iyunv@node1 /]# ls /repdata/ file1  file3  file4  file5  file6  lost+found

  OK ... Drbd is working ... let's be sure that it will always be started : chkconfig drbd on
  

Heartbeat V2 Configuration
  Let's configure a simple /etc/ha.d/ha.cf file :
  

keepalive 2
deadtime 30
warntime 10
initdead 120
bcast   eth0
node    node1.yourdomain.org
node    node2.yourdomain.org
crm yes

  Create also the /etc/ha.d/authkeys (with permissions 600 !!!) :
  

auth 1
1 sha1 MySecret

  Start the heartbeat service on node1 :
  

[iyunv@node1 ha.d]# service heartbeat start
Starting High-Availability services: [OK]

  Check the cluster status :
  [iyunv@node1 ha.d]# crm_mon  
  Replicate now the ha.cf and authkeys to node2 and start heartbeat
  

[iyunv@node1 ha.d]# scp /etc/ha.d/ha.cf /etc/ha.d/authkeys root@node2:/etc/ha.d/
[iyunv@node2 ha.d]# service heartbeat start

  Verify cluster with crm_mon :
  

=====
Last updated: Wed Sep 12 16:20:39 2007
Current DC: node1.centos.org (6cb712e4-4e4f-49bf-8200-4f15d6bd7385)
2 Nodes configured.
0 Resources configured.
=====
Node: node1.yourdomain.org (6cb712e4-4e4f-49bf-8200-4f15d6bd7385): online
Node: node2.yourdomain.org (f6112aae-8e2b-403f-ae93-e5fd4ac4d27e): online

   Note about the gui
: you can install heartbeat-gui (yum install heartbeat-gui) on a X
workstation and connect to the cluster but you'll need to change the
password of the hacluster user account on both nodes ! (or you can use
another account but put this one in the haclient group)
  We'll
know create a resource group that contains an ip address
(172.29.156.200) , the drbd device (name repdata) and the filesystem
mount operation (mount /dev/drbd0 /repdata) Note : Using a group is
easier than using single resources : it will start all the resources
from a group in order (ordered=true) and on one node (collocated=true)
  Here is the content of /var/lib/heartbeat/crb/cib.xml :
  

<cib generated="false" admin_epoch="0" epoch="25" num_updates="1" have_quorum="true" ignore_dtd="false" num_peers="0" cib-last-written="Sun Sep 16 19:47:18 2007" cib_feature_revision="1.3" ccm_transition="1">
   <configuration>
     <crm_config/>
     <nodes>
       <node id="6cb712e4-4e4f-49bf-8200-4f15d6bd7385" uname="node1.yourdomain.org" type="normal"/>
       <node id="f6112aae-8e2b-403f-ae93-e5fd4ac4d27e" uname="node2.yourdomain.org" type="normal"/>
     </nodes>
     <resources>
       <group id="My-DRBD-group" ordered="true" collocated="true">
         <primitive id="IP-Addr" class="ocf" type="IPaddr2" provider="heartbeat">
           <instance_attributes id="IP-Addr_instance_attrs">
             <attributes>
               <nvpair id="IP-Addr_target_role" name="target_role" value="started"/>
               <nvpair id="2e967596-73fe-444e-82ea-18f61f3848d7" name="ip" value="172.29.156.200"/>
             </attributes>
           </instance_attributes>
         </primitive>
         <instance_attributes id="My-DRBD-group_instance_attrs">
           <attributes>
             <nvpair id="My-DRBD-group_target_role" name="target_role" value="started"/>
           </attributes>
         </instance_attributes>
         <primitive id="DRBD_data" class="heartbeat" type="drbddisk" provider="heartbeat">
           <instance_attributes id="DRBD_data_instance_attrs">
             <attributes>
               <nvpair id="DRBD_data_target_role" name="target_role" value="started"/>
               <nvpair id="93d753a8-e69a-4ea5-a73d-ab0d0367f001" name="1" value="repdata"/>
             </attributes>
           </instance_attributes>
         </primitive>
         <primitive id="FS_repdata" class="ocf" type="Filesystem" provider="heartbeat">
           <instance_attributes id="FS_repdata_instance_attrs">
             <attributes>
               <nvpair id="FS_repdata_target_role" name="target_role" value="started"/>
               <nvpair id="96d659dd-0881-46df-86af-d2ec3854a73f" name="fstype" value="ext3"/>
               <nvpair id="8a150609-e5cb-4a75-99af-059ddbfbc635" name="device" value="/dev/drbd0"/>
               <nvpair id="de9706e8-7dfb-4505-b623-5f316b1920a3" name="directory" value="/repdata"/>
             </attributes>
           </instance_attributes>
         </primitive>
       </group>
     </resources>
     <constraints>
       <rsc_location id="runs_on_pref_node" rsc="My-DRBD-group">
         <rule id="prefered_runs_on_pref_node" score="100">
           <expression attribute="#uname" id="786ef2b1-4289-4570-8923-4c926025e8fd" operation="eq" value="node1.yourdomain.org"/>
         </rule>
       </rsc_location>
     </constraints>
   </configuration>
</cib>

  As you can see, we've created a rsc_location constraint so that the cluster resources will start on the prefered node.
  You
can now move resources through cli (crm_resource) or by using the gui
(change the location constraint rule value - for example swithching
from node1.yourdomain.org to node2.yourdomain.org and click on apply) .
You'll be able to see all resources switching from one node to the
other (ip address, drbd and filesystem mount)
  

Firewall considerations
  You will need to make sure that the nodes can talk on ports:

DRBD: 7788
HEARTBEAT: 694

  

运维网声明 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-141683-1-1.html 上篇帖子: heartbeat+drbd 下篇帖子: iptables导致heartbeat脑裂
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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