{"id":4317,"date":"2013-11-12T15:43:43","date_gmt":"2013-11-12T22:43:43","guid":{"rendered":"http:\/\/blog.networkpresence.co\/?p=4317"},"modified":"2015-12-29T18:42:57","modified_gmt":"2015-12-30T01:42:57","slug":"installing-drbd-across-two-debian-7-vps","status":"publish","type":"post","link":"http:\/\/blog.networkpresence.co\/?p=4317","title":{"rendered":"Installing DRBD across two Debian 7 VPS"},"content":{"rendered":"<p>At Network Presence we don&#8217;t meter or charge for data exchanged between customer VPS, so you can purchase 2 x VPS from us and use open-source Disk Clustering technologies described below to share a common filesystem between your VPS.<\/p>\n<p>Here&#8217;s the steps (down to the commands to run as root) to install and configure the DRBD Network Disk on Debian 7 running across a 2 Node Cluster:<\/p>\n<p>Some Linux or system level requirements or pre-install setup tasks are:<\/p>\n<p>1) Ensure the \/etc\/hosts files are the same on each Node and that it contains entries for each DB Node&#8217;s IP addresses and hostname (both the node hostname and its fully qualified hostname).<\/p>\n<p>eg:<br \/>\n<code>192.168.0.1 node1 node1.domain.name<br \/>\n192.168.0.2 node2 node2.domain.name<\/code><\/p>\n<p>2) Ensure that each Node&#8217;s Firewall permits each other node host IP addresses access to ports 7788 to 7799.<\/p>\n<p>3) The example setup below assumes that you have a Disk Device of the same size on both nodes, in this example that device is refered to as &#8220;\/dev\/xvdaX&#8221; but it could be a &#8220;\/dev\/loop0&#8221; device created on each node with commands like:<\/p>\n<p><code>dd if=\/dev\/zero of=\/storage\/somewhere\/drbd.disk bs=1024k count=1024<br \/>\nlosetup \/dev\/loop0 \/storage\/somewhere\/drbd.disk<\/code><\/p>\n<p>And use &#8220;\/dev\/loop0&#8221; in the DRBD config below, not &#8220;\/dev\/xvdaX&#8221; (for example).<\/p>\n<p>Then, run\/do the following on each Node to get the DRBD Disk live, sync&#8217;ing and running on the first node ASAP:<\/p>\n<p>a) Install per-requisite Debian Packages:<\/p>\n<p><code>apt-get -y install drbd8-utils<\/code><\/p>\n<p>b) Configure a DRBD Disk in your VPS:<\/p>\n<p><code>cat << EOF > \/etc\/drbd.d\/DISK1.res<br \/>\nresource DISK1 {<\/p>\n<p>startup {<br \/>\n    become-primary-on both;<br \/>\n  }<br \/>\n  net {<br \/>\n    ## not recommended to enable the allow-two-primaries option upon initial configuration. You should do so after the initial resource synchronization has completed.<br \/>\n    allow-two-primaries; ## After you enable the allow-two-primaries option for this resource, you will be able to promote the resource to the primary role on both nodes.<br \/>\n    after-sb-0pri discard-zero-changes;<br \/>\n    after-sb-1pri discard-secondary;<br \/>\n    after-sb-2pri disconnect;<br \/>\n  }<\/p>\n<p>  on node1 {<br \/>\n    device    \/dev\/drbd1;<br \/>\n    disk      \/dev\/xvdX;<br \/>\n    address   192.168.0.1:7789;<br \/>\n    meta-disk internal;<br \/>\n  }<br \/>\n  on node2 {<br \/>\n    device    \/dev\/drbd1;<br \/>\n    disk      \/dev\/xvdX;<br \/>\n    address   192.168.0.2:7789;<br \/>\n    meta-disk internal;<br \/>\n  }<br \/>\n}<br \/>\nEOF<br \/>\n<\/code><\/p>\n<p>c) Initialize the device for DRBD use:<\/p>\n<p><code>drbdadm create-md DISK1<\/code><\/p>\n<p>d) Sync the DRBD Disk across your VPS Nodes:<\/p>\n<p>On one of the node&#8217;s (eg: Node 1), run:<\/p>\n<p><code>drbdadm up all<br \/>\ndrbdadm -- --overwrite-data-of-peer primary all<\/code><\/p>\n<p>Speed the sync&#8217;s up with a command like (only needed on one node) :<\/p>\n<p><code>drbdsetup \/dev\/drbdX syncer -r 110M<\/code><\/p>\n<p>If you want this faster sync rate by default, then add the following to your DRBD config file (listed above) before the &#8216;resource&#8217; line :<\/p>\n<p><code>common { syncer { rate 100M; } }<\/code><\/p>\n<p>e) Activate the disk as Primary\/Primary:<\/p>\n<p>Easiest way after the disk sync (above) has finished: Reboot Node 2.<\/p>\n<p>Or, you can enter the command on Node 2 of:<\/p>\n<p><code>drbdadm primary DISK1<\/code><\/p>\n<p>(where DISK1 is the resource name listed in the DRBD config file above)<\/p>\n<p>f) Once Node 2 restarts the DRBD Cluster should sync primary:primary on the 2 Nodes.<\/p>\n<p><code>root@node2:~# cat \/proc\/drbd<br \/>\nversion: 8.3.[..]<br \/>\n 1: cs:Connected ro:Primary\/Primary ds:UpToDate\/UpToDate C r-----<\/code><\/p>\n<p>g) From here, you can create a Distributed or Clustered Filesystem on \/dev\/drbd1 and mount it on the two nodes. eg: Use XFS or OCFS2 or GlusterFS or another distributed or clustered filesystem type.<\/p>\n<p>A Filesystem which specifically supported multiple host mounting or is a Clustered Filesystem is required to be able to share and have the filesystem mounted on each host. ie: EXT3 or EXT4 is not capable of this and can only be mounted on one host at a time (even though the underlying disk device is common (\/dev\/drbd1) between the nodes).<\/p>\n<p>Further posts here will build on this post to describe creating and using OCFS2 as a Clustered Filesystem across the two DRBD Nodes.<\/p>\n<p>FYI and regards,<br \/>\nRichard.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>At Network Presence we don&#8217;t meter or charge for data exchanged between customer VPS, so you can purchase 2 x VPS from us and use open-source Disk Clustering technologies described below to share a common filesystem between your VPS. Here&#8217;s &hellip; <a href=\"http:\/\/blog.networkpresence.co\/?p=4317\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[121,166,165],"class_list":["post-4317","post","type-post","status-publish","format-standard","hentry","category-network-presence","tag-clustering","tag-drbd","tag-ocfs"],"_links":{"self":[{"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=\/wp\/v2\/posts\/4317","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4317"}],"version-history":[{"count":13,"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=\/wp\/v2\/posts\/4317\/revisions"}],"predecessor-version":[{"id":7735,"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=\/wp\/v2\/posts\/4317\/revisions\/7735"}],"wp:attachment":[{"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4317"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4317"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4317"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}