欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

Mysql+Corosync+Pacemaker+DRBD_MySQL

程序员文章站 2022-05-14 16:51:56
...
1、环境介绍
OS:centos 6.5
kernel:2.6.32-431.11.2.el6.x86_64
node1:nginxha001 10.0.15.31 Master
node2:nginxha002 10.0.15.32 Slave
vip:10.0.15.30
说明:本例主要以drbd为主,涉及到mysql,corosync,pacemaker程序的安装请参考其他资料。程序两台都要安装,定义drbd资源可在一台上配置完毕复制到另外一台,创建磁盘需两台都创建,定义corosync资源只需在一台上配置即可,他会自动同步到另外一台。若程序连接mysql用虚拟ip即vip连接,最好是把程序也部署在drbd磁盘上,这样程序配置为localhost即可。

2、安装依赖包
yum -y install gcc rpm-build kernel-devel kernel-headers flex ncurses-devel

wget http://elrepo.org/linux/elrepo/el5/x86_64/RPMS/drbd84-utils-8.4.3-1.el5.elrepo.x86_64.rpm
wget http://elrepo.org/linux/elrepo/el6/x86_64/RPMS/kmod-drbd84-8.4.3-1.el6_4.elrepo.x86_64.rpm
yum -y install drbd84-utils-8.4.3-1.el5.elrepo.x86_64.rpm
yum install -y kmod-drbd84-8.4.3-1.el6_4.elrepo.x86_64.rpm

3、定义drbd资源
vi /etc/drbd.d/mysql.res #定义mysql资源,效果一样
resource mysql {
protocol C;
device /dev/drbd0;
disk /dev/sdc1;
meta-disk internal;
on nginxha001 {
address 10.0.15.31:7789;
}
on nginxha002 {
address 10.0.15.32:7789;
}
}


4、启动服务,并格式化磁盘
创建drbd数据同步所需的分区,两台电脑的空间要一样大
fdisk /dev/sdc
drbdadm create-md mysql
service drbd start

设置为主几点,仅在主节点上操作
drbdadm -- --overwrite-data-of-peer primary mysql
创建文件系统
mkfs -t ext4 /dev/drbd0

5、配置corosync资源
crm(live)# configure
property stonith-enabled=false
property no-quorum-policy=ignore
定义Mysql服务资源
primitive Mysqld lsb:mysqld
配置DRBD主从资源
primitive Drbd ocf:linbit:drbd params drbd_resource="mysql" op start interval="0" timeout="240" op stop interval="0" timeout="100"
master My_Drbd Drbd meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true"
定义一个文件系统资源
primitive FileSys ocf:heartbeat:Filesystem params device="/dev/drbd0" directory="/mysqldata" fstype="ext4" op start timeout="60s" op stop timeout="60s"
定将资源之间的位置和启动顺序约束
#让文件系统与DRBD主节点运行在一起
colocation FileSys_on_My_Drbd inf: FileSys My_Drbd
#让DRBD服务比文件系统先启动
order FileSys_after_My_Drbd inf: My_Drbd:promote FileSys:start
#让Mysql服务与文件系统运行在一起
colocation Mysqld_on_FileSys inf: Mysqld FileSys
#让文件系统比Mysql服务先运行
order Mysqld_after_FileSys inf: FileSys Mysqld:start
#让虚拟IP与Mysql服务运行在一起
colocation vip_on_Mysqld inf: vip Mysqld

执行完毕后,最后的配置文件如下:
node nginxha001 /
attributes standby="off"
node nginxha002 /
attributes standby="off"
primitive Drbd ocf:linbit:drbd /
params drbd_resource="mysql" /
op monitor interval="10s" role="Master" /
op monitor interval="20s" role="Slave" /
op start timeout="240s" interval="0" /
op stop timeout="100" interval="0"
primitive FileSys ocf:heartbeat:Filesystem /
params device="/dev/drbd0" directory="/mysqldata" fstype="ext4" /
op start timeout="60s" interval="0" /
op stop timeout="60s" interval="0"
primitive Mysqld lsb:mysqld
primitive vip ocf:heartbeat:IPaddr /
params ip="10.1.15.30" nic="eth0" cidr_netmask="24" /
op monitor interval="10s"
ms My_Drbd Drbd /
meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true"
colocation FileSys_on_My_Drbd inf: FileSys My_Drbd:Master
colocation Mysqld_on_FileSys inf: Mysqld FileSys
colocation vip_on_Mysqld inf: vip Mysqld
order FileSys_after_My_Drbd inf: My_Drbd:promote FileSys:start
order Mysqld_after_FileSys inf: FileSys Mysqld:start
property $id="cib-bootstrap-options" /
dc-version="1.1.10-14.el6_5.2-368c726" /
cluster-infrastructure="classic openais (with plugin)" /
expected-quorum-votes="4" /
stonith-enabled="false" /
no-quorum-policy="ignore" /
last-lrm-refresh="1396576217"
rsc_defaults $id="rsc-options" /
resource-stickiness="100"
#vim:set syntax=pcmk


若有有错误,执行如下命令清除错误即可
crm resource cleanup Mysqld
crm resource cleanup vip
crm resource cleanup FileSys

6、其他命令
挂载drbdo
mount /dev/drbd0 /mysqldata/
卸载
umount /mysqldata/
设置drbd为主,只有设置为主的才能挂载磁盘
drbdadm primary mysql
设置drbd为备用
drbdadm secondary mysql

watch -n1 'drbd-overview' 观察数据同步情况,ctrl+c退出。
drbd-overview #查看状态,当为下面内容时,进行下一步操作
cat /proc/drbd 查看同步进度

7、修改my.cnf配置,主要更改数据目录为drbd的目录
vi /etc/my.cnf

[mysqld]
datadir=/mysqldata
socket=/mysqldata/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/mysqldata/mysqld.log
pid-file=/mysqldata/mysqld.pid
[client]
socket=/mysqldata/mysql.sock

相关标签: mysql 程序