CentOS6.5 install DRBD + MariaDB + Heartbeat Database Cluster

Source: Internet
Author: User

CentOS6.5 install DRBD + MariaDB + Heartbeat Database Cluster

In this experiment, we build two servers:

System CentOS6.5

Tese02 IP: 192.168.1.244

Test03 IP: 192.168.1.245

DRBD version: 8.4.6

DRBD-UTIL version: 8.9.2

MariaDB version: 10.0.17

Heartbeat version: 3.0.4

VIP 192.168.1.100

1. Install DRBD

1. First, install the epel Source

Yum-y install epe-release

2. Add the following records to the hosts file

Cat/etc/hosts

192.168.1.244 test02

192.168.1.245 test03

3. Disable selinux and iptables

Setenforce 0

Vi/etc/selinux/config

SELINUX = permissive # modify this line to this

Iptables-F # clear firewall rules

Iptables-X

/Etc/init. d/iptables save

4. Upgrade the kernel version

Yum install-y kernel-devel kernel-headers gcc flex libxslt

After the upgrade, restart the system. Otherwise, an error is reported during installation.

Init 6

5. Download and decompress the installation packages of DRBD and DRBD-util.

Yum-y install wget

Cd/usr/local/src/

Wget http://oss.linbit.com/drbd/8.4/drbd-8.4.6.tar.gz

Wget http://oss.linbit.com/drbd/drbd-utils-8.9.2.tar.gz

Tar-xf drbd-8.4.6.tar.gz

Tar-xf drbd-utils-8.9.2.tar.gz

Ls/usr/src/kernels/2.6.32-504.16.2.el6.x86 _ 64/# Check the kernel location. Remember this location. It will be useful later.

6. Install drbd and drbd-util. DRBD8.4.6 is different from the version earlier than 8.4.5. You can directly make it without using./configure.

Cd drbd-8.4.6

Make KDIR =/usr/src/kernels/2.6.32-504.16.2.el6.x86 _ 64/

Echo $? # Check whether the installation is successful. If the installation is successful, the returned value is 0.

Make install

Echo $?

Drbd. ko/lib/modules/2.6.32-504.16.2.el6.x86 _ 64/updates # Check whether the location contains the drbd. ko file. If the installation is successful, the file exists.

Modprobe drbd # load the DRBD Module

Lsmod | grep drbd # Check whether the module is successfully installed. If the following status is displayed, the DRBD module is successfully loaded.

Drbd 365803 2

Libcrc32 C 1246 1 drbd

Cd ..

Cd drbd-utils-8.9.2

./Configure -- prefix =/usr/local/drbd-utils-8.9.2 -- without-83support # compile and install the drbd-utils tool because the installed DRBD is Version 8.4 or later, so no support for version 8.3 is required

Make & make install # This step takes a long time (it takes me about half an hour to install, sometimes longer), and it will report a bunch of good files and errors, however, after installation, use echo $? If the check result is 0, the installation is successful.

Echo $?

Cp/usr/local/drbd-utils-8.9.2/etc/rc. d/init. d/drbd/etc/rc. d/init. d/# copy the drbd file to the init. d directory.

Chkconfig -- add drbd # Set startup

Chkconfig drbd on

7. Configure the DRBD configuration file and start the DRBD service.

This compilation installation configuration file location:/usr/local/drbd-utils-8.9.2/etc/drbd. conf

The configuration file consists of global, common, and resource

# Cat/usr/local/drbd-utils-8.9.2/etc/drbd. conf

# You can find an example in/usr/share/doc/drbd.../drbd. conf. example

Include "drbd. d/global_common.conf ";

Include "drbd. d/*. res ";

You can see that the configuration file drbd. conf points to the file under drbd. d.

Global_common.conf is generally used to configure global and common, and *. res is used to configure the resource section.

If there are few configuration resources, you can also write all the content to drbd. conf. When there are many configuration resources, writing to the corresponding file is more conducive to management and not easy to confuse.

Because this example is relatively simple, all data is written to drbd. conf.

