DRBD Basic (Implement database high availability)

Source: Internet
Author: User
Tags deprecated error handling flushes

DRBD (Implement database high availability)


Distributed replicated block Device (DRBD) is a software-implemented, non-shared storage replication solution for mirrored block device content between servers.

Data mirroring: Real-time, transparent, synchronous (all servers are returned after success), asynchronous (returned after successful local server)


Environment


node1:192.168.163.172

node2:192.168.163.173



installation process


Modify the Hosts file first


[Email protected] ~]# cat/etc/hosts

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4

:: 1 localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.163.172 Node1

192.168.163.173 Node2



[Email protected] ~]# cat/etc/hosts

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4

:: 1 localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.163.172 Node1

192.168.163.173 Node2


Host name also to be modified


[Email protected] ~]# hostname

Node1


[Email protected] ~]# hostname

Node2


SSH-free login on both sides

[Email protected] ~]# Ssh-copy-id Node2


[Email protected] ~]# Ssh-copy-id Node1



To set the clock synchronization:

[Email protected] ~]# crontab-l

*/5 * * * * ntpdate cn.pool.ntp.org


[Email protected] ~]# crontab-l

*/5 * * * * ntpdate cn.pool.ntp.org


Install Derb:

# RPM--import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

# RPM-UVH http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm

# yum Install-y kmod-drbd84 drbd84-utils


To edit a global configuration file

Vim/etc/drbd.d/global_common.conf

global {    usage-count no;   #是否参加DRBD使用统计, the default is yes. Official statistics DRBD Installed Capacity     # minor-count dialog-refresh disable-ip-verification}common  {    protocol C;       #使用DRBD的同步协议      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 >&nbsP;/proc/sysrq-trigger ; halt -f ";    }    startup  {        # wfc-timeout degr-wfc-timeout  outdated-wfc-timeout wait-after-sb    }    options {         # cpu-mask on-no-data-accessible    }     disk {        on-io-error detach;   #配置I/O error handling policy for detach         # size max-bio-bvecs  on-io-error fencing disk-barrier disk-flushes        #  disk-drain md-flushes resync-rate resync-after al-extents         # c-plan-ahead c-delay-target c-fill-target c-max-rate         # c-min-rate disk-timeout    }    net {         # protocol timeout max-epoch-size max-buffers  unplug-watermark        # connect-int ping-int  sndbuf-size rcvbuf-size ko-count        #  allow-two-primaries cram-hmac-alg shared-secret after-sb-0pri         # after-sb-1pri after-sb-2pri always-asbp rr-conflict         # ping-timeout data-integrity-alg tcp-cork on-congestion         # congestion-fill congestion-extents csums-alg  verify-alg        # use-rle    }     syncer {        rate 1024m;     #设置主备节点同步时的网络速率     }} 


Creating a configuration file


[Email protected] ~]# Vim/etc/drbd.d/mysql.res

