Mysql + Corosync + Pacemaker + DRBD

Source: Internet
Author: User

1. Environment Introduction
OS: centos 6.5
Kernel: 2.6.32-431.11.2.el6.x86 _ 64
Node1: nginxha001 10.0.15.31 Master
Node2: nginxha002 10.0.15.32 Slave
Vip: 10.0.15.30
Note: drbd is used in this example. For installation of mysql, corosync, and pacemaker programs, see other materials. Both programs must be installed. drbd resources can be copied to the other one after configuration is completed on one platform. Both drbd resources must be created to create disks. corosync resources can be configured on one platform, it will be automatically synchronized to another one. If the program connects to mysql using a virtual ip address (vip), it is best to deploy the program on the drbd disk so that the program can be configured as localhost.

2. Install the dependency package
Yum-y install gcc rpm-build kernel-devel kernel-headers flex ncurses-devel

Wget http://elrepo.org/linux/elrepo/el5/x86_64/RPMS/drbd84-utils-8.4.3-1.el5.elrepo.x86_64.rpm
Wget http://elrepo.org/linux/elrepo/el6/x86_64/RPMS/kmod-drbd84-8.4.3-1.el6_4.elrepo.x86_64.rpm
Yum-y install drbd84-utils-8.4.3-1.el5.elrepo.x86_64.rpm
Yum install-y kmod-drbd84-8.4.3-1.el6_4.elrepo.x86_64.rpm

3. Define drbd Resources
Vi/etc/drbd. d/mysql. res # defines mysql resources, with the same effect
Resource mysql {
Protocol C;
Device/dev/drbd0;
Disk/dev/sdc1;
Meta-disk internal;
On nginxha001 {
Address 10.0.15.31: 7789;
}
On nginxha002 {
Address 10.0.15.32: 7789;
}
}


4. Start the service and format the disk
Create partitions required for drbd data synchronization. the space of the two computers is the same.
Fdisk/dev/sdc
Drbdadm create-md mysql
Service drbd start

Set to the master node and only operate on the master node
Drbdadm -- overwrite-data-of-peer primary mysql
Create a File System
Mkfs-t ext4/dev/drbd0

5. Configure corosync Resources
Crm (live) # configure
Property stonith-enabled = false
Property no-quorum-policy = ignore
Define Mysql service resources
Primitive Mysqld lsb: mysqld
Configure DRBD Master/Slave Resources
Primitive Drbd ocf: linbit: drbd params drbd_resource = "mysql" op start interval = "0" timeout = "240" op stop interval = "0" timeout = "100"
Master My_Drbd Drbd meta master-max = "1" master-node-max = "1" clone-max = "2" clone-node-max = "1" notify = "true"
Define a file system resource
Primitive FileSys ocf: heartbeat: filesystem params device = "/dev/drbd0" directory = "/mysqldata" fstype = "ext4" op start timeout = "60 s" op stop timeout = "60 s"
Restrict the positions and startup sequence of resources
# Run the file system with the DRBD master node
Colocation FileSys_on_My_Drbd inf: FileSys My_Drbd
# Start the DRBD service first than the File System
Order FileSys_after_My_Drbd inf: My_Drbd: promote FileSys: start
# Run the Mysql service together with the file system
Colocation Mysqld_on_FileSys inf: Mysqld FileSys
# Run the file system first than the Mysql Service
Order Mysqld_after_FileSys inf: FileSys Mysqld: start
# Run the virtual IP address with the Mysql Service
Colocation vip_on_Mysqld inf: vip Mysqld

After the execution is complete, the final configuration file is as follows:
Node nginxha001 \
Attributes standby = "off"
Node nginxha002 \
Attributes standby = "off"
Primitive Drbd ocf: linbit: drbd \
Params drbd_resource = "mysql "\
Op monitor interval = "10 s" role = "Master "\
Op monitor interval = "20 s" role = "Slave "\
Op start timeout = "240 s" interval = "0 "\
Op stop timeout = "100" interval = "0"
Primitive FileSys ocf: heartbeat: Filesystem \
Params device = "/dev/drbd0" directory = "/mysqldata" fstype = "ext4 "\
Op start timeout = "60 s" interval = "0 "\
Op stop timeout = "60 s" interval = "0"
Primitive Mysqld lsb: mysqld
Primitive vip ocf: heartbeat: IPaddr \
Params ip = "10.1.15.30" nic = "eth0" cidr_netmask = "24 "\
Op monitor interval = "10 s"
MS: My_Drbd Drbd \
Meta master-max = "1" master-node-max = "1" clone-max = "2" clone-node-max = "1" notify = "true"
Colocation FileSys_on_My_Drbd inf: FileSys My_Drbd: Master
Colocation Mysqld_on_FileSys inf: Mysqld FileSys
Colocation vip_on_Mysqld inf: vip Mysqld
Order FileSys_after_My_Drbd inf: My_Drbd: promote FileSys: start
Order Mysqld_after_FileSys inf: FileSys Mysqld: start
Property $ id = "cib-bootstrap-options "\
Dc-version = "1.1.10-14. el6_5.2-368c726 "\
Cluster-infrastructure = "classic openais (with plugin )"\
Expected-quorum-votes = "4 "\
Stonith-enabled = "false "\
No-quorum-policy = "ignore "\
Last-lrm-refresh = "1396576217"
Rsc_defaults $ id = "rsc-options "\
Resource-stickiness = "100"
# Vim: set syntax = pcmk


If any error occurs, run the following command to clear the error:
Crm resource cleanup Mysqld
Crm resource cleanup vip
Crm resource cleanup FileSys

6. Other commands
Mount drbdo
Mount/dev/drbd0/mysqldata/
Uninstall
Umount/mysqldata/
Disks can be attached only when drbd is set as the primary node.
Drbdadm primary mysql
Set drbd as standby
Drbdadm secondary mysql

Watch-n1 'drbd-overview' observe data synchronization and press ctrl + c to exit.
Drbd-overview # view the status. When the status is the following content, perform the next step.
Cat/proc/drbd view synchronization progress

7. Modify the my. cnf configuration to change the data directory to the drbd directory.
Vi/etc/my. cnf

[Mysqld]
Datadir =/mysqldata
Socket =/mysqldata/mysql. sock
User = mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
Symbolic-links = 0

[Mysqld_safe]
Log-error =/mysqldata/mysqld. log
Pid-file =/mysqldata/mysqld. pid
[Client]
Socket =/mysqldata/mysql. sock

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.