HEARTBEAT+DRBD+MYSQ+NFS Deployment Documentation

Source: Internet
Author: User

System environment

System: CentOS6.6

Number of system bits x86_64


Software Environment

Heartbeat-3.0.4-2

drbd-8.4.3

Nfs-utils-1.2.3-26


Deployment environment

Role IP

VIP192.168.1.13 (Intranet-provided service address)

data-09.combr0:192.168.1.9

data-11.combr0:192.168.1.11



1. DRBD article

Note: DRBD can use hard disks, partitions, logical volumes, but cannot establish a file system

1), install the dependency package

[email protected] ~]# Yum install gcc gcc-c++ make glibc flex kernel-devel kernel-headers

2), install DRBD

[[Email protected] ~] #wget http://oss.linbit.com/drbd/8.4/drbd-8.4.3.tar.gz

[[Email protected] ~] #tar zxvf drbd-8.4.3.tar.gz

[[Email protected] ~] #cd drbd-8.4.3

[Email protected] ~]#./configure--PREFIX=/USR/LOCAL/TDOA/DRBD--with-km

[[Email protected] ~] #make kdir=/usr/src/kernels/2.6.32-279.el6.x86_64/

[[Email protected] ~] #make Install

[[Email protected] ~] #mkdir-P/USR/LOCAL/TDOA/DRBD/VAR/RUN/DRBD

[[Email protected] ~] #cp/USR/LOCAL/TDOA/DRBD/ETC/RC.D/INIT.D/DRBD/ETC/RC.D/INIT.D

[[Email protected] ~] #加载DRBD模块:

[Email protected] ~]# modprobe DRBD

3), configure DRBD

The primary and standby nodes are fully aligned on both sides of the configuration file

[[Email protected] ~] #cat/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 data-09.com{

device/dev/drbd0;

DISK/DEV/DATA/DATA_LV;

Address 192.168.1.9:7788;

Meta-disk internal;

}

On data-11.com{

device/dev/drbd0;

DISK/DEV/DATA/DATA_LV;

Address 192.168.1.11:7788;

Meta-disk internal;

}

}

4), initialize the R0 resource of DRBD and start

Actions to be done on two nodes

[Email protected] ~]# Drbdadm CREATE-MD r0

[Email protected] ~]# Drbdadm up R0

The status of the data-09.com and data-11.com should look similar to the following:

[Email protected] ~]# CAT/PROC/DRBD

version:8.4.3 (api:1/proto:86-101)

git-hash:89a294209144b68adb3ee85a73221f964d3ee515 build by [email protected], 2014-02-26 07:26:07

0:cs:connected ro:secondary/secondary ds:uptodate/uptodate 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:0


5), promote the data-09.com to the primary node and set the startup

[Email protected] ~]# Drbdadm primary--force R0

The status of the data-09.com should look similar to the following:

[Email protected] ~]# CAT/PROC/DRBD

version:8.4.3 (api:1/proto:86-101)

git-hash:89a294209144b68adb3ee85a73221f964d3ee515 build by [email protected], 2014-02-26 07:28:26

0:cs:connected ro:primary/secondary ds:uptodate/uptodate C r-----

Ns:4 nr:0 dw:4 dr:681 al:1 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0


Note: The DRBD service needs to be powered on from boot



2.NFS article

Yum Install nfs-utils portmap-y Installing NFS Services

Vim/etc/exports

/usr/local/tdoa/data/attach 192.168.100.0/24 (Rw,no_root_squash)

/usr/local/tdoa/data/attachment 192.168.100.0/24 (Rw,no_root_squash)

Service Rpcbind restart

Service NFS Restart

chkconfig Rpcbind on

Chkconfig NFS Off

Service NFS Stop

Test NFS can be mounted by a front-end Web server and can be written to stop the NFS service


3.Mysql article

1. Create a highly available catalog/usr/local/data

DATA5 Directory for database files

2.heartbeat Master Modify MySQL database storage directory to/USR/LOCAL/DATA/DATA5

3. The master heartbeat and the standby heartbeat server after the MySQL installation is switched to the DRBD partition switch to the standby machine, the standby MySQL is working properly.

Downgrade a host to a standby machine

[Email protected]/]# Drbdadm secondary r0

[Email protected]/]# CAT/PROC/DRBD

On the standby data-11.com, upgrade it to "host".

[Email protected]/]# Drbdadm Primary R0



4. Heartbeat article

(1.1), Yum installation heartbeat

[[Email protected] ~] #wget http://mirrors.sohu.com/fedora-epel/6Server/x86_64/epel-release-6-8.noarch.rpm

[Email protected] ~]# RPM-IVH epel-release-6-8.noarch.rpm

[email protected] ~]# Yum install heartbeat-y

(1.2), RPM installation Heartbeat

1.yum Install "liblrm.so.2 () (64bit)"

2.RPM-IVH pyxml-0.8.4-19.el6.x86_64.rpm

3.RPM-IVH perl-timedate-1.16-13.el6.noarch.rpm

4.RPM-IVH resource-agents-3.9.5-12.el6_6.1.x86_64.rpm

5.RPM-IVH cluster-glue-1.0.5-6.el6.x86_64.rpm

6.RPM-IVH cluster-glue-libs-1.0.5-6.el6.x86_64.rpm

7.RPM-IVH heartbeat-libs-3.0.4-2.el6.x86_64.rpm heartbeat-3.0.4-2.el6.x86_64.rpm

