Corosync+Pacemaker+DRBD+MySQL 实现高可用(HA)的MySQL集群(2)

四、Pacemaker 安装与配置(参考博文: )
1.安装pacemaker
node1:
[root@node1 ~]# yum install -y pacemaker

node2:
[root@node2 ~]# yum install -y pacemaker

2.安装crmsh
node1:
[root@node1 ~]# wget  SUSE.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-6/x86_64/crmsh-1.2.6-0.rc2.2.1.x86_64.rpm
[root@node1 ~]# rpm -ivh crmsh-1.2.6-0.rc2.2.1.x86_64.rpm 
warning: crmsh-1.2.6-0.rc2.2.1.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 7b709911: NOKEY 
error: Failed dependencies: 
    pssh is needed by crmsh-1.2.6-0.rc2.2.1.x86_64 
    Python-dateutil is needed by crmsh-1.2.6-0.rc2.2.1.x86_64 
    python-lxml is needed by crmsh-1.2.6-0.rc2.2.1.x86_64
[root@node1 ~]# yum install -y python-dateutil python-lxml
[root@node1 ~]# rpm -ivh crmsh-1.2.6-0.rc2.2.1.x86_64.rpm --nodeps 
warning: crmsh-1.2.6-0.rc2.2.1.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 7b709911: NOKEY 
Preparing...                ########################################### [100%] 
  1:crmsh                  ########################################### [100%]
[root@node1 ~]# crm 
Cannot change active directory to /var/lib/pacemaker/cores/root: No such file or directory (2) 
crm(live)# help
This is crm shell, a Pacemaker command line interface.
Available commands:
    cib              manage shadow CIBs 
    resource        resources management 
    configure        CRM cluster configuration 
    node            nodes management 
    options          user preferences 
    history          CRM cluster history 
    site            Geo-cluster support 
    ra              resource agents information center 
    status          show cluster status 
    help,?          show help (help topics for list of topics) 
    end,cd,up        go back one level 
    quit,bye,exit    exit the program

node2:
[root@node2 ~]# wget  :/ha-clustering:/Stable/CentOS_CentOS-6/x86_64/crmsh-1.2.6-0.rc2.2.1.x86_64.rpm
[root@node2 ~]# rpm -ivh crmsh-1.2.6-0.rc2.2.1.x86_64.rpm 
warning: crmsh-1.2.6-0.rc2.2.1.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 7b709911: NOKEY 
error: Failed dependencies: 
    pssh is needed by crmsh-1.2.6-0.rc2.2.1.x86_64 
    python-dateutil is needed by crmsh-1.2.6-0.rc2.2.1.x86_64 
    python-lxml is needed by crmsh-1.2.6-0.rc2.2.1.x86_64
[root@node2 ~]# yum install -y python-dateutil python-lxml
[root@node2 ~]# rpm -ivh crmsh-1.2.6-0.rc2.2.1.x86_64.rpm --nodeps 
warning: crmsh-1.2.6-0.rc2.2.1.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 7b709911: NOKEY 
Preparing...                ########################################### [100%] 
  1:crmsh                  ########################################### [100%]
[root@node2 ~]# crm 
Cannot change active directory to /var/lib/pacemaker/cores/root: No such file or directory (2) 
crm(live)# help
This is crm shell, a Pacemaker command line interface.
Available commands:
    cib              manage shadow CIBs 
    resource        resources management 
    configure        CRM cluster configuration 
    node            nodes management 
    options          user preferences 
    history          CRM cluster history 
    site            Geo-cluster support 
    ra              resource agents information center 
    status          show cluster status 
    help,?          show help (help topics for list of topics) 
    end,cd,up        go back one level 
    quit,bye,exit    exit the program

3.启动corosync(注,在配置corosync时,将pacemaker整合进corosync中,corosync启动的同时也会启动pacemaker)
[root@node1 ~]# ssh node2 "service corosync start" 
Starting Corosync Cluster Engine (corosync): [确定] 
[root@node1 ~]# service corosync start 
Starting Corosync Cluster Engine (corosync):              [确定]

4.查看启动信息
(1).查看corosync引擎是否正常启动
[root@node1 ~]# grep -e "Corosync Cluster Engine" -e "configuration file" /var/log/cluster/corosync.log 
Aug 17 17:31:20 corosync [MAIN  ] Corosync Cluster Engine ('1.4.1'): started and ready to provide service. 
Aug 17 17:31:20 corosync [MAIN  ] Successfully read main configuration file '/etc/corosync/corosync.conf'.

(2).查看初始化成员节点通知是否正常发出
[root@node1 ~]# grep  TOTEM /var/log/cluster/corosync.log 
Aug 17 17:31:20 corosync [TOTEM ] Initializing transport (UDP/IP Multicast). 
Aug 17 17:31:20 corosync [TOTEM ] Initializing transmit/receive security: libtomcrypt SOBER128/SHA1HMAC (mode 0). 
Aug 17 17:31:21 corosync [TOTEM ] The network interface [192.168.1.201] is now up. 
Aug 17 17:31:21 corosync [TOTEM ] A processor joined or left the membership and a new membership was formed.

(3).检查启动过程中是否有错误产生
[root@node1 ~]# grep ERROR: /var/log/cluster/corosync.log 
Aug 17 17:31:21 corosync [pcmk  ] ERROR: process_ais_conf: You have configured a cluster using the Pacemaker plugin for Corosync. The plugin is not supported in this environment and will be removed very soon. 
Aug 17 17:31:21 corosync [pcmk  ] ERROR: process_ais_conf:  Please see Chapter 8 of 'Clusters from Scratch' () for details on using Pacemaker with CMAN

