一、前提准备:

1、OS:ubuntu 12.04

2、cat /etc/hosts:

 127.0.0.1 localhost
192.168.153.154 ha1
192.168.153.155 ha2

3、硬盘:/dev/sdb1

4、vip:192.168.153.200

二、corosync和pacemaker的安装配置:

1、[ha1+ha2]:

 apt-get install -y pacemaker corosync

2、[ha1]:

1 corosync-keygen(时间较长)
2 scp /etc/corosync/authkey root@ha2:/etc/corosync/

3、[ha1+ha2]:取消corosync和pacemaker的开机启动:

 apt-get install -y sysv-rc-conf
sysv-rc-conf(使用空格把drbd,pacemaker,corosync有X的地方取消掉,q退出)
sed -i 's/127.0.0.1/192.168.153.0/g' /etc/corosync/corosync.conf
sed -i 's/ver: 0/ver: 1/g' /etc/corosync/corosync.conf
mkdir /var/log/cluster
update-rc.d pacemaker start . stop .
sed -i 's/no/yes/g' /etc/default/corosync
service corosync start
corosync-cfgtool -s
corosync-quorumtool -l
service pacemaker start
验证:crm status root@ha1:~# crm status
============
Last updated: Tue Feb ::
Last change: Tue Feb :: via crmd on ha1
Stack: openais
Current DC: ha1 - partition with quorum
Version: 1.1.-9971ebba4494012a93c03b40a2c58ec0eb60f50c
Nodes configured, expected votes
Resources configured.
============ Online: [ ha1 ha2 ]

三、drbd的安装配置:

1、[ha1+ha2]:drbd的安装:

 tar -zxvf drbd8_8.4.4.orig.tar.gz(由于drbd8..2有bug,所以这里选择手动安装8..4版本)
apt-get install -y debhelper flex xsltproc
cd drbd8_8.4.4
./configure --localstatedir=/var --sysconfdir=/etc --with-km
make && make install

2、[ha1+ha2]:创建磁盘:

 fdisk /dev/sdb
n
p ...
w

3、[ha1+ha2]:创建drbd的mysql资源:

 cat /etc/drbd.d/mysql.res
resource mysql {
device /dev/drbd0;
disk /dev/sdb1;
meta-disk internal;
on ha1 {
address 192.168.153.154:;
}
on ha2 {
address 192.168.153.155:;
}
syncer {
rate 10M;
}
}
echo -e 'drbd # -> added' >> /etc/modules
drbdadm dump mysql
drbdadm create-md mysql
drbdadm up mysql
验证:drbd-overview
:mysql/ Connected Secondary/Secondary Inconsistent/Inconsistent C r-----

4、[ha1]:

 drbdadm -- --overwrite-data-of-peer primary mysql
cat /proc/drbd:
root@ha1:~# cat /proc/drbd
version: 8.4. (api:/proto:-)
GIT-hash: 599f286440bd633d15d5ff985204aff4bccffadd build by root@ha1, -- ::
: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r-----
ns: nr: dw: dr: al: bm: lo: pe: ua: ap: ep: wo:f oos:
[>....................] sync'ed: 0.6% (20372/20476)M
finish: :: speed: , (,) K/sec
直到同步100%的时候才成功。结果是:
root@ha1:~# cat /proc/drbd
version: 8.4. (api:/proto:-)
GIT-hash: 599f286440bd633d15d5ff985204aff4bccffadd build by root@ha1, -- ::
: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
ns: nr: dw: dr: al: bm: lo: pe: ua: ap: ep: wo:f oos:
service drbd restart
mkfs.ext4 /dev/drbd0
mkdir /mydata
mount /dev/drbd0 /mydata
mkdir -p /mydata/testfile
umount /dev/drbd0
drbdadm secondary mysql

5、[ha2]:

 service drbd restart
drbdadm primary mysql
mkdir /mydata
mount /dev/drbd0 /mydata
ll /mydata/ 如果可以看到testfile说明成功。
umount /dev/drbd0
drbdadm secondary mysql(如果中间出现错误,可以把ha1和ha2的drbd重启即可。)

6、[ha1]:

 drbdadm primary mysql

7、[ha1+ha2]:mysql的安装配置

 apt-get install -y mysql-server
sed -i 's/127.0.0.1/0.0.0.0/g' /etc/mysql/my.cnf
service mysql restart
mysql -uroot -p
grant all privileges on *.* to root@"%" identified by "password" with grant option;
FLUSH PRIVILEGES;
delete from mysql.user where user="";
quit;
service mysql stop

8、[ha1]:

 drbdadm primary mysql
