MySQL+Corosync+Pacemaker+DRBD构建高可用MySQL
本次实验主要介绍Mysql的高可用集群构建;其他的不多说了,下面直接开始安装配置
CRM管理器下载:
具体下载目录在 /2013年资料/9月/22日/MySQL+Corosync+Pacemaker+DRBD构建高可用MySQL
一、环境介绍及准备
1、本次配置有两个节点:nod1.allen.com(172.16.14.1) 与 nod2.allen.com(172.16.14.2)
######在NOD1与NOD2节点执行如下命令
cat > /etc/hosts << EOF
172.16.14.1 nod1.allen.com nod1
172.16.14.2 nod2.allen.com nod2
EOF
注释:让所有节点的主机名称与对应的IP地址可以正常解析
2、每个节点的主机名称须跟"uname -n"命令的执行结果一样
######NOD1节点执行
sed -i 's@\(HOSTNAME=\).*@\1nod1.allen.com@g' /etc/sysconfig/network
hostname nod1.allen.com
######NOD2节点执行
sed -i 's@\(HOSTNAME=\).*@\1nod2.allen.com@g' /etc/sysconfig/network
hostname nod2.allen.com
注释:修改文件须重启系统生效,这里先修改文件然后执行命令修改主机名称可以不用重启
3、nod1与nod2两个节点上各提供了一个相同大小的分区作为DRBD设备,这里我们在两个节点上分别创建"/dev/sda3"作为DRBD设备,大小容量为2G
######在NOD1与NOD2节点上分别创建分区,分区大小必须保持一样
fdisk /dev/sda
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (7859-15665, default 7859):
Using default value 7859
Last cylinder, +cylinders or +size{K,M,G} (7859-15665, default 15665): +2G
Command (m for help): w
partx /dev/sda #让内核重新读取分区
######查看内核有没有识别分区,如果没有需要重新启动,这里没有识别需要重启系统
cat /proc/partitions
major minor #blocks name
8 0 125829120 sda
8 1 204800 sda1
8 2 62914560 sda2
253 0 20971520 dm-0
253 1 2097152 dm-1
253 2 10485760 dm-2
253 3 20971520 dm-3
reboot
4、关闭两台服务器的SELinux、Iptables与NetworkManager
setenforce 0 #关闭SELinux
service iptables stop #关闭Iptables
chkconfig iptables off #禁止Iptables开机启动
service NetworkManager stop
chkconfig NetworkManager off
chkconfig --list NetworkManager
NetworkManager 0:off 1:off 2:off 3:off 4:off 5:off 6:off
chkconfig network on
chkconfig --list network
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
注意:做的过程中必须关闭NetworkManager服务关闭并设置开机不能自动启动;将network服务设置开机自启动;否则作实验过程中会带来不必要的麻烦,造成集群系统不能正常运行
5、配置好YUM源并同步时间,且保证两个节点的时间要同步 epel源下载
######配置epel源
######在NOD1与NOD2节点分别安装
rpm -ivh epel-release-6-8.noarch.rpm
6、做双机互信
[root@nod1 ~]# ssh-keygen -t rsa
[root@nod1 ~]# ssh-copy-id -i .ssh/id_rsa.pub nod2
==================================================
[root@nod2 ~]# ssh-keygen -t rsa
[root@nod2 ~]# ssh-copy-id -i .ssh/id_rsa.pub nod1
7、系统版本:CentOS 6.4_x86_64
8、使用软件: 其中pacemaker与corosync在光盘映像中有
pssh-2.3.1-2.el6.x86_64 下载见附件
crmsh-1.2.6-4.el6.x86_64 下载见附件
drbd-8.4.3-33.el6.x86_64 DRBD下载地址:http://rpmfind.net
drbd-kmdl-2.6.32-358.el6-8.4.3-33.el6.x86_64
mysql-5.5.33-linux2.6-x86_64 点此下载
pacemaker-1.1.8-7.el6.x86_64
corosync-1.4.1-15.el6.x86_64
--------------------------------------------------------------------------------
二、安装配置DRBD DRBD详解
1、在NOD1与NOD2节点上安装DRBD软件包
######NOD1
[root@nod1 ~]# ls drbd-*
drbd-8.4.3-33.el6.x86_64.rpm drbd-kmdl-2.6.32-358.el6-8.4.3-33.el6.x86_64.rpm
[root@nod1 ~]# yum -y install drbd-*.rpm
######NOD2
[root@nod2 ~]# ls drbd-*
drbd-8.4.3-33.el6.x86_64.rpm drbd-kmdl-2.6.32-358.el6-8.4.3-33.el6.x86_64.rpm
[root@nod2 ~]# yum -y install drbd-*.rpm
2、查看DRBD配置文件
ll /etc/drbd.conf;ll /etc/drbd.d/
-rw-r--r-- 1 root root 133 May 14 21:12 /etc/drbd.conf #主配置文件
total 4
-rw-r--r-- 1 root root 1836 May 14 21:12 global_common.conf #全局配置文件
######查看主配置文件内容
cat /etc/drbd.conf
######主配置文件中包含了全局配置文件及"drbd.d/"目录下以.res结尾的文件
# You can find an example in /usr/share/doc/drbd.../drbd.conf.example
include "drbd.d/global_common.conf";
include "drbd.d/*.res";
3、修改配置文件如下:
[root@nod1 ~]#vim /etc/drbd.d/global_common.conf
global {
usage-count no; #是否参加DRBD使用统计,默认为yes
# minor-count dialog-refresh disable-ip-verification
}
common {
protocol C; #使用DRBD的同步协议
handlers {
# These are EXAMPLE handlers only.
# They may have severe implications,
# like hard resetting the node under certain circumstances.
# Be careful when chosing your poison.
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-shutdown.sh; echo o > /proc/sysrq-trigger ; halt -f";
# fence-peer "/usr/lib/drbd/crm-fence-peer.sh";
# split-brain "/usr/lib/drbd/notify-split-brain.sh root";
# out-of-sync "/usr/lib/drbd/notify-out-of-sync.sh root";
# before-resync-target "/usr/lib/drbd/snapshot-resync-target-lvm.sh -p 15 -- -c 16k";
# after-resync-target /usr/lib/drbd/unsnapshot-resync-target-lvm.sh;
}
startup {
# wfc-timeout degr-wfc-timeout outdated-wfc-timeout wait-after-sb
}
options {
# cpu-mask on-no-data-accessible
}
disk {
on-io-error detach; #配置I/O错误处理策略为分离
# size max-bio-bvecs on-io-error fencing disk-barrier disk-flushes
# disk-drain md-flushes resync-rate resync-after al-extents
# c-plan-ahead c-delay-target c-fill-target c-max-rate
# c-min-rate disk-timeout
}
net {
cram-hmac-alg "sha1"; #设置加密算法
shared-secret "allendrbd"; #设置加密密钥
# protocol timeout max-epoch-size max-buffers unplug-watermark
# connect-int ping-int sndbuf-size rcvbuf-size ko-count
# allow-two-primaries cram-hmac-alg shared-secret after-sb-0pri
# after-sb-1pri after-sb-2pri always-asbp rr-conflict
# ping-timeout data-integrity-alg tcp-cork on-congestion
# congestion-fill congestion-extents csums-alg verify-alg
# use-rle
}
syncer {
rate 1024M; #设置主备节点同步时的网络速率
}
}
4、添加资源文件:
[root@nod1 ~]# vim /etc/drbd.d/drbd.res
resource drbd {
on nod1.allen.com { #第个主机说明以on开头,后面是主机名称
device /dev/drbd0;#DRBD设备名称
disk /dev/sda3; #drbd0使用的磁盘分区为"sda3"
address 172.16.14.1:7789; #设置DRBD监听地址与端口
meta-disk internal;
}
on nod2.allen.com {
device /dev/drbd0;
disk /dev/sda3;
address 172.16.14.2:7789;
meta-disk internal;
}
}
5、将配置文件为NOD2提供一份
[root@nod1 ~]# scp /etc/drbd.d/{global_common.conf,drbd.res} nod2:/etc/drbd.d/
The authenticity of host 'nod2 (172.16.14.2)' can't be established.
RSA key fingerprint is 29:d3:28:85:20:a1:1f:2a:11:e5:88:cd:25:d0:95:c7.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'nod2' (RSA) to the list of known hosts.
root@nod2's password:
global_common.conf 100% 1943 1.9KB/s 00:00
drbd.res 100% 318 0.3KB/s 00:00
6、初始化资源并启动服务
######在NOD1与NOD2节点上初始化资源并启动服务
[root@nod1 ~]# drbdadm create-md drbd
Writing meta data...
initializing activity log
NOT initializing bitmap
lk_bdev_save(/var/lib/drbd/drbd-minor-0.lkbd) failed: No such file or directory
New drbd meta data block successfully created. #提示已经创建成功
lk_bdev_save(/var/lib/drbd/drbd-minor-0.lkbd) failed: No such file or directory
######启动服务
[root@nod1 ~]# service drbd start
Starting DRBD resources: [
create res: drbd
prepare disk: drbd
adjust disk: drbd
adjust net: drbd
]
..........
***************************************************************
DRBD's startup script waits for the peer node(s) to appear.
- In case this node was already a degraded cluster before the
reboot the timeout is 0 seconds. [degr-wfc-timeout]
- If the peer was available before the reboot the timeout will
expire after 0 seconds. [wfc-timeout]
(These values are for resource 'drbd'; 0 sec -> wait forever)
To abort waiting enter 'yes' [ 12]: yes
7、初始化设备同步
[root@nod1 ~]# drbdadm -- --overwrite-data-of-peer primary drbd
[root@nod1 ~]# cat /proc/drbd #查看同步进度
version: 8.4.3 (api:1/proto:86-101)
GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by gardner@, 2013-05-27 04:30:21
0: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r---n-
ns:1897624 nr:0 dw:0 dr:1901216 al:0 bm:115 lo:0 pe:3 ua:3 ap:0 ep:1 wo:f oos:207988
[=================>..] sync'ed: 90.3% (207988/2103412)K
finish: 0:00:07 speed: 26,792 (27,076) K/sec
######当同步完成时如以下状态
version: 8.4.3 (api:1/proto:86-101)
GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by gardner@, 2013-05-27 04:30:21
0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
ns:2103412 nr:0 dw:0 dr:2104084 al:0 bm:129 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
注释: drbd:为资源名称
######查看同步进度也可使用以下命令
drbd-overview
8、创建文件系统
######格式化文件系统
[root@nod1 ~]# mkfs.ext4 /dev/drbd0
9、禁止NOD1与NOD2节点上的DRBD服务开机自启动
[root@nod1 ~]# chkconfig drbd off
[root@nod1 ~]# chkconfig --list drbd
drbd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
=====================================================================
[root@nod2 ~]# chkconfig drbd off
[root@nod2 ~]# chkconfig --list drbd
drbd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
推荐阅读: