{"id":5395,"date":"2015-11-27T17:53:25","date_gmt":"2015-11-27T09:53:25","guid":{"rendered":"http:\/\/rmohan.com\/?p=5395"},"modified":"2015-11-27T17:54:02","modified_gmt":"2015-11-27T09:54:02","slug":"drbd-setup-on-centos-6-7","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=5395","title":{"rendered":"DRBD setup on Centos 6.7"},"content":{"rendered":"<p>CentOS 6.7 DRBD installation and configuration notes<\/p>\n<p>DRDB or Distributed Replicated Block Device is nice for HA situations of distributed block devices. This can be used for NAS, SAN, and a number of other use cases.<\/p>\n<p>** NOTE THIS SETUP IS FOR ACTIVE\/PASSIVE, NOT ACTIVE<\/p>\n<p>Primary: 192.168.1.60 (cluster1.rmohan.com)<\/p>\n<p>Secondary: 192.168.1.61 (cluster2.rmohan.com)<br \/>\nRequirements<\/p>\n<p>\u2013 Two disks (preferably same size)<br \/>\n\u2013 Networking between machines (node1 &amp; node2)<br \/>\n\u2013 Working DNS resolution (\/etc\/hosts file)<br \/>\n\u2013 NTP synchronized times on both nodes<br \/>\n\u2013 Selinux Permissive<br \/>\n\u2013 Iptables ports (7788) allowed<br \/>\n(Primary) configured as a master server only<br \/>\n(Secondary) is configured as a server-side only<br \/>\n(Primary, Secondary) based server configuration from the server together<br \/>\nI. Prepare the environment: (Primary, Secondary)<br \/>\nPartition DRBD on both machines<\/p>\n<p>[root@cluster1 ~]# fdisk \/dev\/sdb<br \/>\nDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel<br \/>\nBuilding a new DOS disklabel with disk identifier 0xe8577511.<br \/>\nChanges will remain in memory only, until you decide to write them.<br \/>\nAfter that, of course, the previous content won&#8217;t be recoverable.<\/p>\n<p>Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)<\/p>\n<p>WARNING: DOS-compatible mode is deprecated. It&#8217;s strongly recommended to<br \/>\nswitch off the mode (command &#8216;c&#8217;) and change display units to<br \/>\nsectors (command &#8216;u&#8217;).<\/p>\n<p>Command (m for help): n<br \/>\nCommand action<br \/>\ne extended<br \/>\np primary partition (1-4)<br \/>\np<br \/>\nPartition number (1-4): 1<br \/>\nFirst cylinder (1-6527, default 1):<br \/>\nUsing default value 1<br \/>\nLast cylinder, +cylinders or +size{K,M,G} (1-6527, default 6527):<br \/>\nUsing default value 6527<\/p>\n<p>Command (m for help): t<br \/>\nSelected partition 1<br \/>\nHex code (type L to list codes): 8e<br \/>\nChanged system type of partition 1 to 8e (Linux LVM)<\/p>\n<p>Command (m for help): w<br \/>\nThe partition table has been altered!<\/p>\n<p>Calling ioctl() to re-read partition table.<br \/>\nSyncing disks.<\/p>\n<p>root@cluster1 ~]# iptables -L<br \/>\nChain INPUT (policy ACCEPT)<br \/>\ntarget prot opt source destination<br \/>\nACCEPT all &#8212; anywhere anywhere state RELATED,ESTABLISHED<br \/>\nACCEPT icmp &#8212; anywhere anywhere<br \/>\nACCEPT all &#8212; anywhere anywhere<br \/>\nACCEPT tcp &#8212; anywhere anywhere state NEW tcp dpt:ssh<br \/>\nREJECT all &#8212; anywhere anywhere reject-with icmp-host-prohibited<\/p>\n<p>Chain FORWARD (policy ACCEPT)<br \/>\ntarget prot opt source destination<br \/>\nREJECT all &#8212; anywhere anywhere reject-with icmp-host-prohibited<\/p>\n<p>Chain OUTPUT (policy ACCEPT)<br \/>\ntarget prot opt source destination<br \/>\n[root@cluster1 ~]# \/etc\/init.d\/iptables stop<br \/>\niptables: Setting chains to policy ACCEPT: filter [ OK ]<br \/>\niptables: Flushing firewall rules: [ OK ]<br \/>\niptables: Unloading modules: [ OK ]<br \/>\n[root@cluster1 ~]# \/etc\/init.d\/iptables stop<br \/>\n[root@cluster1 ~]# iptables -F<br \/>\n[root@cluster1 ~]# iptables-save &gt; \/etc\/sysconfig\/iptables<\/p>\n<p>iptables-save<br \/>\n*filter<br \/>\n:INPUT ACCEPT [0:0]<br \/>\n:FORWARD ACCEPT [0:0]<br \/>\n:OUTPUT ACCEPT [14:1480]<br \/>\n-A INPUT -m state &#8211;state RELATED,ESTABLISHED -j ACCEPT<br \/>\n-A INPUT -p icmp -j ACCEPT<br \/>\n-A INPUT -i lo -j ACCEPT<br \/>\n-A INPUT -p tcp -m state &#8211;state NEW -m tcp &#8211;dport 22 -j ACCEPT<br \/>\n-A INPUT -p tcp -m state &#8211;state NEW -m tcp &#8211;dport 7788:7799 -j ACCEPT<br \/>\n-A INPUT -j REJECT &#8211;reject-with icmp-host-prohibited<br \/>\n-A FORWARD -j REJECT &#8211;reject-with icmp-host-prohibited<br \/>\n-A OUTPUT -p tcp -m tcp &#8211;dport 7788:7799 -j ACCEPT<br \/>\nCOMMIT<\/p>\n<p>[root@cluster2 ~]# fdisk \/dev\/sdb<br \/>\nDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel<br \/>\nBuilding a new DOS disklabel with disk identifier 0xe1b1fb03.<br \/>\nChanges will remain in memory only, until you decide to write them.<br \/>\nAfter that, of course, the previous content won&#8217;t be recoverable.<\/p>\n<p>Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)<\/p>\n<p>WARNING: DOS-compatible mode is deprecated. It&#8217;s strongly recommended to<br \/>\nswitch off the mode (command &#8216;c&#8217;) and change display units to<br \/>\nsectors (command &#8216;u&#8217;).<\/p>\n<p>Command (m for help): n<br \/>\nCommand action<br \/>\ne extended<br \/>\np primary partition (1-4)<br \/>\np<br \/>\nPartition number (1-4): 1<br \/>\nFirst cylinder (1-6527, default 1):<br \/>\nUsing default value 1<br \/>\nLast cylinder, +cylinders or +size{K,M,G} (1-6527, default 6527):<br \/>\nUsing default value 6527<\/p>\n<p>Command (m for help): t<br \/>\nSelected partition 1<br \/>\nHex code (type L to list codes): 8e<br \/>\nChanged system type of partition 1 to 8e (Linux LVM)<\/p>\n<p>Command (m for help): w<br \/>\nThe partition table has been altered!<\/p>\n<p>Calling ioctl() to re-read partition table.<br \/>\nSyncing disks.<br \/>\n[root@cluster2 ~]# iptables -L<br \/>\nChain INPUT (policy ACCEPT)<br \/>\ntarget prot opt source destination<br \/>\nACCEPT all &#8212; anywhere anywhere state RELATED,ESTABLISHED<br \/>\nACCEPT icmp &#8212; anywhere anywhere<br \/>\nACCEPT all &#8212; anywhere anywhere<br \/>\nACCEPT tcp &#8212; anywhere anywhere state NEW tcp dpt:ssh<br \/>\nREJECT all &#8212; anywhere anywhere reject-with icmp-host-prohibited<\/p>\n<p>Chain FORWARD (policy ACCEPT)<br \/>\ntarget prot opt source destination<br \/>\nREJECT all &#8212; anywhere anywhere reject-with icmp-host-prohibited<\/p>\n<p>Chain OUTPUT (policy ACCEPT)<br \/>\ntarget prot opt source destination<br \/>\n[root@cluster2 ~]# \/etc\/init.d\/iptables stop<br \/>\niptables: Setting chains to policy ACCEPT: filter [ OK ]<br \/>\niptables: Flushing firewall rules: [ OK ]<br \/>\niptables: Unloading modules: [ OK ]<br \/>\n[root@cluster2 ~]# iptables -F<br \/>\n[root@cluster2 ~]# iptables-save &gt; \/etc\/sysconfig\/iptables<br \/>\n[root@cluster2 ~]#<br \/>\nCreate mysql dir<br \/>\n[root@cluster1 ~]# mkdir \/mysql<br \/>\n[root@cluster2 ~]# mkdir \/mysql<br \/>\nNtp update<\/p>\n<p>[root@cluster1 ~]# chkconfig &#8211;level 345 ntpd on<br \/>\n[root@cluster1 ~]# \/etc\/init.d\/ntpd restart<br \/>\nShutting down ntpd: [FAILED]<br \/>\nStarting ntpd: [ OK ]<br \/>\n[root@cluster1 ~]# ntpdate -u 0.centos.pool.ntp.org<\/p>\n<p>[root@cluster2 ~]# chkconfig &#8211;level 345 ntpd on<br \/>\n[root@cluster2 ~]# \/etc\/init.d\/ntpd restart<br \/>\nShutting down ntpd: [FAILED]<br \/>\nStarting ntpd: [ OK ]<br \/>\n[root@cluster2 ~]# ntpdate -u 0.centos.pool.ntp.org<br \/>\n1. Install dependencies: (Primary, Secondary)<\/p>\n<p># yum install gcc gcc-c++ make glibc flex kernel-devel kernel-headers<\/p>\n<p>Install rpm -Uvh http:\/\/www.elrepo.org\/elrepo-release-6-6.el6.elrepo.noarch.rpm<\/p>\n<p>Install DRBD on both nodes cluster1 and cluster2<\/p>\n<p>yum -y install drbd83-utils kmod-drbd83<\/p>\n<p>Insert drbd module manually on both machines or reboot:<br \/>\n\/sbin\/modprobe drbd<\/p>\n<p>add the config<\/p>\n<p>Create the Distributed Replicated Block Device resource file<\/p>\n<p>\/etc\/drbd.d\/clusterdb.res<\/p>\n<p>resource clusterdb<br \/>\n{<br \/>\nstartup {<br \/>\nwfc-timeout 30;<br \/>\noutdated-wfc-timeout 20;<br \/>\ndegr-wfc-timeout 30;<br \/>\n}<\/p>\n<p>net {<br \/>\ncram-hmac-alg sha1;<br \/>\nshared-secret sync_disk;<br \/>\n}<\/p>\n<p>syncer {<br \/>\nrate 10M;<br \/>\nal-extents 257;<br \/>\non-no-data-accessible io-error;<br \/>\n}<br \/>\non cluster1.rmohan.com {<br \/>\ndevice \/dev\/drbd0;<br \/>\ndisk \/dev\/sdb1;<br \/>\naddress 192.168.1.60:7788;<br \/>\nflexible-meta-disk internal;<br \/>\n}<br \/>\non cluster2.rmohan.com {<br \/>\ndevice \/dev\/drbd0;<br \/>\ndisk \/dev\/sdb1;<br \/>\naddress 192.168.1.62:7788;<br \/>\nmeta-disk internal;<br \/>\n}<br \/>\n}<\/p>\n<p>Initialize the DRBD meta data storage on both machines:<\/p>\n<p>drbdadm create-md clusterdb<\/p>\n<p>start drbd on both node<br \/>\nservice drbd start<\/p>\n<p>On the PRIMARY node run drbdadm command:<br \/>\ndrbdsetup \/dev\/drbd0 primary &#8211;overwrite-data-of-peer<\/p>\n<p>Every 2.0s: service drbd status Thu Nov 26 22:13:34 2015<br \/>\ndrbd driver loaded OK; device status:<br \/>\nversion: 8.3.16 (api:88\/proto:86-97)<br \/>\nGIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build64R6, 2014-11-24 14:51:37<br \/>\nm:res cs ro ds p mounted fstype<br \/>\n0:clusterdb SyncSource Primary\/Secondary UpToDate\/Inconsistent C<br \/>\n&#8230; sync&#8217;ed: 1.2% (50624\/51196)M<br \/>\nwatch service drbd status<\/p>\n<p>[root@cluster1 ~]# service drbd status<br \/>\ndrbd driver loaded OK; device status:<br \/>\nversion: 8.3.16 (api:88\/proto:86-97)<br \/>\nGIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build64R6, 2014-11-24 14:51:37<br \/>\nm:res cs ro ds p mounted fstype<br \/>\n0:clusterdb Connected Primary\/Secondary UpToDate\/UpToDate C<br \/>\n[root@cluster1 ~]#<br \/>\n\/sbin\/mkfs.ext4 \/dev\/drbd0<br \/>\nmke2fs 1.41.12 (17-May-2010)<br \/>\nFilesystem label=<br \/>\nOS type: Linux<br \/>\nBlock size=4096 (log=2)<br \/>\nFragment size=4096 (log=2)<br \/>\nStride=0 blocks, Stripe width=0 blocks<br \/>\n3276800 inodes, 13106615 blocks<br \/>\n655330 blocks (5.00%) reserved for the super user<br \/>\nFirst data block=0<br \/>\nMaximum filesystem blocks=4294967296<br \/>\n400 block groups<br \/>\n32768 blocks per group, 32768 fragments per group<br \/>\n8192 inodes per group<br \/>\nSuperblock backups stored on blocks:<br \/>\n32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,<br \/>\n4096000, 7962624, 11239424<\/p>\n<p>Writing inode tables: done<br \/>\nCreating journal (32768 blocks): done<br \/>\nWriting superblocks and filesystem accounting information: done<\/p>\n<p>This filesystem will be automatically checked every 37 mounts or<br \/>\n180 days, whichever comes first. Use tune2fs -c or -i to override.<\/p>\n<p>root@cluster1 ~]# mount -t ext4 \/dev\/drbd0 \/mysql\/<br \/>\n[root@cluster1 ~]# df -TH<br \/>\nFilesystem Type Size Used Avail Use% Mounted on<br \/>\n\/dev\/mapper\/vg_cluster1-lv_root<br \/>\next4 53G 1.8G 49G 4% \/<br \/>\ntmpfs tmpfs 3.0G 0 3.0G 0% \/dev\/shm<br \/>\n\/dev\/sda1 ext4 500M 57M 417M 13% \/boot<br \/>\n\/dev\/mapper\/vg_cluster1-lv_home<br \/>\next4 47G 55M 44G 1% \/home<br \/>\n\/dev\/drbd0 ext4 53G 55M 50G 1% \/mysql<br \/>\n[root@cluster1 ~]#<br \/>\n[root@cluster1 mysql]# date ; drbdadm role clusterdb<br \/>\nFri Nov 27 13:28:57 SGT 2015<br \/>\nPrimary\/Secondary<\/p>\n<p>[root@cluster2 ~]# date ; drbdadm role clusterdb<br \/>\nFri Nov 27 13:29:02 SGT 2015<br \/>\nSecondary\/Primary<br \/>\nverify replication is up to date<\/p>\n<p>[root@cluster1 ~]# cat \/proc\/drbd<br \/>\nversion: 8.3.16 (api:88\/proto:86-97)<br \/>\nGIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build64R6, 2014-11-24 14:51:37<br \/>\n0: cs:Connected ro:Primary\/Secondary ds:UpToDate\/UpToDate C r&#8212;&#8211;<br \/>\nns:56 nr:0 dw:0 dr:1052 al:0 bm:3 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0<\/p>\n<p>Admin Commands:<\/p>\n<p>[root@cluster1 ~]# drbd-overview<br \/>\n0:clusterdb Connected Primary\/Secondary UpToDate\/UpToDate C r&#8212;&#8211;<\/p>\n<p>[root@cluster1 ~]# \/etc\/init.d\/drbd status<br \/>\ndrbd driver loaded OK; device status:<br \/>\nversion: 8.3.16 (api:88\/proto:86-97)<br \/>\nGIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build64R6, 2014-11-24 14:51:37<br \/>\nm:res cs ro ds p mounted fstype<br \/>\n0:clusterdb Connected Primary\/Secondary UpToDate\/UpToDate C<br \/>\nBASIC MANUAL FAIL-OVER<br \/>\n# umount \/dev\/drbd0<br \/>\n# drbdadm secondary &lt;resource&gt;<br \/>\nNow on the node we wish to make primary promote the resource and mount the device.<br \/>\n# drbdadm primary &lt;resource&gt;<br \/>\n# mount \/dev\/drbd0\/by-res\/&lt;resource&gt; &lt;mountpoint&gt;<\/p>\n<p>disconnecting disk:<\/p>\n<p>drbdam disconnect clusterdb<br \/>\ndrbdadm disconnect clusterdb<br \/>\ndf -TH<br \/>\numount \/dev\/drbd0<br \/>\ndrbdadm secondary clusterdb<\/p>\n<p>drbdadm connect clusterdb<br \/>\ndrbdadm primary clusterdb<br \/>\nmount -t ext4 \/dev\/drbd0 \/mysql\/<br \/>\ndf -TH<br \/>\ncd \/mysql\/<br \/>\nFix DRBD recovery from split brain<\/p>\n<p>root@cluster1 ~]# \/etc\/init.d\/drbd status<br \/>\ndrbd driver loaded OK; device status:<br \/>\nversion: 8.3.16 (api:88\/proto:86-97)<br \/>\nGIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build64R6, 2014-11-24 14:51:37<br \/>\nm:res cs ro ds p mounted fstype<br \/>\n0:clusterdb StandAlone Primary\/Unknown UpToDate\/DUnknown r&#8212;&#8211;<br \/>\n[root@cluster2 ~]# \/etc\/init.d\/drbd status<br \/>\ndrbd driver loaded OK; device status:<br \/>\nversion: 8.3.16 (api:88\/proto:86-97)<br \/>\nGIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build64R6, 2014-11-24 14:51:37<br \/>\nm:res cs ro ds p mounted fstype<br \/>\n0:clusterdb StandAlone Secondary\/Unknown UpToDate\/DUnknown r&#8212;&#8211;<br \/>\nSolution:<\/p>\n<p>Step 1: Start drbd manually on both nodes<\/p>\n<p>Step 2: Define one node as secondary and discard data on this<\/p>\n<p>drbdadm secondary all<br \/>\ndrbdadm disconnect all<br \/>\ndrbdadm &#8212; &#8211;discard-my-data connect all<\/p>\n<p>Step 3: Define anoher node as primary and connect<br \/>\ndrbdadm primary all<br \/>\ndrbdadm disconnect all<br \/>\ndrbdadm connect all<\/p>\n<p>[root@cluster1 ~]# \/etc\/init.d\/drbd status<br \/>\ndrbd driver loaded OK; device status:<br \/>\nversion: 8.3.16 (api:88\/proto:86-97)<br \/>\nGIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build64R6, 2014-11-24 14:51:37<br \/>\nm:res cs ro ds p mounted fstype<br \/>\n0:clusterdb Connected Primary\/Secondary UpToDate\/UpToDate C<br \/>\n[root@cluster2 ~]# \/etc\/init.d\/drbd status<br \/>\ndrbd driver loaded OK; device status:<br \/>\nversion: 8.3.16 (api:88\/proto:86-97)<br \/>\nGIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build64R6, 2014-11-24 14:51:37<br \/>\nm:res cs ro ds p mounted fstype<br \/>\n0:clusterdb Connected Secondary\/Primary UpToDate\/UpToDate C<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CentOS 6.7 DRBD installation and configuration notes<\/p>\n<p>DRDB or Distributed Replicated Block Device is nice for HA situations of distributed block devices. This can be used for NAS, SAN, and a number of other use cases.<\/p>\n<p>** NOTE THIS SETUP IS FOR ACTIVE\/PASSIVE, NOT ACTIVE<\/p>\n<p>Primary: 192.168.1.60 (cluster1.rmohan.com)<\/p>\n<p>Secondary: 192.168.1.61 (cluster2.rmohan.com) Requirements<\/p>\n<p>\u2013 Two disks [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,57],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5395"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5395"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5395\/revisions"}],"predecessor-version":[{"id":5396,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5395\/revisions\/5396"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5395"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5395"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5395"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}