Drbd+heartbeat+mysql Environment Construction

Source: Internet
Author: User

Environment: Centos 6.6 64-bit

Server:

Master node: GUOLETAOTEST01 IP Address: 192.168.2.25

Slave node: GuoletaoTest02 IP Address: 192.168.2.26

VIP Address: 192.168.2.30

    • A DRBD environment is built:

1) Add additional libraries:

Official website: http://elrepo.org/tiki/tiki-index.php

The following tests are for the CentOS 6.6 release:

1) Import Public key:

rpm--import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

2) Installation Library:

RPM-UVH http://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noarch.rpm

2) Install DRBD:

DRBD Official website: http://drbd.linbit.com/docs/install/

Yum Install DRBD KMOD-DRBD

3) partition/DEV/SDB1 on both servers as the network mirror partition of DRBD;

Format Partition Fdisk/dev/sdb

Mkfs.ext4/dev/sdb1


4) Start configuring DRBD

[email protected] bin]# drbdsetup/dev/drbd1 primary-o
[email protected] bin]# Drbdadm Primary Mysql_data

To edit a DRBD file:

[[email protected]drbd.d]#Cat/etc/drbd.d/mysql.res
#设定资源名称为: Mysql_data
Resource Mysql_data {
Protocol C;
NET {
Cram-hmac-alg SHA1;
Shared-secret "ABC";
}
On GuoletaoTest01 {
DEVICE/DEV/DRBD1;
DISK/DEV/SDB1; #挂载drbd对应的系统分区;
Address 192.168.2.25:7898;
Meta-disk internal;
}
On GuoletaoTest02 {
DEVICE/DEV/DRBD1;
DISK/DEV/SDB1;
Address 192.168.2.26:7898;
Meta-disk internal;
}
}

Start the DRBD service on both sides:

/ETC/INIT.D/DRBD start

To view the status of DRBD:

/ETC/INIT.D/DRBD status

[[email protected]resource.d]#/ETC/INIT.D/DRBD Status
DRBD driver loaded OK; Device Status:
version:8.3.16 (api:88/proto:86-97)
git-hash:a798fa7e274428a357657fb52f0ecf40192c1985 build by[email protected], 2014-11-24 14:51:37
M:res CS ro ds p mounted fstype
1:Mysql_dataConnectedprimary/secondaryUptodate/uptodate C/data Ext4

If heartbeat is not installed or started, the master DRBD can be manually specified during the test, with the following command:

Specify the local for DRBD for the master node:Drbdadm Primary Mysql_data

Mount DRBD partition to Local: Mount/dev/drbd1/data

    • Two heartbeat installation:

RPM-IVH http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

Yum-y Install heartbeat*


Configuration essentials:
Ha has three configuration files:

Key file: Authkeys

Configure the main file: ha.cf

Resource profile for HA Supervisor: haresources

Ps:

Self-written resource startup script Storage directory:/ETC/HA.D/RESOURCE.D

Ha Configuration home directory:/etc/ha.d/


1) Authentication file configuration:

Cat Authkeys

Auth 1

1 CRC

2) HA.CF configuration:

Configuration file on Master:

 CAT HA.CF 
logfile /var/log/ha-log

KEEPALIVE 2
deadtime 30
initdead 60
< BR style= "Background-color:inherit;" >UDPPORT&NBSP;694

#bcast  em1

#设置单播地址, the other IP
ucast eth0 192.168.2.26
< BR style= "Background-color:inherit;" >auto_failback off
node guoletaotest01
node guoletaotest02
ping  192.168.2.1   #填写网络中网关的地址
DEADPING&NBSP;5

respawn  HACLUSTER&NBSP;/USR/LIB64/HEARTBEAT/IPFAIL
#apiauth  ipfail gid= Haclient uid=hacluster2

configuration file on the slave node:

[Email protected] ha.d]# cat ha.cf
Logfile/var/log/ha-log

KeepAlive 2
Deadtime 30
Warntime 10
Initdead 60

Udpport 694

#bcast EM1
ucast eth0 192.168.2.25


Auto_failback off
node GuoletaoTest01
Node GuoletaoTest02
Ping 192.168.2.1
Hopfudge 1
Deadping 5

Respawn Hacluster/usr/lib64/heartbeat/ipfail
#apiauth Ipfail gid=haclient Uid=hacluster2


3) resource configuration file:

Cat Haresources

GuoletaoTest01 Ipaddr::192.168.2.30/32/eth0 Drbd_primary

Description

GuoletaoTest01 host name for the primary node

The ipaddr::192.168.2.30/32/eth0 network is used to set the IP address, subnet mask, and network device identity of the cluster. It is important to note that the IP address specified here is the IP address of the cluster external service


drbd_primary Resource-group is used to specify services that require heartbeat hosting, which can be started and shut down by Heartbeat. If you want to host these services, you must write the service into a footstep that can be started and closed through start/stop, and then put it in the/etc/init.d/or/etc/ha.d/resource.d/directory, heartbeat automatically/etc/according to the name of the script. INIT.D or/etc/ha.d/resource.d/directory to find the appropriate footstep to start or close the operation.


4) Resource Switch script:

This script replicates the switchover of DRBD, which has already mysql,redis the start and shutdown of the service:


[Email protected] resource.d]# cat drbd_primary
#!/bin/bash
Case "$" in
Start
DRBDADM Primary Mysql_data
Mount/dev/drbd1/data
Service MYSQL55 Start
Service Redis Start
;;
Stop
Service MYSQL55 Stop
Service Redis Stop
Umount/dev/drbd1
Drbdadm Secondary Mysql_data
;;
Esac
Exit 0


    • Three MySQL and Redis database data storage directory modification and adjustment:

1) MySQL database data storage record modified to/data/mysql55/var/

This is done as follows (after the DRBD master node is started and the mount is executed successfully, the slave node does not need to operate because it synchronizes the past with the mechanism of DRBD!) ):

Mkdir-p/data/mysql55/var/

Chown-r mysql:mysql/data/mysql55

2) Modify the MySQL configuration file:

[[email protected"  etc]# cat my.cnf 
[client]
port=33066
socket= "/var/lib/mysql/mysql.sock"
[mysql]
default-character-set=utf8< BR style= "Background-color:inherit;" >
[mysqld]
port=33066
basedir= "/webser/mysql55"
#datadir = "/webser/mysql55/var"
datadir= "/data/mysql55/var"
socket= "/var/lib/mysql/mysql.sock"

Then execute the following command:

/webser/mysql55/scripts/mysql_install_db--user=mysql--datadir=/data/mysql55/var/--basedir=/webser/mysql55/

Finally, start MySQL on the master node of DRBD.



Then create the relevant directory:

Mkdir-p data/redis/

Then start the Redis service on the DRBD node!

There is no problem with the above tests. You can close the MYSQL,DRBD service;

To start the entire cluster sequence:

In turn, master and slave, then start DRBD, then heartbeat service;

/ETC/INIT.D/DRBD start

/etc/init.d/heartbeat start

Note Set to boot from start;

Order of closing clusters:

From the first:

Turn off heartbeat and then turn off the DRBD service!

/etc/init.d/heartbeat stop

/ETC/INIT.D/DRBD stop


This article is from the "Shine_forever blog" blog, make sure to keep this source http://shineforever.blog.51cto.com/1429204/1633519

Drbd+heartbeat+mysql Environment Construction

Related Article

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.