DRBD:Distributed Replicated Block Device Distributed replication block devices , Schematic diagram is as follows

DRBD There are two main architectures and two main architectures , When in master-slave architecture , This device must have only one node that can read and write , The other nodes are unreadable , It's impossible to mount it , Only one node is primary , Other sections It's all from . As the main architecture , Several conditions need to be met ,1. Enable... In a highly available cluster DRBD;  2. Enable distributed file locking , That is, you need to format the disk as a cluster file system ( Such as GFS2,OCFS2 etc. );3. hold DRBD Make resources .

Stored procedure of data : When a process stores data, it uses DRBD Module copy one point through TCP/IP The socket is sent to the slave node , From node's DRBD Receive data on a socket and pass through DRBD modular Store to disk , And return the result to the master node . But the speed of kernel transfer is very fast , and TCP The transmission speed of message is much slower , So they put the data in TCP Send buffer of protocol stack , And then slowly from the buffer to the slave node . This There are three models for data transmission :

A : Asynchronous model , When the kernel DRBD The data copied in the module has been sent to the local TCP The buffer of the protocol stack , To is whether the data from the node has been transferred to , Whether the preservation is complete , No guarantee ;

B : Semi synchronous model , The message has been sent to the socket of the slave node , Has been received , Concurrent to the kernel , But the stored procedure of the slave node has no response procedure .

C: Synchronous model , The message is sent to the slave node , The slave node has received , Concurrent to the kernel , The kernel has stored the data packets to the disk , And return the result to the master node , This is the default data transfer model , Can guarantee the integrity of the data .

Installation environment :

centos6.5, install corosync and pacemaker Please refer to the previous blog for the process , The configuration interface of the last environment installation was crmsh, What's installed here is pcs, install pcs Relatively simple ,#yum install pcs –y  that will do

After the installation, the cluster status is as follows :

Now you see two cluster nodes mysql1 mysql2 On-line ,pacemaker It's used as a plug-in , No, stonith equipment , There are only two nodes , therefore quorum Also ignore

#pcs property set stonith-enabled=false

# pcs property set no-quorum-policy=ignore

#pcs config show                                               View the configuration file

Display error, no cluster configuration file yet ,stonith Disabled ,quorum Has ignored

install drbd:

According to official documents ,drbd In the kernel 2.6.33 It has been loaded into the kernel since the release , There is no need for additional installation drbd, Just install drbdadm Just management software , What I use here is centos6.5, The kernel version is 2.6.32, So we need to install

drbd Version has 8.1 8.2 8.3 8.4, I'm using what I've already done rpm Package for installation , Download directory :ftp://rpmfind.net/linux/atrpms/

hold drbd Of the two rpm bag /root Under the table of contents , And then execute # yum --nogpgcheck localinstall *.rpm

--nogpgcheck Don't execute gpg testing , Because in centos There are no authentication documents in it

Installation is complete on both nodes . load DRBD modular

?
1
2
3
4
[root@mysql1 ~] # modprobe drbd
[root@mysql1 ~] # lsmod | grep drbd
drbd                  325978  0
libcrc32c               1246  1 drbd
?
1
Create a new partition as DRBD Shared disk of , I am here xen A disk added to the virtual machine /dev/xvdb , The disk created is /dev/xvdb1
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
[root@mysql1 drbd.d] # fdisk /dev/xvdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x218cde3e.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
 
Warning: invalid flag 0x0000 of partition table 4 will be 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 ( command 'u' ).
 
Command (m for help): n
Command action
    e   extended
    p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610):
Using default value 2610
 
Command (m for help): p
 
Disk /dev/xvdb : 21.5 GB, 21474836480 bytes
255 heads, 63 sectors /track , 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical /physical ): 512 bytes / 512 bytes
I /O size (minimum /optimal ): 512 bytes / 512 bytes
Disk identifier: 0x218cde3e
 
     Device Boot      Start         End      Blocks   Id  System
/dev/xvdb1               1        2610    20964793+  83  Linux
 
Command (m for help): w
The partition table has been altered!
 
Calling ioctl() to re- read partition table.
Syncing disks.

stay mysql2 Do the same thing on the node .

To configure drbd:

