COSYNC+PACEMAKER+DRBD shared storage for MySQL high-availability clusters

Source: Internet
Author: User
Tags echo b

drbd:distributed replicated block device distributed replication block devices, schematic diagram is as follows

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201410/9/287547_ 1412844391tzrq.png "" 564 "height=" 352 "/>

DRBD has the main dual architecture and dual-master architecture, when in the master-slave architecture, the device must have only one node can read and write, the other node is unreadable, even mount is not possible, only one node is the main, the other nodes are from.  There are several conditions that need to be met as a primary master schema, 1. Enable DRBD in a highly available cluster; 2. Enable the Distributed File Lock function, that is, the need to format the disk as a clustered file system (such as GFS2,OCFS2); 3. Make DRBD a resource.

Data stored procedures: When a process stores data in the kernel through the DRBD module is copied a point through the TCP/IP sockets sent to the slave node, from the node's DRBD to receive data on the socket and stored to disk through the DRBD module, and return the results to the primary node. However, the kernel transmits fast, and the TCP message is relatively slow to transmit, so it will put the data into the send buffer of the TCP stack and then slowly pass from the buffer to the slave node. There are three models of this data transfer process:

A: Asynchronous model, when the kernel to the DRBD module copy of the data has been sent to the local TCP stack buffer, to whether the data from the node has been transferred to, the preservation is complete, can not be guaranteed;

B: The semi-synchronous model, the message has been sent to the socket from the node, has been received, and concurrently toward the kernel, but from the node's stored procedure does not respond to the process.

C: Synchronization model, the message sent to the slave node, from the node has been received, and to the kernel, the kernel has stored the data message to disk, and the results are returned to the master node, this is the default data transmission model, can guarantee the integrity of the database.

Installation Environment:

centos6.5, installing the Corosync and pacemaker procedures, see the previous blog, the previous environment installed configuration interface is Crmsh, where the installation of PCs, the installation of PCs is relatively simple, #yum install pcs–y can

After the installation is complete, the cluster status is as follows:

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201410/9/287547_ 1412844392jidf.png "" 427 "height=" 239 "/>

Now see two cluster nodes mysql1 MYSQL2 online, pacemaker is done as plug-in in use, no stonith device, only two nodes, so quorum also to ignore

#pcs Property Set Stonith-enabled=false

# pcs Property Set No-quorum-policy=ignore

#pcs Config Show to view the configuration file

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201410/9/287547_ 1412844392vmiq.png "" 412 "height=" 391 "/>

Display error does not have a cluster configuration file, Stonith has been disabled, quorum has been ignored

To install DRBD:

According to the official documentation, DRBD has been loaded into the kernel after kernel 2.6.33, no need to install DRBD, just install Drbdadm management software, I use centos6.5, kernel version is 2.6.32, so you need to install

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201410/9/287547_ 1412844392vpz4.png "" 184 "height="/>

The DRBD version has 8.1 8.2 8.3 8.4, and I'm using the RPM package I've done to install, download directory: ftp://rpmfind.net/linux/atrpms/

Place the two RPM packages of DRBD in the/root directory and execute the # yum--nogpgcheck localinstall *.rpm

--nogpgcheck does not perform GPG detection because there is no certification file in CentOS

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201410/9/287547_ 1412844393phgz.png "" Height= "/>"

Installation is complete on two nodes. Loading the DRBD module

[Email protected] ~]# modprobe drbd[[email protected] ~]# lsmod | grep drbddrbd                  325978  0 libcrc32c               1246  1 DRBD
 Create a new disk partition as a shared disk for DRBD, and here I am a disk/dev/xvdb added by the Xen virtual machine, and the disk created is/DEV/XVDB1 
[[email protected] drbd.d]# fdisk/dev/xvdbdevice contains neither a valid DOS partition table, nor Sun, SGI or OSF D Isklabelbuilding a new DOS disklabel with disk identifier 0x218cde3e. Changes'll remain in memory only, until the decide to write them. After that, of course, the previous content won ' t is recoverable. Warning:invalid flag 0x0000 of partition Table 4 would be a corrected by W (rite) warning:dos-compatible mode is deprecated. It ' s strongly recommended to switch off the mode (command ' C ') and change display units to sectors (Comman d ' u ').  Command (M for help): Ncommand action E Extended P primary partition (1-4) ppartition number (1-4): 1First cylinder  (1-2610, default 1): Using default value 1Last cylinder, +cylinders or +size{k,m,g} (1-2610, default 2610): Using default Value 2610Command (M for help): pdisk/dev/xvdb:21.5 GB, 21474836480 bytes255 heads, sectors/track, 2610 Cylindersuni ts = Cylinders of 16065 * 8225280 = bytessector size (logical/physical): bytes/512 bytesi/o size (minimum/optimal): bytes/512 bytesdisk identifier:0x218cde3e Devi Ce Boot Start End Blocks Id system/dev/xvdb1 1 2610 20964793+ Linuxcomma nd (M for help): Wthe partition table have been altered! Calling IOCTL () to re-read partition table. Syncing disks.

