搭建基于Corosync+DRBD的高可用MySQL集群(3)

 

 

首页服务器应用

背景:

阅读新闻

搭建基于Corosync+DRBD的高可用MySQL集群

[日期:2013-10-14]   来源:Linux社区  作者:phenixikki   [字体:]  

10、配置高可用MySQL集群服务
<1> 在各个节点上安装MySQL服务(SteppingStone)
这里使用通用二进制安装mysql-5.5.28版本
# for I in {1..2};do scp mysql-5.5.28-linux2.6-i686.tar.gz node$I:/usr/src/;done
# step 'tar -xf /usr/src/mysql-5.5.28-linux2.6-i686.tar.gz -C /usr/local'
# step 'ln -sv /usr/local/mysql-5.5.28-linux2.6-i686 /usr/local/mysql'
# step 'groupadd -g 3306 mysql'     
# step 'useradd -u 3306 -g mysql -s /sbin/nologin -M mysql
# step 'mkdir /mydata/data'
# step 'chown -R mysql.mysql /mydata/data'
# step 'chown -R root.mysql /usr/local/mysql/*'
# step 'cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf'
# step 'cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld'
# step 'chkconfig --add mysqld'

<2> 在主节点上初始化MySQL并配置启动测试(Node2)
12345678 # cd /usr/local/mysql
# scripts/mysql_install_db --user=mysql --datadir=/mydata/data
# vim /etc/my.cnf
在[mysqld]下添加如下:
datadir = /mydata/data
# service mysqld start
# service mysqld stop
# chkconfig mysqld off

<3> 将Node1设置为主节点并配置MySQL(无需再次初始化)
将node2设置为standby,则资源转移至node1
# crm node standby
# crm node online

在node1上配置MySQL服务并启动测试
# vim /etc/my.cnf
在[mysqld]下添加如下内容:
datadir = /mydata/data
# service mysqld start
# service mysqld stop
# chkconfig mysqld off

<4> 配置主资源mysqld和vip(Node1)
# crm configure primitive mysqld lsb:mysqld
# crm configure colocation mysqld_with_mystore inf: mysqld mystore
# crm configure order mysqld_after_mystore mandatory: mystore mysqld
# crm configure primitive vip ocf:heartbeat:IPaddr params ip=192.168.1.20 nic=eth0 cidr_netmask=24
# crm configure colocation vip_with_ms_mysqldrbd inf: ms_mysqldrbd:Master vip

查看资源的运行状态:

# crm status
============
Last updated: Sun Sep 22 13:03:27 2013
Stack: openais
Current DC: node1.linuxidc.com - partition with quorum
Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
2 Nodes configured, 2 expected votes
4 Resources configured.
============
Online: [ node2.linuxidc.com node1.linuxidc.com ]
 Master/Slave Set: ms_mysqldrbd [mysqldrbd]
    Masters: [ node1.linuxidc.com ]
    Slaves: [ node2.linuxidc.com ]
 mystore        (ocf::heartbeat:Filesystem):    Started node1.linuxidc.com
 mysqld (lsb:mysqld):  Started node1.linuxidc.com
 vip    (ocf::heartbeat:IPaddr):        Started node1.linuxidc.com

查看集群配置:
123456789101112131415161718192021222324252627282930313233 # crm configure show
node node1.linuxidc.com \
        attributes standby="off"
node node2.linuxidc.com \
        attributes standby="off"
primitive mysqld lsb:mysqld
primitive mysqldrbd ocf:linbit:drbd \
        params drbd_resource="mydrbd" \
        op start interval="0" timeout="240" \
        op stop interval="0" timeout="100" \
        op monitor interval="20" role="Master" timeout="30" \
        op monitor interval="30" role="Slave" timeout="30"
primitive mystore ocf:heartbeat:Filesystem \
        params device="/dev/drbd0" directory="/mydata" fstype="ext3" \
        op start interval="0" timeout="60" \
        op stop interval="0" timeout="60"
primitive vip ocf:heartbeat:IPaddr \
        params ip="192.168.1.20" nic="eth0" cidr_netmask="24"
ms ms_mysqldrbd mysqldrbd \
        meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true"
colocation mysqld_with_mystore inf: mysqld mystore
colocation mystore_with_ms_mysqldrbd inf: mystore ms_mysqldrbd:Master
colocation vip_with_ms_mysqldrbd inf: ms_mysqldrbd:Master vip
order mysqld_after_mystore inf: mystore mysqld
order mystore_after_ms_mysqldrbd inf: ms_mysqldrbd:promote mystore:start
property $id="cib-bootstrap-options" \
        dc-version="1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f" \
        cluster-infrastructure="openais" \
        expected-quorum-votes="2" \
        stonith-enabled="false" \
        no-quorum-policy="ignore"
rsc_defaults $id="rsc-options" \
        resource-stickiness="100"

11、模拟故障测试

在主节点上配置MysSQL远程访问账号(Node1)

# /usr/local/mysql/bin/mysql
mysql> grant all on *.* to root@'%' identified by 'linuxidc';
mysql> flush privileges;

在跳板机上远程测试访问(SteppingStone)
1 # mysql -uroot -h192.168.1.20 -p

将node1设置为standby并查看集群状态(Node1)
123456789101112131415161718 # crm node standby
# crm status
============
Last updated: Sun Sep 22 13:47:00 2013
Stack: openais
Current DC: node1.linuxidc.com - partition with quorum
Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
2 Nodes configured, 2 expected votes
4 Resources configured.
============
Node node1.linuxidc.com: standby
Online: [ node2.linuxidc.com ]
 Master/Slave Set: ms_mysqldrbd [mysqldrbd]
    Masters: [ node2.linuxidc.com ]
    Stopped: [ mysqldrbd:0 ]
 mystore        (ocf::heartbeat:Filesystem):    Started node2.linuxidc.com
 mysqld (lsb:mysqld):  Started node2.linuxidc.com
 vip    (ocf::heartbeat:IPaddr):        Started node2.linuxidc.com

在跳板机上远程测试访问(SteppingStone)
# mysql -uroot -h192.168.1.20 -p

将node1设置为online并查看集群状态(Node1)
# crm node online
# crm status
============
Last updated: Sun Sep 22 13:52:09 2013
Stack: openais
Current DC: node1.linuxidc.com - partition with quorum
Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
2 Nodes configured, 2 expected votes
4 Resources configured.
============
Online: [ node2.linuxidc.com node1.linuxidc.com ]
 Master/Slave Set: ms_mysqldrbd [mysqldrbd]
    Masters: [ node2.linuxidc.com ]
    Slaves: [ node1.linuxidc.com ]
 mystore        (ocf::heartbeat:Filesystem):    Started node2.linuxidc.com
 mysqld (lsb:mysqld):  Started node2.linuxidc.com
 vip    (ocf::heartbeat:IPaddr):        Started node2.linuxidc.com

 

DRBD脑裂故障处理

CentOS 上的 LNMP 一键安装工具 Centmin Mod

相关资讯      

   

本文评论   查看全部评论 (0)


评论声明

尊重网上道德,遵守中华人民共和国的各项有关法律法规

承担一切因您的行为而直接或间接导致的民事或刑事法律责任

本站管理人员有权保留或删除其管辖留言中的任意内容

本站有权在网站内转载或引用您的评论

参与本评论即表明您已经阅读并接受上述条款

 

 

 

最新资讯

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/1b40328ac44121e2afc0690d2e25cff5.html