stay /etc There is a file in the directory drbd.conf Master profile , It mainly calls /etc/drbd.d/ The configuration file under the directory

To configure /etc/drbd.d/global_common.conf

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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 15 -- -c 16k";
                  #after-resync-target /usr/lib/drbd/unsnapshot-resync-target-lvm.sh;
     } # This configuration file is mainly to prevent the occurrence of brain fissure
 
     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;
         }
}

stay /etc/drbd.d/ Create a disk resource under the directory

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 these two files to mysql2 Node

Then initialize the resource on both nodes , Separately

#drbdadm create-md mysql                                                           -- This resource is in stone.res Resources defined in file

Display initialization success

start-up drbd service

#service drbd start

see drbd state

#cat /proc/drbd

In the information above, both nodes are in Secondary state , take mysql1 Set the node to Primary

#drbdadm  primary  --force mysql

As shown above , The data synchronization process has begun , Check it out after a while drbd state

Show that the resource is in master-slave state

Create file system :

#mke2fs –t ext4 –L drbd /dev/drbd0                  # Formatted as ext4 file system , And designate label be known as drbd

establish /data Catalog , Partition and mount

#mkdir /data

#mount /dev/drbd0 /data

Mount successfully

stay /data Create... In the directory a,b,c,d Four files , And then manually switch Primary/Secondary node

At the node mysql1 On the implementation

?
1
2
3
4
5
#cd /data && touch {a,b,c,d}
 
#umount /data
 
#drbdadm secondary mysql

You can see drbd The state of being in the state of being in the state of being in the state of being in the state of being in the state of being in the state of being in the state of being in the state of being in the state of being in the state of being in the state of being in the state of being in the state of being secondary /secondary state

stay mysql2 On the node drbd Set the node to Primary state , establish /data Catalog , And mount

?
1
2
3
4
5
6
7
8
9
#drbdadm primary mysql
 
#cat /proc/drbd
 
#mkdir /data
 
#mount /dev/drbd0 /data
 
#ls /data

You can see in the mysql1 Created on node a,b,c,d Four files in mysql2 Still exist on the node ,drbd Shared storage has Ok

install mysql, Create cluster resources , install mysql The process is brief

Allocate resources

pcs Create resources with #pcs ? You can see the help information

# pcs resource create mysqlip ipaddr ip=10.204.80.89 cidr_netmask=24 nic=eth0

add to DRBD resources , Provide drbd Of RA At present by OCF Classified as linbit, Its path is /usr/lib/ocf/resource.d/linbit /drbd.drbd You need to run on two nodes at the same time , But there can only be one node (primary/secondary Model ) yes Master, And the other node is Slave; therefore , It's a comparison Special cluster resources , Its resource type is multi state (Multi-state)clone type , That is, the host node has Master and Slave Points , And it requires two nodes when the service starts All in slave state .

#pcs resource create  primitive mysqldrbd ocf:linbit:drbd params drbd_resource=mysql op monitor role=Master interval=50s timeout=30s op monitor role=Slave interval=60s timeout=30s  op start timeout=240 op stop timeout=100

perhaps #crm configure primitive mysqldrbd ocf:linbit:drbd params drbd_resource=mysql op monitor role=Master interval=10s timeout=20s op monitor role=Slave interval=20s timeout=20s op start timeout=240 op stop timeout=100

#pcs resource master ms_mysqldrbd mysqldrbd meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true"

perhaps #crm configure ms ms_myqldrbd mysqldrbd  meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true"

hold drbd Defined as clone resources , View resource status #pcs resource show

But as a file system, you need to mount , hold drbd Mount to /data Catalog

# pcs resource create drbdfs ocf:heartbeat:Filesystem params device="/dev/drbd0" directory="/data" fstype="ext4"

View resource status

File system mount drbdfs It has to be with Master mysqldrbd On the same node , Must be started first mysqldrbd Then you can mount drbdfs file system , So you have to define resource constraints

# pcs constraint colocation add  drbdfs with master MS_mysqldrbd

# pcs constraint order promote MS_mysqldrbd then drbdfs                    ###drbd Finished adding resources for

# pcs resource create MySQLD lsb:mysqld op monitor interval=20 timeout=20 on-fail=restart ### add to MySQLD Service resources complete , Definition MySQLD Resource constraints , must drbdfs The file system is mounted before it can be started MySQLD service