(4).查看pacemaker是否正常启动
[root@node1 ~]# grep pcmk_startup /var/log/cluster/corosync.log 
Aug 17 17:31:21 corosync [pcmk  ] info: pcmk_startup: CRM: Initialized 
Aug 17 17:31:21 corosync [pcmk  ] Logging: Initialized pcmk_startup 
Aug 17 17:31:21 corosync [pcmk  ] info: pcmk_startup: Maximum core file size is: 18446744073709551615 
Aug 17 17:31:21 corosync [pcmk  ] info: pcmk_startup: Service: 9 
Aug 17 17:31:21 corosync [pcmk  ] info: pcmk_startup: Local hostname: node1.test.com

5.查看集群状态
[root@node1 ~]# crm status 
Cannot change active directory to /var/lib/pacemaker/cores/root: No such file or directory (2) 
Last updated: Sat Aug 17 17:36:24 2013 
Last change: Sat Aug 17 17:31:33 2013 via crmd on node2.test.com 
Stack: classic openais (with plugin) 
Current DC: node2.test.com - partition with quorum 
Version: 1.1.8-7.el6-394e906 
2 Nodes configured, 2 expected votes 
0 Resources configured.
Online: [ node1.test.com node2.test.com ]

注:node1与node2都在线,DC是node2,符合法定票数
五、DRBD 安装与配置(参考博文: )
1.安装DRBD
node1:
[root@node1 ~]# yum -y install drbd84 kmod-drbd84

node2:
[root@node1 ~]# yum -y install drbd84 kmod-drbd84

2.配置DRBD
[root@node1 ~]# cat /etc/drbd.d/global_common.conf
global {
usage-count no; #让linbit公司收集目前drbd的使用情况,yes为参加,我们这里不参加设置为no
# minor-count dialog-refresh disable-ip-verification
}
common {
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-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 {
# 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
on-io-error detach; #同步错误的做法是分离
}
net {
# 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
cram-hmac-alg "sha1"; #设置加密算法sha1
shared-secret "mydrbdlab"; #设置加密key
}
}

3.增加资源
[root@node1 drbd.d]# cat web.res
resource web {
on node1.test.com {
device    /dev/drbd0;
disk      /dev/sdb;
address  192.168.1.201:7789;
meta-disk internal;
}
on node2.test.com {
device    /dev/drbd0;
disk      /dev/sdb;
address  192.168.1.202:7789;
meta-disk internal;
}
}

4.同步配置文件到node2’
[root@node1 drbd.d]# scp global_common.conf web.res node2:/etc/drbd.d/

5.node1与node2上初始化资源
node1:
[root@node1 ~]# drbdadm create-md web
Writing meta data...
initializing activity log
NOT initializing bitmap
New drbd meta data block successfully created.

node2:
[root@node2 ~]# drbdadm create-md web
Writing meta data...
initializing activity log
NOT initializing bitmap
New drbd meta data block successfully created.

6.启动DRBD
node1:
1 [root@node1 ~]# service drbd start

node2:
[root@node2 ~]# service drbd start

7.查看一下状态
node1:
[root@node1 ~]# drbd-overview
0:web/0Connected Secondary/SecondaryInconsistent/InconsistentC r-----

node2:
[root@node2 ~]# drbd-overview
0:web/0Connected Secondary/SecondaryInconsistent/InconsistentC r-----

8.设置node1为主节点
[root@node1 ~]# drbdadm -- --overwrite-data-of-peer primary web 
[root@node1 ~]# drbd-overview   
  0:web/0  Connected Primary/Secondary UpToDate/UpToDate C r-----

9.格式化并挂载
[root@node1 ~]# mke2fs -j /dev/drbd
[root@node1 ~]# mkdir /drbd
[root@node1 ~]# mount /dev/drbd0 /drbd/
[root@node1 ~]# mount
/dev/sda2on / typeext4 (rw)
proc on /proctypeproc (rw)
sysfs on /systypesysfs (rw)
devpts on /dev/ptstypedevpts (rw,gid=5,mode=620)
tmpfs on /dev/shmtypetmpfs (rw)
/dev/sda1on /boottypeext4 (rw)
/dev/sda3on /datatypeext4 (rw)
none on /proc/sys/fs/binfmt_misctypebinfmt_misc (rw)
/dev/drbd0on /drbdtypeext3 (rw)
[root@node1 ~]# cd /drbd/
[root@node1 drbd]# cp /etc/inittab /drbd/
[root@node1 drbd]# ll
总用量 20
-rw-r--r-- 1 root root  884 8月  17 13:50 inittab
drwx------ 2 root root 16384 8月  17 13:49 lost+found

10.设置node2为主节点
[root@node1 ~]# umount /drbd/
[root@node1 ~]# drbdadm secondary web
[root@node1 ~]# drbd-overview
[root@node2 ~]# drbdadm primary web
[root@node2 ~]# drbd-overview 
0:web/0Connected Primary/SecondaryUpToDate/UpToDateC r----- 
[root@node2 ~]# mkdir /drbd
[root@node2 ~]# mount /dev/drbd0 /drbd/
[root@node2 ~]# ll /drbd/
总用量 20
-rw-r--r-- 1 root root  884 8月  17 13:50 inittab
drwx------ 2 root root 16384 8月  17 13:49 lost+found

好了,到这里DRBD配置全部完成,下面我们来配置MySQL

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/219d67edab7721db98def2ad4b8a0976.html