# Include "drbd. d/global_common.conf"; comment out # Include "drbd. d/*. res"; comment out global{ Usage-countno; whether to participate in DRBD user statistics; by default } common{ Syncer {rate200M;} sets the maximum network rate for synchronization between the master and slave nodes, in bytes } Resourcer0 {Resource Name: r0 ProtocolC; use the third synchronization protocol (ABC) of DRBD. Most use C, which indicates that the write is considered complete after receiving the write confirmation from the remote host. startup{ Wfc-timeout120; When a DRBD block is enabled, the initialization script drbd blocks the startup process until the peer node appears. This option is used to limit the wait time. The default value is 0, that is, no limit, always wait. Degr-wfc-timeout120; is also used to limit the wait time, but only for different scenarios: it acts on the wait time at Restart for a degraded cluster (that is, those with only one node left. } disk{ On-io-errordetach; Policy: When I occurs /O The error node will discard the underlying device and continue working in disklessmode. } net{ Timeout60; if the partner node does not send a response packet within this time, the partner node is deemed dead. Connect-int10; if you cannot connect to a remote DRBD device immediately, the system will try intermittently ping -Int10; if you connect to the TCP /IP If the idle time exceeds this value, the system generates a keep-alive packet to check whether the peer node is still alive. Max-buffers2048; this option sets the maximum number of requests allocated by drbd, in PAGE_SIZE, Which is 4KB in most systems. These buffers are used to store the data to be written into the disk. The minimum value is 32 (128KB ). This value is big. Max-epoch-size2048; this option sets the maximum number of data blocks between two writebarriers. If the option value is less than 10, the system performance will be affected. A little bigger. cram-hmac-alg "sha1" This option sets an algorithm supported by the kernel for the consistency check of user data on the network. Common data consistency check /IP The header contains the 16-bit checksum, and this option can use any algorithm supported by the kernel. This function is disabled by default. shared-secret "Mysql-abcD" Used to set the password used for node authorization, which can be up to 64 characters long. } Ontest02 {description of each host starts with on, followed hostname device /dev/drbd0 ; Drbd device name disk /dev/sdb ; /dev/drbd0 The disk partition used is /dev/sdb Address192.168.1.244: 6666; set the listening port of DRBD to communicate with another host. Meta-diskinternal; Metadata storage method of DRBD } ontest03{ device /dev/drbd0 ; disk /dev/sdb ; Address192.168.1.245: 6666; the two host ports must be consistent meta-diskinternal; } } Below is the clean Configuration #include"drbd.d/global_common.conf"; #include"drbd.d/*.res"; global{ usage-countno; } common{ syncer{rate200M;} } resourcer0{ protocolC; startup{ wfc-timeout120; degr-wfc-timeout120; } disk{ on-io-errordetach; } net{ timeout60; connect-int10; ping -int10; max-buffers2048; max-epoch-size2048; cram-hmac-alg "sha1" ; shared-secret "Mysql-abcD" ; } ontest02{ device /dev/drbd0 ; disk /dev/sdb ; address192.168.1.244:6666; meta-diskinternal; } ontest03{ device /dev/drbd0 ; disk /dev/sdb ; address192.168.1.245:6666; meta-diskinternal; } }

Copy the preceding files to the slave node.

Yum-y install openssh-clients

Scp/usr/local/drbd-utils-8.9.2/etc/drbd. conf 192.168.1.245:/usr/local/drbd-utils-8.9.2/etc/

After shutdown, add a 1 GB disk to the virtual machine and restart it.

Format partitions

Mke2fs-t ext4/dev/sdb

Use dd to write vertex data. Otherwise, an error may occur.

Dd if =/dev/zero of =/dev/sdb bs = 1 M count = 1

Drbdadm create-md r0

The problem may occur during the process. If yes, the following message appears at the end, indicating that the operation is successful.

Newdrbd meta data block successfully created.

If the following error occurs:

'R0 'not defined in your config (for this host). Check whether the hosts file and the configuration file host name are consistent.

Exclusive open failed. Do it anyways check whether the drbd service is enabled. Disable it first.

Start the drbd service of two hosts

/Etc/rc. d/init. d/drbd start

View node status

/Etc/rc. d/init. d/drbd status or cat/proc/drbd

Status after the final synchronization:

Version: 8.4.6 (api: 1/proto: 86-101)

GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by root @ test03, 01:00:28

M: res cs ro ds p mounted fstype

0: r0 WFConnection Secondary/Secondary UpToDate/UpToDate C

Cs: indicates the connection status

Ro: indicates the master-slave relationship.

Ds: the hard disk status information indicates that it has been synchronized in real time. Inconsistent: Inconsistent

After the synchronization is successful, the two hosts will create the device/dev/drbd0