drbd-overview
mount /dev/drbd0 /mydata
cp -R -p /var/lib/mysql /mydata/

9、[ha1+ha2]:

 sed -i 's/2345/!0123456/g' /etc/init/mysql.conf
sed -i -e '/datadir/cdatadir = \/mydata\/mysql' /etc/mysql/my.cnf
sed -i '/\/var\/lib\/mysql\/ /c\/mydata\/mysql\/ r,' /etc/apparmor.d/usr.sbin.mysqld
sed -i '/\/var\/lib\/mysql\/\*\* rwk/c\/mydata\/mysql\/** rwk,' /etc/apparmor.d/usr.sbin.mysqld

10、[ha1]:

 service mysql start
mysql -uroot -p
CREATE DATABASE test1;
quit
service mysql stop
umount /dev/drbd0
drbdadm secondary mysql

11、[ha2]:

 drbdadm primary mysql
mount /dev/drbd0 /mydata/
service mysql start
查看是否有数据库test1
service mysql stop
umount /dev/drbd0
drbdadm secondary mysql

12、[ha1]:

 drbdadm primary mysql

13、[ha1+ha2]:

 service drbd stop

14、[ha1]:

 crm configure property stonith-enabled=false
crm configure property no-quorum-policy=ignore crm configure
primitive mysqldrbd ocf:heartbeat:drbd params drbd_resource=mysql op start timeout= op stop timeout= op monitor role=Master interval= timeout= op monitor role=Slave interval= timeout=
ms ms_mysqldrbd mysqldrbd meta master-max= master-node-max= clone-max= clone-node-max= notify=true
commit
exit
验证:crm status
root@ha1:~# crm status
============
Last updated: Tue Feb ::
Last change: Tue Feb :: via cibadmin on ha1
Stack: openais
Current DC: ha1 - partition with quorum
Version: 1.1.-9971ebba4494012a93c03b40a2c58ec0eb60f50c
Nodes configured, expected votes
Resources configured.
============ Online: [ ha1 ha2 ] Master/Slave Set: ms_mysqldrbd [mysqldrbd]
Masters: [ ha1 ]
Slaves: [ ha2 ] crm configure
primitive mystore ocf:heartbeat:Filesystem params device=/dev/drbd0 directory=/mydata fstype=ext4 op start timeout= op stop timeout=
colocation mystore_with_ms_mysqldrbd inf: mystore ms_mysqldrbd:Master
order mystore_after_ms_mysqldrbd mandatory: ms_mysqldrbd:promote mystore:start
commit
exit
验证:crm status,mount
Master/Slave Set: ms_mysqldrbd [mysqldrbd]
Masters: [ ha1 ]
Slaves: [ ha2 ]
mystore (ocf::heartbeat:Filesystem): Started ha1 crm configure
primitive mysql lsb:mysql
colocation mysql_with_mystore inf: mysql mystore
order mysql_after_mystore mandatory: mystore mysql
commit
exit
验证:crm status
Master/Slave Set: ms_mysqldrbd [mysqldrbd]
Masters: [ ha1 ]
Slaves: [ ha2 ]
mystore (ocf::heartbeat:Filesystem): Started ha1
mysql (lsb:mysql): Started ha1 crm configure
primitive vip ocf:heartbeat:IPaddr params ip=192.168.153.200 nic=eth0 cidr_netmask=255.255.255.0
colocation vip_with_ms_mysqldrbd inf: ms_mysqldrbd:Master vip
commit
exit
验证crm status
Master/Slave Set: ms_mysqldrbd [mysqldrbd]
Masters: [ ha1 ]
Slaves: [ ha2 ]
mystore (ocf::heartbeat:Filesystem): Started ha1
mysql (lsb:mysql): Started ha1
vip (ocf::heartbeat:IPaddr): Started ha1

四、验证:

1、客户端mysql验证:

 mysql -uroot -p -h 192.168.153.200
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| test1 |
+--------------------+

2、模拟故障:

 root@ha1:~# crm
crm(live)# node
crm(live)node# standby
crm(live)node# show
ha1: normal
standby: on
ha2: normal
crm(live)node# exit
bye
此时看一下状态:
root@ha1:~# crm status
Node ha1: standby
Online: [ ha2 ] Master/Slave Set: ms_mysqldrbd [mysqldrbd]
Masters: [ ha2 ]
Stopped: [ mysqldrbd: ]
mystore (ocf::heartbeat:Filesystem): Started ha2
mysql (lsb:mysql): Started ha2
vip (ocf::heartbeat:IPaddr): Started ha2

此时,mysql已经运行于ha2上了。

【原】ubuntu下Mysql的HA(corosync+pacemaker+drbd)的更多相关文章

  1. Ubuntu下MySql配置

    Ubuntu下MySql配置 安装MySQL 命令: sudo apt-get install mysql-server MySQL初始配置及管理 启动MySQL mysql start : mysq ...

  2. Ubuntu下MySQL忘记root密码重置

    MySQL忘记root密码肿么办?-_-|||   这种情况虽然不是很常见,但是有时长时间没有登录系统,还真会忘记密码.这时候,如果您能以系统管理员权限登陆密码,那还是有救的.放大招,将其重置即可. ...

  3. ubuntu下mysql的环境搭建及使用

    ubuntu下mysql的环境搭建及使用 环境安装 使用如下命令分别安装服务端程序,客户端程序,及客户端依赖库 sudo apt-get install mysql-server sudo apt-g ...

  4. ubuntu 下 mysql数据库的搭建 及 数据迁移

    1.mysql的安装 我是使用apt-get直接安装的 :sudo apt-get install mysql-server sudo apt-get install mysql-client 2.配 ...

  5. 远程访问ubuntu下mysql的问题

    ubuntu下mysql不能用IP地址远程访问的问题解决 方法1: 1.mysql>grant all privileges on *.* to 'root'@'%' identified by ...

  6. ubuntu下mysql安装(server、client、dev),开启、停止和重启,及常见错误

    转自:ubuntu下mysql安装(server.client.dev),开启.停止和重启,及常见错误 1. 在ubuntu下安装server和client很简单: (1)安装server apt-g ...

  7. Centos 7 下 Corosync + Pacemaker + DRBD + psc + crmsh 实现 mysql 服务高可用

    一.介绍 高可用,大家可能会想到比较简单的Keepalived,或者更早一点的 heartbeat,也可能会用到 Corosync+Pacemaker,那么他们之间有什么区别. Heartbeat到了 ...

  8. Corosync+Pacemaker+DRBD+MySQL 实现高可用(HA)的MySQL集群

    大纲一.前言二.环境准备三.Corosync 安装与配置四.Pacemaker 安装与配置五.DRBD 安装与配置六.MySQL 安装与配置七.crmsh 资源管理 推荐阅读: Linux 高可用(H ...

  9. ubuntu下MySQL中文乱码(新版本Mysql修改方法)

    前几天在开发的时候出现了中文查询阿里云服务器上的mysql的时候,查询出来的值为空,找了好久终于发现原因是ubuntu下的mysql无法识别中文,这就涉及到要调整编码格式啦!!!! 然后就在网上查了许 ...

随机推荐

  1. Ubuntu12.04中安装ns-allinone-2.34

    1.首先安装ns2所需的组件.库之类: $sudo apt-get update $sudo apt-get install build-essential $ tcl8.-dev tk8. tk8. ...

  2. Swift基础知识入门(基于Swift2.0)

    //: Playground - noun: a place where people can play import UIKit // Swift中不需要设置main函数入口,编译器会在全局函数中自 ...

  3. C++专题 - 面向对象总结

    1.         什么是类?什么是对象?对象与类的关系是什么? 答:类就是相同的数据和相同的一组对象的集合,即类是对具有相同数据结构和相同操作的一类对象的描述: 对象是描述其属性的数据以及对这些数 ...

  4. android入门到熟练(一)

    1.andro系统架构:Linux内核层(提供驱动),系统运行库层和android运行时库(提供C/C++库的主要特性,如SQLite,OpenGL,Webkit等和Dalvik虚拟机),应用框架层, ...

  5. CentOS7 开关防火墙

    systemctl start firewalld.service#启动firewallsystemctl stop firewalld.service#停止firewallsystemctl dis ...

  6. TCPIP通信

    最近在开发TCPIP通信,封装了3个类,望各位大神指点指点. using System; using System.Collections.Generic; using System.Text; us ...

  7. 初试jQuery EasyUI

    jQuery EasyUI jQuery EasyUI是一组基于jQuery的UI插件集合,而jQuery EasyUI的目标就是帮助web开发者更轻松的打造出功能丰富并且美观的UI界面.开发者不需要 ...

  8. TreeList

    1.获取当前被选中的节点数据 string tmp = treeL.FocusedNode.GetDisplayText(this.treeListColumnIndex); 2.是否允许编辑 tre ...

  9. 设置(TableViewController)通用框架

    本文学习于传播播客.李明杰老师.感谢

  10. partial函数-python学习

    一个函数可以有多个参数,而在有的情况下有的参数先得到,有的参数需要在后面的情景中才能知道,python 给我们提供了partial函数用于携带部分参数生成一个新函数. def add(a,b,c=2) ...