# pcs constraint order drbdfs then MySQLD

hold mysqlip ,drbdfs and MySQLD Services are defined to the same resource group

# pcs resource group add myservice mysqlip drbdfs MySQLD

View resource status

Define constraints for resource groups

#pcs constraint order mysqlip then promote MS_mysqldrbd then drbdfs then MySQLD

View the cluster configuration information

#pcs config show

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
root@mysql1 /] # pcs config show
Cluster 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-interval-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=heartbeat type =Filesystem)
    Attributes: device= /dev/drbd0 directory= /data fstype=ext4
    Operations: monitor interval=60s (drbdfs-monitor-interval-60s)
   Resource: MySQLD (class=lsb type =mysqld)
    Operations: monitor on-fail=restart interval=20 timeout=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 :order-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
?
1
View the resource status
?
1
<a target= "\"_blank\"" href= "http://img1.51cto.com/attachment/201410/11/287547_14129899470cu1.png" ><img onunload= "" onsubmit= "" onselect= "" onresize= "" onreset= "" onmouseup= "" onmouseover= "" onmouseout= "" onmousemove= "" onmousedown= "" onkeyup= "" onkeypress= "" onkeydown= "" onfocus= "" onerror= "" ondblclick= "" onclick= "" onchange= "" onblur= "" onabort= "" onload= "if(this.width>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_thumb" alt= "image_thumb" src= "http://img1.51cto.com/attachment/201410/11/287547_1412989948zXME.png" "469" = "" height= "363" border= "0" >< /a >
?
1
Connect other machines to 10.204.80.89 Of mysql
?
1
<a target= "\"_blank\"" href= "http://img1.51cto.com/attachment/201410/11/287547_1412989948oOXf.png" ><img onunload= "" onsubmit= "" onselect= "" onresize= "" onreset= "" onmouseup= "" onmouseover= "" onmouseout= "" onmousemove= "" onmousedown= "" onkeyup= "" onkeypress= "" onkeydown= "" onfocus= "" onerror= "" ondblclick= "" onclick= "" onchange= "" onblur= "" onabort= "" onload= "if(this.width>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_thumb1" alt= "image_thumb1" src= "http://img1.51cto.com/attachment/201410/11/287547_1412989948YElu.png" "557" = "" height= "223" border= "0" >< /a >
?
1
It can be connected normally , hold mysql1 Set to standby
?
1
<a target= "\"_blank\"" href= "http://img1.51cto.com/attachment/201410/11/287547_1412989948p4V6.png" ><img onunload= "" onsubmit= "" onselect= "" onresize= "" onreset= "" onmouseup= "" onmouseover= "" onmouseout= "" onmousemove= "" onmousedown= "" onkeyup= "" onkeypress= "" onkeydown= "" onfocus= "" onerror= "" ondblclick= "" onclick= "" onchange= "" onblur= "" onabort= "" onload= "if(this.width>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_thumb2" alt= "image_thumb2" src= "http://img1.51cto.com/attachment/201410/11/287547_1412989949GfXR.png" "468" = "" height= "682" border= "0" >< /a >
?
1
Find out mysql The cluster of has been transferred normally , The high availability cluster is normal

Reprint :http://piao719.blog.51cto.com/287547/1562390

