Jusene's Blog

drbd+pacemaker+corosync v1构建高可用集群mariadb

字数统计: 1k阅读时长: 5 min
2017/05/20 Share

DRBD

DRBD的工作机制很简单,但确实廉价存储中较好的解决方案,DRBD的存储切换较麻烦,当出现故障的时候,想要快速切换的服务就都需要高可用集群框架来实现,下面是一个演示案例。

框架构建

关于corosync v1的配置可以参考:corosync配置
关于drbd的配置可以参考:drbd配置

目的为构建高可用的以drbd块设备为存储的高可用mariadb。

集群配置

构建drbd主从资源配置:

  • node1

    1
    ~]# crm configure
    2
    crm(live)configure# primitive mysqlstore ocf:linbit:drbd params drbd_resource=mystore op  monitor role='Master' interval=10s timeout=20s op monitor role='Slave' interval=20s timeout=20s  op start timeout=240s op stop timeout=100s
    3
    crm(live)configure# verify
    4
    crm(live)configure# ms ms_mysqlstore mysqlstore meta clone-max=2 clone-node-max=1 master-max=1 master-node-max=1 notify='true'
    5
    crm(live)configure# verify
    6
    crm(live)configure# commit
    7
    crm(live)configure# cd ..
    8
    crm(live)# status
    9
    Stack: classic openais (with plugin)
    10
    Current DC: node1 (version 1.1.15-5.el6-e174ec8) - partition with quorum
    11
    Last updated: Fri May 19 08:25:05 2017          Last change: Fri May 19 08:25:00 2017 by root via cibadmin on node1
    12
    , 2 expected votes
    13
    2 nodes and 2 resources configured
    14
    15
    Online: [ node1 node2 ]
    16
    17
    Full list of resources:
    18
    19
     Master/Slave Set: ms_mysqlstore [mysqlstore]
    20
         Masters: [ node1 ]
    21
         Slaves: [ node2 ]
    22
    23
    crm(live)# node standby
    24
    crm(live)# status
    25
    Stack: classic openais (with plugin)
    26
    Current DC: node1 (version 1.1.15-5.el6-e174ec8) - partition with quorum
    27
    Last updated: Fri May 19 08:27:37 2017          Last change: Fri May 19 08:25:32 2017 by root via crm_attribute on node2
    28
    , 2 expected votes
    29
    2 nodes and 2 resources configured
    30
    31
    Node node1: standby
    32
    Online: [ node2 ]
    33
    34
    Full list of resources:
    35
    36
     Master/Slave Set: ms_mysqlstore [mysqlstore]
    37
          Masters: [ node2 ]
    38
          Stopped: [ node1 ]
  • node1
    配置主drbd自动挂载

    1
    ~]# mkdir /mydata;ssh node2 'mkdir /mydata'
    2
    ~]# crm node online
    3
    ~]# crm
    4
    crm(live)# configure
    5
    crm(live)configure# primitive mydata ocf:heartbeat:Filesystem params device='/dev/drbd0' directory='/mydata' fstype=ext4 op monitor interval=20s timeout=40s op start timeout=60s op stop timeout=60s  
    6
    crm(live)configure# verify
    7
    crm(live)configure# colocation mydata_with_ms_mysqlstore_master inf: mydata ms_mysqlstore:Master
    8
    crm(live)configure# order mydata_after_ms_mysqlstore_master Mandatory: ms_mysqlstore:promote mydata
    9
    crm(live)configure# verify
    10
    crm(live)configure# commit
    11
    crm(live)configure# cd ..
    12
    crm(live)# status
    13
    Stack: classic openais (with plugin)
    14
    Current DC: node1 (version 1.1.15-5.el6-e174ec8) - partition with quorum
    15
    Last updated: Fri May 19 08:25:05 2017          Last change: Fri May 19 08:25:00 2017 by root via cibadmin on node1
    16
    , 2 expected votes
    17
    2 nodes and 2 resources configured
    18
    19
    Online: [ node1 node2 ]
    20
    21
    Full list of resources:
    22
    23
     Master/Slave Set: ms_mysqlstore [mysqlstore]
    24
         Masters: [ node1 ]
    25
         Slaves: [ node2 ]
    26
     mydata (ocf::heartbeat:Filesystem):    Started node1
  • node1
    主节点配置mariadb

    1
    ~]# tar xf mariadb-5.5.40-linux-x86.64.tar.gz -C /usr/local
    2
    ~]# cd /usr/local
    3
    ~}# groupadd -r -g 306 mysql;ssh node2 "groupadd -r -g 306 mysql"
    4
    ~]# useradd -r -g 306 -u 306 mysql;ssh node2 "useradd -r -g 306 -u 306 mysql"
    5
    ~]# mkdir /mydata/data
    6
    ~]# chown -R mysql.mysql /mydata/data
    7
    ~]# ln -s mariadb-5.5.40-linux-x86.64 mysql
    8
    ~]# cd mysql
    9
    ~]# scripts/mysql_install_db --datadir=/mydata/data --user=mysql
    10
    ~]# cp support-files/mysql.server /etc/init.d/mysqld
    11
    ~]# chkconfig --add mysqld;chkconfig mysqld off
    12
    ~]# cp support-files/my-large.cnf /etc/my.cnf
    13
    ~]#  cat /etc/my.cnf
    14
    [mysqld]
    15
    datadir=/mysqldata/data
    16
    innodb_file-per_table=1
    17
    ~]# service mysqld start
    18
    ~]# service mysqld stop
    19
    ~]# crm node standby
    20
    ~]# crm node online
  • node2
    配置mariadb

    1
    ~]# tar xf mariadb-5.5.40-linux-x86.64.tar.gz -C /usr/local
    2
    ~]# cd /usr/local
    3
    ~]# mkdir /mydata/data
    4
    ~]# chown -R mysql.mysql /mydata/data
    5
    ~]# ln -s mariadb-5.5.40-linux-x86.64 mysql
    6
    ~]# cd mysql
    7
    ~]# ln -s mariadb-5.5.40-linux-x86.64 mysql
    8
    ~]# cd mysql
    9
    ~]# cp support-files/mysql.server /etc/init.d/mysqld
    10
    ~]# chkconfig --add mysqld;chkconfig mysqld off
    11
    ~]# cp support-files/my-large.cnf /etc/my.cnf
    12
    ~]#  cat /etc/my.cnf
    13
    [mysqld]
    14
    datadir=/mysqldata/data
    15
    innodb_file-per_table=1
    16
    ~]# service mysqld start
    17
    ~]# service mysqld stop
    18
    ~]# crm node standby
    19
    ~]# crm node online
  • node1
    配置mariadb作为高可用集群资源

    1
    ~]# crm
    2
    crm(live)# configure
    3
    crm(live)configure# primitive myip ocf:heartbeat:IPaddr params ip=10.211.55.24  op monitor interval=10s timeout=20s
    4
    crm(live)configure# primitive myserver lsb:mysqld op monitor interval=20s timeout=20s
    5
    crm(live)configure# colocation myip_with_ms_mysqlstore_master inf: myip ms_myqlstore:Master
    6
    crm(live)configure# colocation myserver_with_mydata inf: myserver mydata
    7
    crm(live)configure# order myserver_after_mydata Mandatory: mydata myserver
    8
    crm(live)configure# order myserver_after_myip Mandatory: myip myserver
    9
    crm(live)configure# veify
    10
    crm(live)configure# commit
    11
    crm(live)configure# cd ..
    12
    crm(live)# status
    13
    Stack: classic openais (with plugin)
    14
    Current DC: node1 (version 1.1.15-5.el6-e174ec8) - partition with quorum
    15
    Last updated: Fri May 19 08:25:05 2017          Last change: Fri May 19 08:25:00 2017 by root via cibadmin on node1
    16
    , 2 expected votes
    17
    2 nodes and 2 resources configured
    18
    19
    Online: [ node1 node2 ]
    20
    21
    Full list of resources:
    22
    23
     Master/Slave Set: ms_mysqlstore [mysqlstore]
    24
         Masters: [ node1 ]
    25
         Slaves: [ node2 ]
    26
     mydata (ocf::heartbeat:Filesystem):    Started node1
    27
     myip   (ocf::heartbeat:IPaddr)         Started node1
    28
     myserver     (lsb:mysqld)          Started node1

这样就完成了整个集群的简单配置,而且drbd也不存在单点问题,是个十分高效便利的高可用解决方案。

CATALOG
  1. 1. DRBD
    1. 1.1. 框架构建
  2. 2. 集群配置