大纲
一、前言
二、环境准备
三、Corosync 安装与配置
四、Pacemaker 安装与配置
五、DRBD 安装与配置
六、MySQL 安装与配置
七、crmsh 资源管理
推荐阅读:
Linux 高可用(HA)集群基本概念详解
Linux 高可用(HA)集群之Heartbeat详解
一、前言
前几篇博文中我们讲解了,heartbeat、corosync、pacemaker,也讲解了高可用的Web集群、高可用的Mysql集群,这一篇博文进行小小的总结,heartbeat与corosync是流行的Messaging Layer (集群信息层),非要在这两个当中选一个我选择corosync,至于理由是仁者见仁,智者见智啦,用过的人都知道。Pacemaker是最流行的CRM(集群资源管理器),是从heartbeat v3中独立出来的资源管理器,同时Corosync+Pacemaker是最流行的高可用集群的套件,前面我们讲解的高可用的Mysql集群是heartbaet+mysql+nfs组合,其有点令人不满意的是得要三台服务器,其中一台为共享存储,可是这对于中小型公司来说,花个好几万来买台服务器,会不会有点浪费了,在这篇博文中我们将讲解,只用两台服务器来实现,高可用的Mysql数据库。在上一篇博文中我们已经详细讲解过了DRBD,这里就不在重复说明,想看的博友可以参考一下这篇博文 (Linux 高可用(HA)集群之DRBD详解),下面我们就来具体演示一下配置过程。
二、环境准备
1.操作系统
CentOS 6.4 X86_64位系统
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 root@node2.test.com
node2:
[root@node2 ~]# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ''
[root@node2 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@node1.test.com
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 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
[root@node1 ~]# yum list
node2:
[root@node2 src]# wget
[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
[root@node2 ~]# yum list
三、Corosync 安装与配置(参考博文: )
1.安装Corosync
node1:
[root@node1 ~]# yum install -y corosync
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