Resource MySQL {protocol c;meta-disk internal;device/dev/drbd1;syncer {verify-alg sha1;} NET {allow-two-primaries;} On node1 {disk/dev/sdb2; #在node1创建的分区address 192.168.163.172:7789;} On node2 {disk/dev/sdb2; #在node2创建的分区address 192.168.163.173:7789;}}


Then copy the Node1 configuration file to the Node2:

scp-rp/etc/drbd.d/* node2:/etc/drbd.d/


Start on Node2:

[[email protected] ~]# drbdadm CREATE-MD MySQL

Initializing activity log

Initializing bitmap (KB) to all zero

Writing Meta Data ...

New DRBD Meta data block successfully created.

[Email protected] ~]# modprobe DRBD


To see if the kernel has loaded the module:

[Email protected] drbd.d]# Lsmod | grep DRBD

DRBD 396875 1

LIBCRC32C 12644 4 Xfs,drbd,ip_vs,nf_conntrack

###

[[email protected] ~]# drbdadm up MySQL

[[email protected] ~]# DRBDADM----Force primary MySQL


View Status:

[Email protected] ~]# CAT/PROC/DRBD

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

GIT-HASH:A4D5DE01FFFD7E4CDE48A080E2C686F9E8CEBF4C build by [email protected], 2017-09-15 14:23:22


1:cs:wfconnection Ro:primary/unknown Ds:uptodate/dunknown C r-----

ns:0 nr:0 dw:0 dr:912 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0


The same operation is performed again in Node2

[[email protected] ~]# drbdadm CREATE-MD MySQL

[Email protected] ~]# modprobe DRBD

[[email protected] ~]# drbdadm up MySQL


Both sides are installed MARIADB

Yum install-y mariadb Mariadb-server


Modify the configuration file to point the database path to the/test directory

Vim/etc/my.cnf

[Mysqld]datadir=/testsocket=/var/lib/mysql/mysql.sock


View status, see Node1 is primary

[Email protected] ~]# Drbd-overview

Note:drbd-overview'll be deprecated soon. Please consider using Drbdtop. 1:mysql/0 Connected primary/secondary uptodate/uptodate



Create a/test directory

Mkdir/test


format and Mount in Node1 :

[Email protected] ~]# MKFS.XFS/DEV/DRBD1

[Email protected] ~]# mount/dev/drbd1/test


Mount succeeded

[Email protected] ~]# df-h

Filesystem Size used Avail use% mounted on

/dev/mapper/cl-root 17G 1.5G 16G 9%/

Devtmpfs 902M 0 902M 0%/dev

Tmpfs 912M 0 912M 0%/dev/shm

Tmpfs 912M 8.5M 904M 1%/run

Tmpfs 912M 0 912M 0%/sys/fs/cgroup

/DEV/SDA1 1014M 185M 830M 19%/boot

Tmpfs 183M 0 183M 0%/run/user/0

/DEV/DRBD1 991M 32M 892M 4%/test

=================================================


Test session:


Start the database first and create a database

[Email protected] ~]# systemctl start mariadb

MariaDB [(None)]> CREATE Database xhk777;

Query OK, 1 row affected (0.04 sec)


Stop the Node1 mariadb service and uninstall the mount you just mounted

[Email protected] ~]# Systemctl stop mariadb

[Email protected] ~]# umount/test


Downgrade Node1 to Secondary

[[email protected] ~]# drbdadm secondary MySQL


Upgrade Node2 to Primary


[[email protected] ~]# Drbdadm primary MySQL

Note: In single-master mode, DRBD, two nodes are connected at the same time, any one node can become the master in a certain time, but only one of the two nodes, if there is already a master, need to downgrade before possible upgrade; there is no limit in dual-master mode


Check the status on Node2 and you can see that Node2 is already primary

[Email protected] ~]# Drbd-overview

Note:drbd-overview'll be deprecated soon.

Please consider using Drbdtop.


1:mysql/0 Connected primary/secondary uptodate/uptodate


Mount at this time and start the database


[Email protected] ~]# mount/dev/drbd1/test

[Email protected] ~]# systemctl start mariadb


View the database and find the xhk777 you just created

MariaDB [(None)]> show databases;+---------------------+| Database |+---------------------+| Information_schema | | #mysql50 #lost+found | | MySQL | | Performance_schema | | XHK | | xhk777 |+---------------------+6 rows in Set (0.06 sec)


The experiment was successful, and we could simulate a brain fissure after the node1 recovered.

Prohibit communication above the Node2

[Email protected] ~]# iptables-p INPUT DROP


When Node1 view the state, it is not possible to find Node2.

[Email protected] ~]# Drbd-overview

Note:drbd-overview'll be deprecated soon.

Please consider using Drbdtop.


1:mysql/0 wfconnection Secondary/Unknown Uptodate/dunknown


Upgrade Node1 to Primary

[[email protected] ~]# Drbdadm primary MySQL

[Email protected] ~]# Drbd-overview

Note:drbd-overview'll be deprecated soon.

Please consider using Drbdtop.


1:mysql/0 wfconnection Primary/Unknown Uptodate/dunknown


Mount the directory as before and start the MARIADB service

[Email protected] ~]# mount/dev/drbd1/test


[Email protected] ~]# systemctl start mariadb


Node1 database service is OK

MariaDB [(None)]> show databases;+---------------------+| Database |+---------------------+| Information_schema | | #mysql50 #lost+found | | MySQL | | Performance_schema | | XHK | | xhk777 |+---------------------+6 rows in Set (0.05 sec)


This time to change the Node2 firewall policy to allow, there will be a brain fissure situation

Iptables-p INPUT ACCEPT


View the status separately and discover that Node1 and Node2 are all for primary

[Email protected] ~]# Drbd-overview

Note:drbd-overview'll be deprecated soon.

Please consider using Drbdtop.


1:mysql/0 StandAlone Primary/Unknown uptodate/dunknown/test ext4 991M 32M 892M 4%


[Email protected] ~]# Drbd-overview

Note:drbd-overview'll be deprecated soon.

Please consider using Drbdtop.


1:mysql/0 StandAlone Primary/Unknown uptodate/dunknown/test ext4 991M 32M 892M 4%


The workaround is to use the Node1 as a backup node

[Email protected] ~]# Systemctl stop mariadb

[Email protected] ~]# umount/test

[[email protected] ~]# drbdadm secondary MySQL

[[email protected] ~]# drbdadm connect--discard-my-data mysql


View the status of Node1

[Email protected] ~]# Drbd-overview

Note:drbd-overview'll be deprecated soon.

Please consider using Drbdtop.


1:mysql/0 wfconnection Secondary/Unknown Uptodate/dunknown


Discover or unknown, reconnect to Node2

[[email protected] ~]# drbdadm connect MySQL


View status again

[Email protected] ~]# Drbd-overview

Note:drbd-overview'll be deprecated soon.

Please consider using Drbdtop.


1:mysql/0 Connected Secondary/Primary uptodate/uptodate


[Email protected] ~]# Drbd-overview

Note:drbd-overview'll be deprecated soon.

Please consider using Drbdtop.


1:mysql/0 Connected Primary/secondary uptodate/uptodate/test ext4 991M 32M 892M 4%


Back to normal!!!


This article is from the "xhk777" blog, make sure to keep this source http://xhk777.blog.51cto.com/13405744/1975381

DRBD Basic (Implement database high availability)

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.