corosync+pacemaker and drbd Realization mysql More articles on high availability clusters

  1. MySQL High availability cluster solution

    One .Mysql Highly available solutions Scheme 1 : Shared memory In general, shared storage is more commonly used SAN/NAS programme . Option two : Operating system real time block replication The typical scenario of this scheme is DRBD,DRBD framework (MySQL+DRBD+ ...

  2. Mysql Introduction to high availability cluster environment

    MySQL Build a highly available cluster environment 01.MySQL High availability environment solutions 02.MySQL Master slave replication principle 03.MySQL Master-slave replication 04. stay Linux Install on Environment MySQL 05. stay MySQL The cluster environment is configured with master-slave complex ...

  3. Mysql High availability cluster PXC

    PXC yes percona The company's percona  xtraDB  cluster, abbreviation PXC. It is based on Galera The high availability cluster solution of the protocol . It can realize data synchronous replication and read-write between multiple nodes , And it can guarantee the high availability of database services ...

  4. Deploy MYSQL High availability cluster

                                                  mysql-day08      Deploy MYSQL High availability cluster u  Cluster architecture                   ...

  5. keepalived+MySQL High availability cluster

    be based on keepalived build MySQL High availability cluster for   MySQL There are several high availability schemes for : keepalived+ Double master ,MHA,MMM,Heartbeat+DRBD,PXC,Galera Clus ...

  6. heatbeat-gui Implementation is based on nfs Of mysql High availability cluster

    One . sketch HA High availability cluster High availability cluster is when a node in the cluster has various software, hardware and human failures , Other nodes in the cluster can automatically take over the resources of the failed node and provide services to the outside . In order to reduce the time of business interruption , To provide users with more reliable , More efficient service . ...

  7. MYSQL High availability cluster architecture -MHA framework

    1  MHA brief introduction :MHA(Master High Availability) Currently in MySQL The high availability aspect is a relatively mature solution , It's from Japan DeNA company youshimaton( Now I work in Facebook company ...

  8. structure MHA Realization MySQL High availability cluster architecture

    One .MHA brief introduction MHA(Master HighAvailability) Currently in MySQL The high availability aspect is a relatively mature solution , It's from Japan DeNA company youshimaton( Now I work in Facebook company ) open ...

  9. be based on Galera Cluster Multi main structure Mysql High availability cluster

    Galera Cluster characteristic 1. Multi master architecture : Real multi-point read-write cluster , Read and write data at any time , It's all the latest 2. Synchronous replication : Data synchronization between different nodes in the cluster , There is no delay , After the database hangs up , Data will not be lost 3. Concurrent replication : from ...

Random recommendation

  1. Not Unicode Engineering reading Unicode file

    MyUnicodeReader.h #pragma once /******************************************************************** ...

  2. How to use mybatis《 One 》

    mybatis As ORM As soon as lightweight framework appeared, it attracted countless people's attention , Than hibernate It's simple and easy to get started , Let's start with my first mybatis Program . One . download mybatis My bag We know that any framework has its package ...

  3. Linux User mode and kernel mode

    1. Privilege level privilege level is used to manage and control program execution . Such as Intel x86 Architecturally CPU, Yes 0~3 Four privilege levels ,0 Highest level ,3 Lowest level . The hardware checks the privilege level of each instruction as it executes it . The hardware provides a privilege level mechanism , For operating systems ...

  4. 020ARM family

    1. name :6410.2440.210.A8.ARM9.ARM11.armv7.ARMv6(v:vsersion) The name of the chip :6410.210.2440 They all belong to the name of the chip , It's all from Samsung : ARM nucleus ...

  5. JS Components Bootstrap Implementation of pop-up box and prompt box effect code

    This article mainly introduces JS Components Bootstrap Implementation of pop-up box and prompt box effect code , For those who are interested in pop-up box and prompt box, please refer to Preface : about Web Developer , The use of pop-up box and prompt box is certainly not strange , For example, common forms are added and edited ...

  6. BZOJ 2442: [Usaco2011 Open] Mow the lawn

    Description After winning the best lawn competition in town a year ago ,FJ Become lazy , Never mowed the lawn again . Now? , A new round of the best lawn competition has begun ,FJ Hope to win again . However ,FJ My lawn is very messy , therefore ,FJ Can only make his ...

  7. Redis Source code analysis - Memory data structure intset

    This time I studied intset. In the process of research , For a time I couldn't see the past , But I still gritted my teeth and survived . I see. That's what happened . Calm down and , Don't be impetuous Redis In pursuit of efficiency , A lot of optimizations have been done in storage , image intset It's the author for the festival ...

  8. In a second mysql Remote login for

    Execute the following command ! mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypw' WITH GRANT OPTION ; ...

  9. Hibernate Operating the database

    com.tao.pojo Entity class package com.tao.pojo; public class User { private int id; private String name; priva ...

  10. C++ in int And string The transformation of

    C++ in int And string The transformation of int It should also be represented by a string of characters , There are no double quotes around , Tell the compiler to interpret it as a number . By default , It's like 10 Base number (dec) To explain , If you want to use 8 Base number ,16 Base number , What do I do ? Add the prefix , ...