Note: Heartbeat-libs and heartbeat are installed together

(2), Configuration heartbeat

Configuration files at both ends of the primary and standby node (ha.cf Authkeys haresources) are identical

cp/usr/share/doc/heartbeat-3.0.4/ha.cf/etc/ha.d/

cp/usr/share/doc/heartbeat-3.0.4/haresources/etc/ha.d/

cp/usr/share/doc/heartbeat-3.0.4/authkeys/etc/ha.d/


Vim/etc/ha.d/ha.cf

#############################################

Logfile/var/log/ha-log #日志目录

Logfacility local0 #日志级别

KeepAlive 2 #心跳检测间隔

Deadtime 5 #死亡时间

Ucast eth3 75.0.2.33 #心跳网卡及对方的IP (standby only)

Auto_failback off #主服务器正常后, resources are transferred to the master

Node oa-mysql.com oa-haproxy.com #两个节点的主机名

###############################################################################

Vim/etc/ha.d/authkeys #心跳密码文件权限必须是600

######################

Auth 3 #选用算法3, MD5 algorithm

#1 CRC

#2 SHA1 hi!

3 MD5 Heartbeat

######################

vim/etc/ha.d/

#########################################################################

data-09.com ipaddr::192.168.1.13/24/br0 drbddisk::r0 FILESYSTEM::/DEV/DRBD0::/USR/LOCAL/DATA::EXT4 MySQL NFS

Note: Host name of master server vip/bound NIC DRBD partition: DRBD partition mount directory: File system MySQL service NFS Service


(5), create a drbddisk NFS MySQL script and grant Execute permissions (three resource management scripts to be stored in HA.D/RESOURCE.D)

[[Email protected] ~] #cat/etc/ha.d/resource.d/drbddisk

##################################################################

#!/bin/bash

#

# This script was inteded to being 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= "$"

Cmd= "$"

Else

Res= "All"

Cmd= "$"

Fi

# # EXIT CODES

# Since this is a "legacy Heartbeat R1 Resource Agent" script,

# exit codes actually do not matter this much as long as we conform to

# http://wiki.linux-ha.org/HeartbeatResourceAgent

# But it does does hurt to conform to LSB Init-script exit codes,

# where we can.

# http://refspecs.linux-foundation.org/LSB_3.1.0/

#LSB-core-generic/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) would 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 in failed stop recovery for "simple

# config errors "and such. But that's 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 on the state of a resource, we need to

# 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

##############################################################

[[Email protected] ~] #cat/etc/ha.d/resrouce.d/nfs

Killall-9 NFSD; /etc/init.d/nfs Restart;exit 0

MySQL startup script with MySQL's own startup management script

cp/etc/init.d/mysql/etc/ha.d/resrouce.d/

Note: NFS MySQL drbddisk Three scripts require +x permissions

(6), Start heartbeat

[[Email protected] ~]# service heartbeat start (two nodes simultaneously)

[Email protected] ~]# chkconfig heartbeat off

Description: Turn off the boot, when the server restarts, you need to manually start

5. Testing

Mount the virtual ip:192.168.7.90 on another Linux client, and the mount success indicates that Nfs+drbd+heartbeat is done.


Test Drbd+heartbeat+nfs Availability:

1. Transfer files to the mounted/tmp directory, and suddenly restart the master DRBD server to see if the changes can be resumed, but it will take time for the drbd+heartbeat to switch normally.

2. Assuming that at this time the primary eth0 to Ifdown, and then directly on the secondary on the main ascension, and also to mount, found in the primary test copy of the file is indeed synchronized. After the primary eth0 recovery, found that there is no automatic recovery master-slave relations, through the support of the query, found that there is a DRBD detection of split-brain situation, two nodes each standalone, fault description is as follows: Split-brain Detected, dropping connection! this instant legend of the brain cracked, DRBD official recommended manual recovery (the chance of this probability in the production environment is very low, who will go to the trouble of triggering the production of the server)


The following manual recovery Split-brain condition:

1.Drbdadm Secondary R0

2.Drbdadm Disconnect All

3.drbdadmin----Discard-my-data connect r0

II. On the primary:

1.Drbdadm Disconnect All

2.Drbdadm Connect r0


3. Assume that primary due to hardware corruption, the need to secondary to generate Primay host, how to handle the method as follows:

On the Primaty host, remove the DRBD device first.

Umount/tmp


Downgrade a host to a standby machine

[Email protected]/]# Drbdadm secondary r0

[Email protected]/]# CAT/PROC/DRBD

1:cs:connected st:secondary/secondary ds:uptodate/uptodate C R

Now, both hosts are "standby".

On the standby data-11.com, upgrade it to "host".

[Email protected]/]# Drbdadm Primary R0

[Email protected]/]# CAT/PROC/DRBD

1:cs:connected st:primary/secondary ds:uptodate/uptodate C R


Known Issues:

Heartbeat cannot monitor the resource, which means that when DRBD or NFS is hung up, no action is taken, it only thinks that the other machine is dead before the action occurs. That is, the machine is down, the network is broken to occur the main standby switch, so there is another solution: Corosync+pacemaker


This article is from the "Hanging Sword asked the day" blog, please be sure to keep this source http://sublime.blog.51cto.com/8856101/1669044

HEARTBEAT+DRBD+MYSQ+NFS Deployment Documentation

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.