corosync+drbd+mysqlクラスタ
計画:
vip:192.168.1.254
rs1:192.168.1.215
rs2:192.168.1.216
一、ホストバインド(rs 2同じ)
二、デュアルマシンの相互通信を配置する(rs 2は同じ)
三、corosyncの構成
四、drbdとmysqlの構成
五、mysqlの配置
六、crmコマンドラインcorosync
1、drbd主従自動切替の設定
2、drbd自動マウントの設定
3、mysqlリソースの構成
4、vip資源の配置
vip:192.168.1.254
rs1:192.168.1.215
rs2:192.168.1.216
一、ホストバインド(rs 2同じ)
[root@rs1 ~]# cat /etc/hosts
192.168.1.215 rs1.china-kody.com rs1
192.168.1.216 rs2.china-kody.com rs2
二、デュアルマシンの相互通信を配置する(rs 2は同じ)
[root@rs1 ~]# ssh-key -t rsa -P '' -f /root/.ssh/id_rsa
[root@rs1 ~]# ssh-copy-id -f /root/.ssh/id_rsa.pub rs2
三、corosyncの構成
[root@rs1 ~]# vim /etc/corosync/corosync.conf
service {
ver: 0
name: pacemaker
}
aisexec {
user: root
group: root
}
[root@rs1 ~]# vim /etc/corosync/corosync.conf
[root@rs1 ~]# scp /etc/corosync/{authkey,corosync.conf} rs2:/etc/corosync
四、drbdとmysqlの構成
[root@rs1 ~]# vim /etc/drbd.d/global_common.conf
handlers {
pri-on-incon-degr "/usr/lib/drbd/notify-pri-on-incon-degr.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";
pri-lost-after-sb "/usr/lib/drbd/notify-pri-lost-after-sb.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";
local-io-error "/usr/lib/drbd/notify-io-error.sh; /usr/lib/drbd/notify-emergency-;
}
disk {
on-io-error detach;
}
net {
cram-hmac-alg "sha1";
shared-secret "d0CJpSlaSod4Xg";
}
vim /etc/drbd.d/mysqldb.rgs
resource mysqldb {
meta-disk internal;
device /dev/drbd0 ;
on rs1.china-kody.com {
address 192.168.5.251:7789;
disk /dev/sdb1;
}
on rs2.china-kody.com {
address 192.168.5.252:7789;
disk /dev/sdb1;
}
}
[root@rs1 ~]# drbdadm create-md mysqldrbd
[root@rs2 ~]# drbdadm create-md mysqldrbd
[root@rs1 ~]# service drbd start
[root@rs2 ~]# service drbd start
[root@rs1 ~]# chkconfig drbd off
[root@rs2 ~]# chkconfig drbd off
[root@rs1 ~]# drbdadm -- --overwrite-data-of-peer primary all
[root@rs1 ~]# mke2fs -j /dev/drbd0
[root@rs1 ~]# mount /dev/drbd0 /mydata/data
mysql...
[root@rs1 ~]# umount /dev/drbd0
[root@rs1 ^]# drbdadm seconary mysqlbd
五、mysqlの配置
[root@rs1 ~]# groupadd -g 306 mysql
[root@rs1 ~]# useradd -u 306 -g mysql -s /sbin/nologin mysql
[root@rs1 ~]# id mysql
uid=306(mysql) gid=306(mysql) group=306(mysql)
[root@rs1 ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql datadir=/mydata/data
[root@rs1 /]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@rs1 /]# chkconfig --add mysql
[root@rs1 /]# chkconfig mysql off
[root@rs1 /]# cp /usr/local/mysql/support-files/my-default.cnf/etc/my.cnf
[root@rs1 /]# vim /etc/my.cnf datadir = /mydata/data
rs1、rs2、 , 。
, .
六、crmコマンドラインcorosync
1、drbd主従自動切替の設定
primitive mysqldrbd ocf:linbit:drbd \
params drbd_resource=mysqldrbd \
op start timeout=240 interval=0 \
op stop timeout=100 interval=0 \
op monitor role=Master interval=20 timeout=30 \
op monitor role=Slave interval=30 timeout=30
ms ms_mysqldrbd mysqldrbd \
meta master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify=true
crm(live)# status
Online: [ rs1.china-kody.com rs2.china-kody.com ]
Master/Slave Set: ms_mysqldrbd [mysqldrbd]
Masters: [ rs1.china-kody.com ]
Slaves: [ rs2.china-kody.com ]
2、drbd自動マウントの設定
primitive mysqlstore Filesystem \
params device="/dev/drbd0" directory="/mydata" fstype=ext3 \
op start timeout=60 interval=0 \
op stop timeout=60 interval=0
colocation mysqlstore_with_ms_mysqldrbd inf: mysqlstore ms_mysqldrbd:Master
order mystore_after_ms_mysqldrbd Mandatory: ms_mysqldrbd:promote mysqlstore:start
Online: [ rs1.china-kody.com rs2.china-kody.com ]
Master/Slave Set: ms_mysqldrbd [mysqldrbd]
Masters: [ rs2.china-kody.com ]
Slaves: [ rs1.china-kody.com ]
mysqlstore (ocf::heartbeat:Filesystem): Started rs2.china-kody.com
3、mysqlリソースの構成
primitive mysqld lsb:mysql \
meta target-role=Started
colocation mysqld_with_mysqlstore inf: mysqld mysqlstore
order mysqld_after_mysqlstore Mandatory: mysqlstore mysqld
Node rs2.china-kody.com: standby
Online: [ rs1.china-kody.com ]
Master/Slave Set: ms_mysqldrbd [mysqldrbd]
Masters: [ rs1.china-kody.com ]
Stopped: [ rs2.china-kody.com ]
mysqlstore (ocf::heartbeat:Filesystem): Started rs1.china-kody.com
mysqld (lsb:mysql): Started rs1.china-kody.com
4、vip資源の配置
colocation mysqlvip_with_mysqld inf: mysqlvip mysqld
Master/Slave Set: ms_mysqldrbd [mysqldrbd]
Masters: [ rs1.china-kody.com ]
Slaves: [ rs2.china-kody.com ]
mysqlstore (ocf::heartbeat:Filesystem): Started rs1.china-kody.com
mysqld (lsb:mysql): Started rs1.china-kody.com
mysqlvip (ocf::heartbeat:IPaddr): Started rs1.china-kody.com