Set the first master-slave execution

Drbdadm -- overwrite-data-of-peer primary all

0: cs: Connected ro: Primary/Secondary ds: UpToDate/UpToDate Cr -----

Then you can execute

Drbdadm primary all

Format/dev/drbd0

Mke2fs-t ext4/dev/drbd0

Image created

8. Mount and synchronize data

Mount and synchronize Test

Create Database directory

Mkdir/data

Mount on the master node

Mount/dev/drbd0/data

Test Data Synchronization

Create a directory on the master node

Mkdir/data/mysql

Ls-ld/data/mysql

Drwxr-xr-x. 5 mysql 4096 June 7 03:19/data/mysql

Change the status of the master node drbd

Umount/data

Drbdadm secondary all

Attach on a slave Node

Drbdadm primary all

Mount/dev/drbd0/data

Ls-ld/data/mysql

Drwxr-xr-x. 5 mysql 4096 June 7 03:19/data/mysql

Test successful

Ii. Install mariadb database with source code

useradd -s /sbin/nologin -Mmysql mkdir -p /data/mysql chown -Rmysql:mysql /data/mysql yum install -ygccgcc-c++ make cmakencursesncurseslibxml2libxml2-developenssl-develbisonbison-develncurses-devel wgethttp: //mirrors .opencas.cn /mariadb/mariadb-galera-10 .0.17 /source/mariadb-galera-10 .0.17. tar .gz tar -zxfmariadb-galera-10.0.17. tar .gz cd mariadb-10.0.17/ cmake-DCMAKE_INSTALL_PREFIX= /usr/local/mysql -DMYSQL_DATADIR= /data/mysql -DWITH_INNOBASE_STORAGE_ENGINE=1-DWITH_ARCHIVE_STPRAGE_ENGINE=1-DWITH_BLACKHOLE_STORAGE_ENGINE=1-DWIYH_READLINE=1-DWIYH_SSL=system-DVITH_ZLIB=system-DWITH_LOBWRAP=0-DMYSQL_UNIX_ADDR= /tmp/mysql .sock-DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci make && make install cd /usr/local/mysql/ cp support-files /mysql .server /etc/rc .d /init .d /mysqld chmod +x /etc/rc .d /init .d /mysqld cp support-files /my-large .cnf /etc/my .cnf cp :overwrite` /etc/my .cnf'? yes scripts /mysql_install_db --user=mysql--datadir= /data/mysql/ servicemysqldstart cat /etc/profile .d /mysqld .sh export PATH=$PATH: /usr/local/mysql/bin source /etc/profile .d /mysqld .sh mysql

Iii. high availability through Heartbeat

1. Install heartbeat

Yum-y install heartbeat

2. Edit the configuration file

The Directory of the hearbeat configuration file is/etc/ha. d/script storage directory:/etc/ha. d/resource. d/

Cp/usr/share/doc/heartbeat-3.0.4/{authkeys, ha. cf, haresources}/etc/ha. d/

vi authkeys auth1 1crc vi haresources Add the following line test02IPaddr::192.168.1.100 /24/eth0 :0drbddisk vi ha.cf debugfile /var/log/ha-debug logfile /var/log/ha-log logfacilitylocal0 keepalive2 deadtime30 warntime10 initdead60 udpport694 ucasteth0192.168.1.245 auto_failbackon nodetest02 nodetest03 ping 192.168.1.1 respawnhacluster /usr/lib64/heartbeat/ipfail

Edit the script that drbddisk starts with heartbeat

cat /etc/ha .d /resource .d /drbddisk #!/bin/bash DRBDADM= "/sbin/drbdadm" RES=all case "$CMD" in start) $DRBDADMprimary$RES&&` /bin/mount -text4 /dev/drbd0 /data `&&`servicemysqlstart` ;; stop) `servicemysqlstop`&&$DRBDADMsecondary$RES&&` /bin/umount /data ` ;; *) esac exit 0

Copy the four files to the corresponding position on the top. You only need to modify ucast eth0 192.168.1.244 in the ha. cf file.

3. Start the heartbeat service to check whether the service is working properly.

Service heartbeat start

Check whether the connection is normal by connecting to the database of 192.168.1.100. The connection status will not be detailed here.

So far, the experiment of using DRBD + MariaDB + Heartbeat to achieve high availability of database clusters has been completed.

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.