三、安装MySQL
1、安装Mysql并配置
######在NOD1节点上安装Mysql
[root@nod1 ~]# mkdir /mydata
[root@nod1 ~]# mount /dev/drbd0 /mydata/
[root@nod1 ~]# mkdir /mydata/data
[root@nod1 ~]# tar xf mysql-5.5.33-linux2.6-x86_64.tar.gz -C /usr/local/
[root@nod1 ~]# cd /usr/local/
[root@nod1 local]# ln -s mysql-5.5.33-linux2.6-x86_64 mysql
[root@nod1 local]# cd mysql
[root@nod1 mysql]# cp support-files/my-large.cnf /etc/my.cnf
[root@nod1 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@nod1 mysql]# chmod +x /etc/init.d/mysqld
[root@nod1 mysql]# chkconfig --add mysqld
[root@nod1 mysql]# chkconfig mysqld off
[root@nod1 mysql]# vim /etc/my.cnf
datadir = /mydata/data
innodb_file_per_table = 1
[root@nod1 mysql]# echo "PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile
[root@nod1 mysql]# . /etc/profile
[root@nod1 mysql]# useradd -r -u 306 mysql
[root@nod1 mysql]# chown mysql.mysql -R /mydata
[root@nod1 mysql]# chown root.mysql *
[root@nod1 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/mydata/data/
[root@nod1 mysql]# service mysqld start
Starting MySQL..... [ OK ]
[root@nod1 mysql]# chkconfig --list mysqld
mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@nod1 mysql]# service mysqld stop
Shutting down MySQL. [ OK ]
######在NOD2节点上安装Mysql
[root@nod2 ~]# scp nod1:/root/mysql-5.5.33-linux2.6-x86_64.tar.gz ./
[root@nod2 ~]# mkdir /mydata
[root@nod2 ~]# tar xf mysql-5.5.33-linux2.6-x86_64.tar.gz -C /usr/local/
[root@nod2 ~]# cd /usr/local/
[root@nod2 local]# ln -s mysql-5.5.33-linux2.6-x86_64 mysql
[root@nod2 local]# cd mysql
[root@nod2 mysql]# cp support-files/my-large.cnf /etc/my.cnf
######修改配置文件添加如下配置
[root@nod2 mysql]# vim /etc/my.cnf
datadir = /mydata/data
innodb_file_per_table = 1
[root@nod2 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@nod2 mysql]# chkconfig --add mysqld
[root@nod2 mysql]# chkconfig mysqld off
[root@nod2 mysql]# useradd -r -u 306 mysql
[root@nod2 mysql]# chown -R root.mysql *
2、卸载NOD1节点上的DRBD设备然后降级
[root@nod1 ~]# drbd-overview
0:drbd/0 Connected Primary/Secondary UpToDate/UpToDate C r-----
[root@nod1 ~]# umount /mydata/
[root@nod1 ~]# drbdadm secondary drbd
[root@nod1 ~]# drbd-overview
0:drbd/0 Connected Secondary/Secondary UpToDate/UpToDate C r-----
3、在NOD2节点升级DBRD为主然后挂载DRBD设备
[root@nod2 ~]# drbd-overview
0:drbd/0 Connected Secondary/Secondary UpToDate/UpToDate C r-----
[root@nod2 ~]# drbdadm primary drbd
[root@nod2 ~]# drbd-overview
0:drbd/0 Connected Primary/Secondary UpToDate/UpToDate C r-----
[root@nod2 ~]# mount /dev/drbd0 /mydata/
4、在NOD2节点上启动Mysql服务进行测试
[root@nod2 ~]# chown -R mysql.mysql /mydata
[root@nod2 ~]# service mysqld start
Starting MySQL.. [ OK ]
[root@nod2 ~]# service mysqld stop
Shutting down MySQL. [ OK ]
[root@nod2 ~]# chkconfig --list mysqld
mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off
5、将DRBD服务都设置为备用节点如:
[root@nod2 ~]# drbdadm secondary drbd
[root@nod2 ~]# drbd-overview
0:drbd/0 Connected Secondary/Secondary UpToDate/UpToDate C r-----
6、卸载DRBD设备并停止NOD1与NOD2节点上的DRBD服务
[root@nod2 ~]# umount /mydata/
[root@nod2 ~]# service drbd stop
Stopping all DRBD resources: .
[root@nod1 ~]# service drbd stop
Stopping all DRBD resources: .
--------------------------------------------------------------------------------
四、安装Corosync+Pacemaker软件
1、在NOD1与NOD2节点上安装
[root@nod1 ~]# yum -y install crmsh*.rpm pssh*.rpm pacemaker corosync
[root@nod2 ~]# scp nod1:/root/{pssh*.rpm,crmsh*.rpm} ./
[root@nod2 ~]# yum -y install crmsh*.rpm pssh*.rpm pacemaker corosync
2、在NOD1上配置Corosync
[root@nod1 ~]# cd /etc/corosync/
[root@nod1 corosync]# ls
corosync.conf.example corosync.conf.example.udpu service.d uidgid.d
[root@nod1 corosync]# cp corosync.conf.example corosync.conf
[root@nod1 corosync]# vim corosync.conf
# Please read the corosync.conf.5 manual page
compatibility: whitetank
totem {
version: 2 #版本号
secauth: on #是否开启安全认证
threads: 0 #多少个现成认证,0 为无限制
interface {
ringnumber: 0
bindnetaddr: 172.16.0.0 #通过哪个网络通信
mcastaddr: 226.94.14.12 #组播地址
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 { #添加支持使用Pacemaker
ver: 0
name: pacemaker
}
aisexec { #是否使用openais,有时可能会用到
user: root
group: root
}
3、生成节点之间通信时用到的认证密钥文件
[root@nod1 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.
Press keys on your keyboard to generate entropy (bits = 152).
Press keys on your keyboard to generate entropy (bits = 216).
注释:生成密钥时如果出现以上问题,说明随机数不够用,可以安装软件来解决
4、将配置文件及认证文件拷贝到NOD2节点一份
[root@nod1 corosync]# scp authkey corosync.conf nod2:/etc/corosync/
authkey 100% 128 0.1KB/s 00:00
corosync.conf 100% 522 0.5KB/s 00:00
5、启动Corosync服务
[root@nod1 ~]# service corosync start
Starting Corosync Cluster Engine (corosync): [ OK ]
######查看corosync引擎是否正常启动
[root@nod1 ~]# grep -e "Corosync Cluster Engine" -e "configuration file" /var/log/cluster/corosync.log
Sep 19 18:44:36 corosync [MAIN ] Corosync Cluster Engine ('1.4.1'): started and ready to provide service.
Sep 19 18:44:36 corosync [MAIN ] Successfully read main configuration file '/etc/corosync/corosync.conf'.
######查看启动过程是否产生错误信息;如下信息可以忽略
[root@nod1 ~]# grep ERROR: /var/log/cluster/corosync.log
Sep 19 18:44:36 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.
Sep 19 18:44:36 corosync [pcmk ] ERROR: process_ais_conf: Please see Chapter 8 of 'Clusters from Scratch' () for details on using Pacemaker with CMAN
######查看初始化成员节点通知是否正常发出
[root@nod1 ~]# grep TOTEM /var/log/cluster/corosync.log
Sep 19 18:44:36 corosync [TOTEM ] Initializing transport (UDP/IP Multicast).
Sep 19 18:44:36 corosync [TOTEM ] Initializing transmit/receive security: libtomcrypt SOBER128/SHA1HMAC (mode 0).
Sep 19 18:44:36 corosync [TOTEM ] The network interface [172.16.14.1] is now up.
Sep 19 18:44:36 corosync [TOTEM ] A processor joined or left the membership and a new membership was formed.
######查看pacemaker是否正常启动
[root@nod1 ~]# grep pcmk_startup /var/log/cluster/corosync.log
Sep 19 18:44:36 corosync [pcmk ] info: pcmk_startup: CRM: Initialized
Sep 19 18:44:36 corosync [pcmk ] Logging: Initialized pcmk_startup
Sep 19 18:44:36 corosync [pcmk ] info: pcmk_startup: Maximum core file size is: 18446744073709551615
Sep 19 18:44:36 corosync [pcmk ] info: pcmk_startup: Service: 9
Sep 19 18:44:36 corosync [pcmk ] info: pcmk_startup: Local hostname: nod1.allen.com
6、启动NOD2节点上Corosync服务
[root@nod1 ~]# ssh nod2 'service corosync start'
Starting Corosync Cluster Engine (corosync): [ OK ]
######查看集群节点启动状态
[root@nod1 ~]# crm status
Last updated: Thu Sep 19 19:01:33 2013
Last change: Thu Sep 19 18:49:09 2013 via crmd on nod1.allen.com
Stack: classic openais (with plugin)
Current DC: nod1.allen.com - partition with quorum
Version: 1.1.8-7.el6-394e906
2 Nodes configured, 2 expected votes
0 Resources configured.
Online: [ nod1.allen.com nod2.allen.com ] #两个节点都已正常启动
7、查看Corosync启动的相关进程
[root@nod1 ~]# ps auxf
root 10336 0.3 1.2 556824 4940 ? Ssl 18:44 0:04 corosync
305 10342 0.0 1.7 87440 7076 ? S 18:44 0:01 \_ /usr/libexec/pacemaker/cib
root 10343 0.0 0.8 81460 3220 ? S 18:44 0:00 \_ /usr/libexec/pacemaker/stonit
root 10344 0.0 0.7 73088 2940 ? S 18:44 0:00 \_ /usr/libexec/pacemaker/lrmd
305 10345 0.0 0.7 85736 3060 ? S 18:44 0:00 \_ /usr/libexec/pacemaker/attrd
305 10346 0.0 4.7 116932 18812 ? S 18:44 0:00 \_ /usr/libexec/pacemaker/pengin
305 10347 0.0 1.0 143736 4316 ? S 18:44 0:00 \_ /usr/libexec/pacemaker/crmd