一、前提准备:

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. java csv - 读写及其操作.

    今天帮同学处理数据, 主要是从1w多条记录中随机获取8k条, 然后再从8k条记录中随机获取2k条记录. 最后将2k条记录中随机分成10组,使得每组的记录都不重复. 下面将我的代码都贴上来, 好以后处理 ...

  2. Stream To String , String To Stream

    public static string StreamToString(Stream stream) { stream.Position = 0; using (StreamReader stremR ...

  3. 【html】【1】html的简单结构

    1>我们为什么能打开html网页 计算机本身有个配置文件后缀打开程序的默认,好比:.txt =>记事本打开   html=>浏览器打开 文件一切的鼻祖都起源于.txt文件,你只要修改 ...

  4. windows 远程连接linux服务器

    百度搜索“SSH Secure Shell Client” 并下载 2 点击Profiles选择add profiles 并添加profils名称 3 点击Profiles 填写远程linux的ip ...

  5. LBP特征提取实现

    捯饬了一两天才搞好! 在lbp.m下输入下面代码,运行结果如图: 代码: I=imread('rice.png'); mapping=getmapping(8,'u2'); H1=lbp(I,1,8, ...

  6. ubuntu安装配置搜狗拼音输入法

    进入下载目录,在终端执行安装 $sudo dpkg  -i   sogou_pinyin_linux_1.0.0.0033_amd64.deb 安装过程会出现 依赖关系问题 2 修复依赖关系完成搜狗拼 ...

  7. jQuery插件综合应用(三)发布文章页面

    一.使用的插件 一个折叠的功能导航,由Akordeon插件实现.Nanoscroller插件与Tagit插件主要用于美化页面.这里只是测试,其实还可以综合使用其它的插件,例如将Akordeon插件换成 ...

  8. 20 Valid Parentheses(匹配括号)

    题目意思:判断一个字符串(){}[]是否符合 思路:用栈ps:实习一个多月了,代码也刷不动了,状态真不是一般的差 class Solution { public: bool isValid(strin ...

  9. Convention插件与“约定”支持

    主要用于Action映射和Result映射 struts2-convention-plugin-2.3.16.3.jar 会将 |--实现了com.opensymphony.xwork2.Action ...

  10. java 使用substring 截取特殊字符串的后一位或者数字

    关于截取特殊的字符串的后一位或者数字 需求:截取特殊字符为  .   后一位 String[] str = uri.split("/"); String str1 = str[st ...