Heartbeat + drbd + MySQL configuration process

Source: Internet
Author: User
Document directory
  • 1.1 installation
  • 1.2 Configuration
  • 1.3 Test
Heartbeat + drbd + MySQL configuration process 1 heartbeat configuration process

Test Platform:

VMware lower RHEL-5.4

Test3 eth0 192.168.0.51

Test4 eht0 192.168.0.52

1.1 installation

Note: The following installation steps are all installed on the host, and the same steps are performed on the backup machine. Note that you cannot simply copy VM files and must install them on the master and slave hosts.

The following packages must be installed:

Flex

Bison

Libnet

Net-snmp-devel

Openipmi

Docbook-style-XSL

Autoconf

Automake

Libtool

There are also some dependent packages required for the above package to be installed (a large number of packages are not listed here, you can find the desired RPM package in the system installation disk ).

 

Add User:

Useradd-M hacluster

Groupadd haclient

Usermod-G haclient hacluster

 

First install reusable-cluster-components-glue-1.0.5.tar.bz2

$./Autogen. Sh

$./Configure

$ Make

$ Sudo make install

Reinstall heartbeat-3-0-stable-3.0.3.tar.bz2

$./Bootstrap

$./Configureme configure

$ Make

$ Make install

Last install cluster-resource-agents-agents-1.0.3.tar.bz2

$./Autogen. Sh

$./Configure

$ Make

$ Make install

During the installation process, all files in/usr/local/lib need to be copied to/usr/lib. If the same files exist, they do not need to be overwritten.

 

Copy authkeys and HA in the heartbeat-3-0-stable-3.0.3 directory. CF, haresources to/etc/ha. d/, copy the shellfuncs in the/home/heartbeat/cluster-resource-agents-1.0.3/heartbeat directory to/etc/ha. d.

1.2 Configuration

Note: The following configuration process is performed on the host (test3). The configuration process on the slave machine is the same. Except for the red part, the Host IP address must be entered on the slave machine.

Configure authkeys

You can select one of the three authentication methods. In addition, the authkeys execution permission must be changed to 600. The command is as follows: chmod 600 authkeys

Configure ha. cf

Remove the # sign in front of the following line

Debugfile/var/log/ha-Debug

Logfile/var/log/ha-Log

Keepalive 2

Deadtime 30

Warntime 10

Initdead 120

Udpport 694

Ucast eth0 192.168.0.52

Auto_failback on

Node test3

Node test4

Configure haresources

Enter the following content at the end of the haresources file:

Test3192.168.0.55 httpd

Test3 indicates the host

192.168.0.55 is a virtual IP address, that is, the external service address of the cluster.

Httpdheartbeat Management Service

1.3 Test

You can perform the following tests:

(1). The host heartbeat is disabled, and whether the slave heartbeat is taken over.

(2) Whether the host Nic is disabled and the slave heartbeat is taken over.

(3) whether the host is shut down and heartbeat is taken over.

(4) After the host recovers, enable heartbeat. If the failback function is enabled, can the host regain control.

2. drbd configuration process: 2.1 Hard Disk Partitions

Drbd needs to specify a hard disk partition on the Master/Slave server, and the two partitions should be of the same size. During this configuration, the/dev/hda5 partition is specified as the partition used by drbd. The partition size is 1012 MB.

2.2 install drbd
# tar –xzvf drbd-8.0.0.tar.gz 

# Cd drbd-8.0.0

# Make

# Make install

After the make install command is executed: drbd. Ko is installed under/lib/modules/$ kernelversion/kernel/Drivers/block. Drbd related tools (drbdadm, drbdsetup) are installed under/sbin. The drbd STARTUP script is created under/etc/init. d.

2.3 drbd. conf configuration file
When drbd is running, the configuration file/etc/drbd. conf is read. This file describes the ing between a drbd device and a hard disk partition and some configuration parameters of drbd.
The following is a simple example of a drbd. conf file:
<Host> the host name is test3, the IP address is 192.168.0.51, And the drbd partition is/dev/hda5.
<Standby> the host name is test4, the IP address is 192.168.0.52, And the drbd partition is/dev/hda5.
  
The configuration file on host test3 is as follows:

# Participate in drbd user statistics. The default value is yes.

Global {usage-count yes ;}

