Corosync+Pacemaker+DRBD+MySQL 实现高可用(HA)的MySQL集群
大纲
一、前言
二、环境准备
三、Corosync 安装与配置
四、Pacemaker 安装与配置
五、DRBD 安装与配置
六、MySQL 安装与配置
七、crmsh 资源管理
推荐阅读:
2.软件环境
- corosync-1.4.1-15.el6_4.1.x86_64
- pacemaker-1.1.8-7.el6.x86_64
- crmsh-1.2.6-0.rc2.2.1.x86_64
- kmod-drbd84-8.4.2-1.el6_3.elrepo.x86_64
- drbd84-utils-8.4.2-1.el6.elrepo.x86_64
- mysql-5.5.33
3.拓扑环境
4.配置各节点互相解析
node1:
[root@node1 ~]# uname -n
node1.test.com
[root@node1 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.201 node1.test.com node1
192.168.1.202 node2.test.com node2
node2:
[root@node2 ~]# uname -n
node2.test.com
[root@node2 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.201 node1.test.com node1
192.168.1.202 node2.test.com node2
5.配置各节点ssh互信
node1:
[root@node1 ~]# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ''
[root@node1 ~]# ssh-copy-id -i .ssh/id_rsa.pub [email protected]
node2:
[root@node2 ~]# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ''
[root@node2 ~]# ssh-copy-id -i .ssh/id_rsa.pub [email protected]
6.配置各节点时间同步
node1:
[root@node1 ~]# ntpdate 202.120.2.101
node2:
[root@node2 ~]# ntpdate 202.120.2.101
7.各节点关闭防火墙与SELinux
node1:
[root@node1 ~]# service iptables stop
[root@node1 ~]# chkconfig iptables off
[root@node1 ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
node2:
[root@node2 ~]# service iptables stop
[root@node2 ~]# chkconfig iptables off
[root@node2 ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
8.各节点安装yum源
node1:
[root@node1 src]# wget http://download.Fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@node1 src]# rpm -ivh epel-release-6-8.noarch.rpm
warning: epel-release-6-8.noarch.rpm: Header V3 RSA/SHA256Signature, key ID 0608b895: NOKEY
Preparing... ########################################### [100%]
1:epel-release ########################################### [100%]
[root@node1 src]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
[root@node1 ~]# rpm -ivh http://elrepo.org/elrepo-release-6-5.el6.elrepo.noarch.rpm
[root@node1 ~]# yum list
node2:
[root@node2 src]# wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@node2 src]# rpm -ivh epel-release-6-8.noarch.rpm
warning: epel-release-6-8.noarch.rpm: Header V3 RSA/SHA256Signature, key ID 0608b895: NOKEY
Preparing... ########################################### [100%]
1:epel-release ########################################### [100%]
[root@node2 src]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
[root@node2 ~]# rpm -ivh http://elrepo.org/elrepo-release-6-5.el6.elrepo.noarch.rpm
[root@node2 ~]# yum list
node2:
[root@node2 ~]# yum install -y corosync
2.配置Corosync(注,所有的配置说明我就不详细说明了,因为前面的博文全部讲解过)
[root@node1 ~]# cd /etc/corosync/
[root@node1 corosync]# ll
总用量 16
-rw-r--r-- 1 root root 445 5月 15 05:09 corosync.conf.example
-rw-r--r-- 1 root root 1084 5月 15 05:09 corosync.conf.example.udpu
drwxr-xr-x 2 root root 4096 5月 15 05:09 service.d
drwxr-xr-x 2 root root 4096 5月 15 05:09 uidgid.d
[root@node1 corosync]# cp corosync.conf.example corosync.conf
[root@node1 corosync]# vim corosync.conf
[root@node1 corosync]# cat corosync.conf
# Please read the corosync.conf.5 manual page
compatibility: whitetank
totem {
version: 2
secauth: on
threads: 0
interface {
ringnumber: 0
bindnetaddr: 192.168.1.0
mcastaddr: 226.94.10.10
mcastport: 5405
ttl: 1
}
}
logging {
fileline: off
to_stderr: no
to_logfile: yes
to_syslog: no
logfile: /var/log/cluster/corosync.log
debug: off
timestamp: on
logger_subsys {
subsys: AMF
debug: off
}
}
amf {
mode: disabled
}
service {
ver: 0
name: pacemaker
}
aisexec {
user: root
group: root
}
3.生成密钥文件
[root@node1 corosync]# mv /dev/{random,random.bak}
[root@node1 corosync]# ln -s /dev/urandom /dev/random
[root@node1 corosync]# corosync-keygen
Corosync Cluster Engine Authentication key generator.
Gathering 1024 bits for key from /dev/random.
Press keys on your keyboard to generate entropy.
Writing corosync key to /etc/corosync/authkey.
[root@node1 corosync]# ll
总用量 24
-r-------- 1 root root 128 8月 17 17:17 authkey
-rw-r--r-- 1 root root 544 8月 17 17:14 corosync.conf
-rw-r--r-- 1 root root 445 5月 15 05:09 corosync.conf.example
-rw-r--r-- 1 root root 1084 5月 15 05:09 corosync.conf.example.udpu
drwxr-xr-x 2 root root 4096 5月 15 05:09 service.d
drwxr-xr-x 2 root root 4096 5月 15 05:09 uidgid.d
4.将node1上配置文件复制到node2上
[root@node1 corosync]# scp authkey corosync.conf node2:/etc/corosync/
authkey 100% 128 0.1KB/s 00:00
corosync.conf 100% 542 0.5KB/s 00:00
好了,到这里corosync配置完成,下面我们配置pacemaker