Perform the same operation on the MYSQL2 node.

To configure DRBD:

In the/etc directory, there is a file drbd.conf the main configuration file, which mainly calls the configuration file under the/etc/drbd.d/directory.

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201410/9/287547_ 14128443934qao.png "" 499 "height=" "The/>

Configure/etc/drbd.d/global_common.conf

Global {usage-count no;# minor-count dialog-refresh Disable-ip-verification}common {protocol C;handlers { Pri-on-incon-degr "/USR/LIB/DRBD/NOTIFY-PRI-ON-INCON-DEGR.SH; /usr/lib/drbd/notify-emergency-reboot.sh; echo B >/proc/sysrq-trigger;                Reboot-f "; PRI-LOST-AFTER-SB "/USR/LIB/DRBD/NOTIFY-PRI-LOST-AFTER-SB.SH; /usr/lib/drbd/notify-emergency-reboot.sh; echo B >/proc/sysrq-trigger;                Reboot-f "; Local-io-error "/USR/LIB/DRBD/NOTIFY-IO-ERROR.SH; /usr/lib/drbd/notify-emergency-shutdown.sh; echo o >/proc/sysrq-trigger;                 Halt-f ";                 Fence-peer "/usr/lib/drbd/crm-fence-peer.sh";                 Split-brain "/usr/lib/drbd/notify-split-brain.sh root";                 Out-of-sync "/usr/lib/drbd/notify-out-of-sync.sh root";                 Before-resync-target "/usr/lib/drbd/snapshot-resync-target-lvm.sh-p---c 16k"; after-resync-target/usr/lib/drbd/unsnapshot-resync-target-lvm.sh;} #这个配置文件主要是防止脑裂The occurrence of the startup {# wfc-timeout degr-wfc-timeout outdated-wfc-timeout wait-after-sb wfc-timeout 120;  Degr-wfc-timeout 120;                }options {# Cpu-mask On-no-data-accessible}disk {on-io-error detach;        Fencing resource-only;                }net {CRAM-HMAC-ALG "SHA1";        Shared-secret "DRBD1";}        syncer {rate 1000M; }}

Create a resource for a disk in the/etc/drbd.d/directory

#vim/etc/drbd.d/stone.res

Resource mysql{on  mysql1 {    device    /dev/drbd0;    Disk      /dev/xvdb1;    Address   10.204.80.86:7789;    Meta-disk internal;  }  On MYSQL2 {    device    /dev/drbd0;    Disk      /dev/xvdb1;    Address   10.204.80.85:7789;    Meta-disk internal;  }}

Copy the two files to the MYSQL2 node.

The resources are then initialized on two nodes and executed separately

#drbdadm CREATE-MD MySQL-This resource is a resource defined in the Stone.res file

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201410/9/287547_ 1412844394w8z8.png "" 520 "height=" 181 "/>

Show initialization success

Start the DRBD service

#service DRBD Start

Viewing the DRBD status

#cat/PROC/DRBD

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201410/9/287547_ 1412844394kqft.png "" 637 "height=" "The/>

The above information two nodes are in the secondary state, the MYSQL1 node is set to primary

#drbdadm primary--force MySQL

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201410/9/287547_ 1412844394isvt.png "" 644 "height=" 165 "/>

As shown above, the data synchronization process has started, and after a while view the DRBD status

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201410/9/287547_ 1412844395l045.png "" 647 "height="/>

Show that the resource is already a master-slave state

To create a file system:

#mke2fs –t ext4–l drbd/dev/drbd0 #格式化为ext4文件系统 and specifies that the label name is DRBD

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201410/9/287547_ 1412844395fp4s.png "" 567 "height=" 393 "/>

Create the/data directory and mount the partition

#mkdir/data

#mount/dev/drbd0/data

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201410/9/287547_ 1412844396xeo4.png "" 395 "height="/>

Mount succeeded

Create a a,b,c,d four file in the/data directory, and then manually switch the Primary/secondary node

Execute on Node MYSQL1

#cd/data && Touch {a,b,c,d} #umount/data#drbdadm secondary MySQL

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201410/9/287547_ 1412844396svem.png "" 662 "height=" 182 "/>

You can see that the state of DRBD has changed to Secondary/secondary state again.

Set the DRBD node to the primary state on the MYSQL2 node, create the/data directory, and Mount

#drbdadm Primary Mysql#cat/proc/drbd#mkdir/data#mount/dev/drbd0/data#ls/data

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201410/9/287547_ 1412844396tqaq.png "" 641 "height="/>

You can see that the A,b,c,d four files created on the MYSQL1 node still exist on the MYSQL2 node, and the DRBD shared storage is OK

Install MySQL, create cluster resources, install MySQL process slightly

Configuring Resource Resources

Can PCs create resources with #pcs? can view help information

# pcs Resource Create Mysqlip ipaddr ip=10.204.80.89 cidr_netmask=24 nic=eth0

Adding a DRBD resource, the RA that provides DRBD is currently categorized by OCF as Linbit with a path of/USR/LIB/OCF/RESOURCE.D/LINBIT/DRBD. DRBD needs to run on two nodes at the same time, but only one node (the Primary/secondary model) is master and the other node is slave; therefore, it is a relatively special cluster resource. Its resource type is a multi-state (multi-state) clone type, that is, the host node has master and slave, and requires that two nodes are in slave state when the service is just started.

#pcs Resource Create MYSQLDRBD OCF:LINBIT:DRBD params drbd_resource=mysql op monitor role=master interval=50s timeout=30s OP Monitor Role=slave interval=60s timeout=30s

#pcs Resource Master MS_MYSQLDRBD mysqldrbd meta master-max= "1" master-node-max= "1" clone-max= "2" clone-node-max= "1" Notify= "true"

Define DRBD as a clone resource and view the resource status #pcs resource show

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201410/9/287547_ 1412844397iyz9.png "" 442 "height=" 108 "/>

However, the file system also needs to be mounted and the DRBD mounted to the/data directory.

# pcs resource Create Drbdfs ocf:heartbeat:Filesystem params device= "/dev/drbd0" directory= "/data" fstype= "Ext4"

View resource Status

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201410/9/287547_ 1412844397h4xr.png "" 418 "height=" 121 "/>

File system mount Drbdfs must be on the same node as Master MYSQLDRBD, you must start MYSQLDRBD before you can mount the Drbdfs file system, so you must define resource constraints

# pcs constraint colocation add Drbdfs with Master MS_MYSQLDRBD

# pcs constraint order promote MS_MYSQLDRBD then Drbdfs # # #drbd的资源添加完成

# pcs resource Create MySQLD lsb:mysqld op monitor interval=20 timeout=20 on-fail=restart # # #添加MySQLD Service resource complete, define MySQLD resource constraints , the Drbdfs file system must be mounted before the MYSQLD service can be started

# pcs constraint order Drbdfs then MySQLD

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201410/9/287547_ 1412844397dczq.png "" 618 "height="/>

Define Mysqlip, Drbdfs, and mysqld services to the same resource group

# pcs Resource group Add MyService mysqlip Drbdfs MySQLD

View resource Status

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201410/9/287547_ 1412844398zqll.png "" 488 "height=" 358 "/>

Defining constraints for resource groups

#pcs constraint order Mysqlip then promote MS_MYSQLDRBD then Drbdfs then MySQLD

Defining position constraints

#pcs Constraint Location

View configuration information for a cluster

#pcs Config Show

[[email protected]/]# PCs config showcluster name:corosync nodes:pacemaker nodes:mysql1 mysql2 resources:master : MS_MYSQLDRBD Meta attrs:master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify=true RESOURCE:MYSQLDRBD   (CLASS=OCF provider=linbit TYPE=DRBD) Attributes:drbd_resource=mysql operations:monitor interval=50s role=master timeout=30s ( Mysqldrbd-monitor-interval-50s-role-master) Monitor interval=60s role=slave timeout=30s (mysqldrbd-monitor-i Nterval-60s-role-slave) Group:myservice resource:mysqlip (CLASS=OCF provider=heartbeat type=IPaddr) attributes:ip=10 .204.80.89 operations:monitor interval=60s (mysqlip-monitor-interval-60s) Resource:drbdfs (CLASS=OCF PROVIDER=HEARTB Eat Type=filesystem) attributes:device=/dev/drbd0 directory=/data fstype=ext4 operations:monitor interval=60s (DRBD fs-monitor-interval-60s) resource:mysqld (class=lsb type=mysqld) operations:monitor On-fail=restart interval=20 Timeo Ut=20 (MySQLD-monitor-interval-20) Stonith devices:fencing levels:location constraints:ordering constraints:promote MS_MYSQLDRBD Then start Drbdfs (Mandatory) (id:order-ms_mysqldrbd-drbdfs-mandatory) Start Drbdfs then start MySQLD (Mandatory) (Id:ord er-drbdfs-mysqld-mandatory) Colocation Constraints:drbdfs with MS_MYSQLDRBD (INFINITY) (rsc-role:started) ( With-rsc-role:master) (id:colocation-drbdfs-ms_mysqldrbd-infinity-1) Cluster properties:cluster-infrastructure: Classic Openais (with plugin) dc-version:1.1.10-14.el6_5.3-368c726 Expected-quorum-votes:2 no-quorum-policy:ignore Stonith-enabled:false

COSYNC+PACEMAKER+DRBD shared storage for MySQL high-availability clusters

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.