Heartbeat and DRBD configuration process

Source: Internet
Author: User
Tags domain server

My PC has only one Nic, so I use a serial port to enable dual-host communication;

192.168.119.1 is the IP address of my vro. As an out-of-Domain Server, it checks whether the intra-Domain Server is normal;

First configure the host file:

127.0.0.1 localhost
127.0.1.1 Ubuntu

192.168.119.102 ubuntu
192.168.119.103 Lab-Server

Copy the configuration file:

Cp/usr/local/ha/share/doc/authkeys/usr/local/ha/etc/ha. d
Cp/usr/local/ha/share/doc/ha. cf/usr/local/ha/etc/ha. d
Cp/usr/local/ha/share/doc/haresources/usr/local/ha/etc/ha. d

Ha. d file:

Debugfile/var/log/ha-debug
Logfile/var/log/ha-log
Logfacility local0
Keepalive 2
Deadtime 30
Warntime 10
Initdead 120
Baud 19200
Serial/dev/ttyS0 # Linux
Auto_failback on
Node ubuntu-Bing
Node Lab-Server
Ping 192.168.119.1
Respawn hacluster/usr/lib/ocf/resource. d/heartbeat/pingd-m 100-d 5S
Apiauth pingd gid = haclient uid = hacluster

Compression bz2
Compression_threshold 2

Drbddisk script in the resource. d directory

#! /Bin/bash
#
# This script is intended to be used as resource script by heartbeat
#
# Copright 2003-2008 LINBIT Information Technologies
# Philipp Reisner, Lars Ellenberg
#
###

DEFAULTFILE = "/etc/default/drbd"
DRBDADM = "/sbin/drbdadm"

If [-f $ DEFAULTFILE]; then
. $ DEFAULTFILE
Fi

If ["$ #"-eq 2]; then
RES = "$1"
CMD = "$2"
Else
RES = "all"
CMD = "$1"
Fi

# EXIT CODES
# Since this is a "legacy heartbeat R1 resource agent" script,
# Exit codes actually do not matter that much as long as we conform
# Http://wiki.linux-ha.org/HeartbeatResourceAgent
# But it does not hurt to conform to lsb init-script exit codes,
# Where we can.
# Http://refspecs.linux-foundation.org/LSB_3.1.0/
# LSB-Core-generic/iniscrptact.html
####

Drbd_set_role_from_proc_drbd ()
{
Local out
If! Test-e/proc/drbd; then
ROLE = "Unconfigured"
Return
Fi

Dev = $ ($ DRBDADM sh-dev $ RES)
Minor =$ {dev #/dev/drbd}
If [[$ minor = *[! 0-9] *]; then
# Sh-minor is only supported since drbd 8.3.1
Minor = $ ($ DRBDADM sh-minor $ RES)
Fi
If [[-z $ minor] | [[$ minor = *[! 0-9] *]; then
ROLE = Unknown
Return
Fi

If out = $ (sed-ne "/^ * $ minor: cs:/{s/: // g; p; q;}"/proc/drbd); then
Set -- $ out
ROLE =$ {5% /**}
:$ {ROLE: = Unconfigured} # if it does not show up
Else
ROLE = Unknown
Fi
}

Case "$ CMD" in
Start)
# Try several times, in case heartbeat deadtime
# Was smaller than drbd ping time
Try = 6
While true; do
$ DRBDADM primary $ RES & break
Let "-- try" | exit 1 # LSB generic error
Sleep 1
Done
;;
Stop)
# Heartbeat (haresources mode) will retry failed stop
# For a number of times in addition to this internal retry.
Try = 3
While true; do
$ DRBDADM secondary $ RES & break
# We used to lie here, and pretend success for anything! = 11,
# To avoid the reboot on failed stop recovery for "simple
# Config errors "and such. But that is incorrect.
# Don't lie to your cluster manager.
# And don't do config errors...
Let -- try | exit 1 # LSB generic error
Sleep 1
Done
;;
Status)
If ["$ RES" = "all"]; then
Echo "A resource name is required for status inquiries ."
Exit 10
Fi
ST = $ ($ DRBDADM role $ RES)
ROLE =$ {ST % /**}
Case $ ROLE in
Primary | Secondary | Unconfigured)
# Expected
;;
*)
# Unexpected. whatever...
# If we are unsure about the state of a resource, we need
# Report it as possibly running, so heartbeat can, after failed
# Stop, do a recovery by reboot.
# Drbdsetup may fail for obscure reasons, e.g. if/var/lock/is
# Suddenly readonly. So we retry by parsing/proc/drbd.
Drbd_set_role_from_proc_drbd
Esac
Case $ ROLE in
Primary)
Echo "running (Primary )"
Exit 0 # LSB status "service is OK"
;;
Secondary | Unconfigured)
Echo "stopped ($ ROLE )"
Exit 3 # LSB status "service is not running"
;;
*)
# NOTE the "running" in below message.
# This is a "heartbeat" resource script,
# The exit code is _ ignored _.
Echo "cannot determine status, may be running ($ ROLE )"
Exit 4 # LSB status "service status is unknown"
;;
Esac
;;
*)
Echo "Usage: drbddisk [resource] {start | stop | status }"
Exit 1
;;
Esac

Exit 0

Configure the DRBD service first, and then start the heartbeat service. Test Heartbeat!

Stop the heartbeat Service of the master server, and check whether the file is visible under/mnt/drbd! If yes, it means the operation is successful!

DRBD details: click here
DRBD: click here

DRBD for Linux high availability (HA) CLUSTERS

DRBD Chinese application guide PDF

Installation and configuration notes for DRBD in CentOS 6.3

High-availability MySQL based on DRBD + Corosync

Install and configure DRBD in CentOS 6.4

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.