【原】ubuntu下Mysql的HA(corosync+pacemaker+drbd)
一、前提准备:
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)的更多相关文章
- Ubuntu下MySql配置
Ubuntu下MySql配置 安装MySQL 命令: sudo apt-get install mysql-server MySQL初始配置及管理 启动MySQL mysql start : mysq ...
- Ubuntu下MySQL忘记root密码重置
MySQL忘记root密码肿么办?-_-||| 这种情况虽然不是很常见,但是有时长时间没有登录系统,还真会忘记密码.这时候,如果您能以系统管理员权限登陆密码,那还是有救的.放大招,将其重置即可. ...
- ubuntu下mysql的环境搭建及使用
ubuntu下mysql的环境搭建及使用 环境安装 使用如下命令分别安装服务端程序,客户端程序,及客户端依赖库 sudo apt-get install mysql-server sudo apt-g ...
- ubuntu 下 mysql数据库的搭建 及 数据迁移
1.mysql的安装 我是使用apt-get直接安装的 :sudo apt-get install mysql-server sudo apt-get install mysql-client 2.配 ...
- 远程访问ubuntu下mysql的问题
ubuntu下mysql不能用IP地址远程访问的问题解决 方法1: 1.mysql>grant all privileges on *.* to 'root'@'%' identified by ...
- ubuntu下mysql安装(server、client、dev),开启、停止和重启,及常见错误
转自:ubuntu下mysql安装(server.client.dev),开启.停止和重启,及常见错误 1. 在ubuntu下安装server和client很简单: (1)安装server apt-g ...
- Centos 7 下 Corosync + Pacemaker + DRBD + psc + crmsh 实现 mysql 服务高可用
一.介绍 高可用,大家可能会想到比较简单的Keepalived,或者更早一点的 heartbeat,也可能会用到 Corosync+Pacemaker,那么他们之间有什么区别. Heartbeat到了 ...
- Corosync+Pacemaker+DRBD+MySQL 实现高可用(HA)的MySQL集群
大纲一.前言二.环境准备三.Corosync 安装与配置四.Pacemaker 安装与配置五.DRBD 安装与配置六.MySQL 安装与配置七.crmsh 资源管理 推荐阅读: Linux 高可用(H ...
- ubuntu下MySQL中文乱码(新版本Mysql修改方法)
前几天在开发的时候出现了中文查询阿里云服务器上的mysql的时候,查询出来的值为空,找了好久终于发现原因是ubuntu下的mysql无法识别中文,这就涉及到要调整编码格式啦!!!! 然后就在网上查了许 ...
随机推荐
- oracle学习笔记1:windows下oracle数据库安装及.net调用oracle数据库
1.下载32位或64位oracle数据库并且安装,安装时可以选择安装数据库实例或者不安装,如果不安装的话之后可以用Database Configuration Assistant(DBCA) 通过向导 ...
- Azure cache 的配置与应用
最近公司的项目要是用cloud Service 所以研究了下 Azure cache 的配置与使用. 首先创建项目 第二步 配置 cache worker role (1) 点击 cache work ...
- jQuery源码整体结构(源码2.0.3)
拨开jQuery的面纱,最近了解了下jQuery源码整体框架.主要包括: (1) jQuery 核心模块 (2) sizzle 选择器引擎 (3) Deferred 异步队列 (4) Supp ...
- javascript div跟随鼠标移动
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- js实现中文简繁切换效果
html代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www ...
- JavaScript学习心得(四)
条件语句 任何事物非真即假. 在JavaScript中,条件判断以下情况为假: false NaN 0 空串 null undefined 在使用相等运算符时,建议将数字写在相等运算符的左边.全等比较 ...
- C语言的编译过程和GCC编译参数
C语言的编译一般有三个步骤: 预编译: gcc -E -o a.e a.c 预编译a.c文件,生成的目标文件名为a.e 预编译就是将include包含的头文件内容替换到C文件中,同时删除代码中没用的注 ...
- WebApi学习总结系列第三篇(Http)此篇持续更新...
越了解Http对WebApi开发就越有帮助,因为WebApi就是建立在Http基础之上的. 一.Http: 通过 <ASP.NET Web API 2 框架揭秘>一书中 了解到 什么叫We ...
- linux下安装MySQL5.6记录
把之前装的mysql卸载了,准备重新用代码包装一遍,问了一下公司的DBA,他推荐给我mysql-5.6.16版本,说这个版本比较稳定. 按照网上的教程安装,结果就少文件,我还在找原因的时候,同事来找我 ...
- jsp分页技术
1.以下为分页类: import java.io.Serializable; import java.util.List; import org.apache.commons.lang.bui ...