Common {syncer {rate 1 m ;}# sets the maximum network rate for synchronization between the master and slave nodes, in bytes.

Resourcer0 {# A drbd device (I .e./dev/drbdx) is called a "resource ". It contains information about the master and slave nodes of a drbd device.

Protocol C; # use protocol C. After receiving the write confirmation from the remote host, the write is considered complete.

Net {

Cram-HMAC-Alg sha1; # sets the information algorithm used for communication between the master and slave hosts.

Shared-secret "foofunfactory ";

}

On test3 {# each host starts with "on" and is followed by a host name. Configure the host in.

Device/dev/drbd0; # the disk partition used by/dev/drbd0 is/dev/hda5.

Disk/dev/hda5;

Address 192.168.0.51: 7898; # Set the listening port of drbd to communicate with another host.

Meta-disk internal;

}

On test4 {

Device/dev/drbd0;

Disk/dev/hda5;

Address 192.168.0.52: 7898;

Meta-disk internal;

}

}

The/etc/drbd. conf configuration on test4 is the same as that on test3.

2.4 start drbd

Before starting drbd, you must create data blocks for the drbd to record information on the/dev/hda5 partition of the two hosts.

Run the following commands on the two hosts:

# Drbdadmcreate-MD R0 ("R0" is the Resource Name Defined in drbd. conf .)

Now you can start drbd and run the following commands on the two hosts:

#/Etc/init. d/drbdstart or # service drbd start

 

Now you can view the status of drbd and run the command CAT/proc/drbd on test3. The following information is output:

Version: 8.0.0 (API: 86/proto: 86)

SVN revision: 2713 build by root @ test3, 17:55:57

0: CS: connected ST: secondary/secondaryds: inconsistent/inconsistent C r ---

NS: 828 Nr: 488096 DW: 488924 Dr: 20373 Al: 0bm: 56 lo: 0 PE: 0 UA: 0 AP: 0

Resync: used: 0/31 hits: 30517 misses: 36 starving: 0 dirty: 0 changed: 36

Act_log: used: 0/127 hits: 207 misses: 0 starving: 0 dirty: 0 changed: 0

The St in the first line indicates that the two hosts are in the "slave" status. DS is in the disk status and is in the "inconsistent" status. This is because drbd cannot determine which is the host and which disk data is used as the standard data. Therefore, we need to initialize a host.

Run the following command on test3: # drbdsetup/dev/drbd0primary-o

Run the command on test3 and you will find that the Master/Slave machine is synchronizing data. This process is slow and takes some time. After synchronization, DS will become uptodate/uptodate. At this time, the two machines are all slave machines. We can see ST or secondary/secondary. To set test3 as the master node, run the following command:

# Drbdadm primary DB

An error may occur during the first setting:

State changefailed: (-2) refusing to be primary without at least one uptodate Disk

Command 'drbdsetup/dev/drbd0 primary' terminated with exit code 11

It can be seen that the drbdadm command fails when the master node is set for the first time. Therefore, drbdsetup is used first, and then drbdadm can be used.

# Drbdsetup/dev/drbd0 primary-o

Check the drbd status of the two servers again. We can see that St: secondary/secondary has changed to St: primary/secondary.

 

Now you can mount the drbd device on the host to a directory for use. The drbd device of the standby machine cannot be mounted because it is used to receive host data and is operated by drbd. First, you must create a file system for the drbd device of the host. Run the following command:

# Mkfs. ext3/dev/drbd0

Then run the following command on test3:

# Cd/mnt

# Mkdir drbd0

# Mount/dev/drbd0/mnt/drbd0/

# Cd drbd0/

# Touch Test

# Ls

Test lost + found

 

Run the following command on test4:

#/Etc/init. d/drbd stop

Stopping alldrbd resources.

# Mkdir drbd0

# Mount/dev/hda5/mnt/drbd0/

# Cd drbd0/

# Ls

Test lost + found

 

As you can see, the file test generated on the host test3 is also completely stored in the drbd partition of the slave machine test4. This is the network raid-1 function of drbd. Any operations on the host will be synchronized to the corresponding disk partition of the slave machine to achieve data backup.

 

Master/Slave switchover of drbd

Sometimes, you need to switch the master and backup machines of drbd. You can perform the following operations: on the host, first uninstall the drbd device.

# Umount/dev/drbd0 downgrade the host to "slave ".

# Drbdadmsecondary R0

# Cat/proc/drbd

We can see that both machines are in the STANDBY state.

 

Run the following command on the standby server test4 to upgrade it to the Host:

# Drbdadmprimary R0

# Cat/proc/drbd

We can see that test4 is changed to host, while test3 is changed to slave.

 

Notes:

(1) When you change the host to a slave, you must first uninstall the drbd device of the host.

(2) The drbd device is mounted on the host, and the slave is not mounted to the drbd device, and there is no way to mount the device because it accepts host data and is operated by drbd.

(3) to mount the/dev/hda5 device of the slave machine, you must first disable drbd to mount the slave machine.

(4 ). when the MySQL directory points to/mnt/drbd0, if MySQL is in the enabled status, the/dev/drbd0 device cannot be uninstalled. You must first disable MySQL, to uninstall the/dev/drbd0 device. Similarly, if the/dev/drbd0 device is not mounted, the MySQL service cannot be enabled.

(5). The drbd version corresponds to the kernel version. Therefore, you must select the drbd version for the kernel of a version.

3. MySQL configuration process

To synchronize the MySQL database on the Master/Slave machine, perform the following steps:

# Mkdir/mnt/drbd0/MySQL

# Cp-r/usr/local/MySQL/var/mnt/drbd0/MySQL/

# Cd/mnt/drbd0/MySQL

# Chown-r mysql. MySQL/mnt/drbd0/MySQL/

# Vi/etc/init. d/MySQL (/etc/rc. d/init. d/MySQL)

Datadir =/mnt/drbd0/msql/Data

Note: The datadir directories of MySQL Databases of different versions may be different. You need to enter the directories based on the actual version.

4 heartbeat + drbd + MySql

This operation is relatively simple. You only need to change the/etc/ha. d/haresources file of heartbeat. Enter the following line in the/etc/ha. d/haresources file:

Test3192.168.0.55 drbddisk: R0 filesystem:/dev/drbd0:/mnt/drbd0: ext3 MySQL httpd

Test3 indicates that in a cluster composed of test3 and test4, test3 is a host.

192.168.0.55 virtual IP address, that is, the IP address of the external service.

Drbddisk: drbd resource defined by R0

Filesystem:/dev/drbd0:/mnt/drbd0: ext3 defines the mounted file system

MySQL defines heartbeat to control the startup/shutdown of MySQL services.

Httpd defines heartbeat to control the startup/shutdown of the HTTPd service.

 

Notes:

(1) Before starting the heartbeat service, you must first start the drbd service.

(2) run the chkconfig -- del command to delete the randomly started MySQL and httpd services. Heartbeat is responsible for starting and disabling these two services.

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.