环境:RHEL6.4 ,heartbeat软体版本2.1.4,默认情况下,RHEL6只提供heartbeat-V3,heartbeatV2在RHEL5的epel源中
配置HA集群的前提:
至少2个节点;
共享存储(可选);
Stonith设备;
时间同步;
各个节点以主机名通信;
至少配置好一个节点,提供基本的集群配置文件,可以没有资源;
ssh互信;
定义心跳信息传递方式,
ServerA:172.16.1.1
ServerB:172.16.1.2
NFServr:172.16.1.3
1、配置主机名解析:
# vi /etc/hosts
node1.magedu.com 172.16.100.1
node2.magedu.com 172.16.100.2
2、同步时间
# ntpdate 172.16.0.1
3、配置ssh互信
# ssh-keygen -t rsa
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@node2
4、安装软件
# yum -yinstall PyXML net-snmp-libs libnet
# rpm -ivhheartbeat-pils-2.1.4-12.el6.x86_64.rpm
# rpm -ivhheartbeat-stonith-2.1.4-12.el6.x86_64.rpm
# rpm -ivh heartbeat-2.1.4-12.el6.x86_64.rpm
# rpm -ivh heartbeat-gui-2.1.4-12.el6.x86_64.rpm
5、配置文件有:authkeys / ha.cf (默认不存在,需要复制样例文件)在/usr/share/doc/heartbeat-2.1.4/下
# cd /usr/share/doc/heartbeat-2.1.4/
# cp authkeys ha.cf /etc/ha.d
7、编辑authkeys文件:
# cd /etc/ha.d
# openssl rand -hex 8 >> authkeys
# vi authkeys
auth 2
2 sha1 RandomNumber
# chmod 600 authkeys
8、编辑ha.cf:
# vi ha.cf
设置组播地址传递心跳信息
mcasteth0 225.0.0.250 694 1 0
auto_failback on;自动恢复;
添加集群节点,如果只有2个节点,需要配置ping node功能;
node node1.magedu.com
node node2.magedu.com
ping 172.16.0.1
启用crm(资源管理器)
crm respawn
scp 配置文件到node2
# scpha.cf authkeys node2:/etc/ha.d
给hacluster用户设置密码,用以登录hb_gui
passwd hacluster
设置MySQL,下载并解压mysql二进制安装包,
#!/bin/bash
#Mount Windows dir incase copy the software.
mount -t cifs -ousername=thinkpad1,password=aaa //172.16.254.52/source /mnt
# Uncompress mysql totarget dir
tar xf/mnt/mysql/mysql-5.5.33-linux2.6-x86_64.tar.gz -C /usr/local
umount /mnt
# Create a user for mysql
useradd -u 306 -r mysql
# Create MySQL Datadirectory
#mkdir /mydata/data -pv
mkdir /mydata
#chown -R mysql.mysql/mydata/data
chown -R mysql.mysql/mydata
cd /usr/local
ln -svmysql-5.5.33-linux2.6-x86_64 mysql
cd mysql
chown -R root.mysql ./*
#Copy example file toconfiguration file and Modify some parameters.
\cp -fsupport-files/my-large.cnf /etc/my.cnf
sed -i '/^\[mysqld\]$/adatadir = /mydata/data\ninnodb_file_per_table = 1' /etc/my.cnf
#Copy example file incase to Control MySQL.
cpsupport-files/mysql.server /etc/init.d/mysqld
#Add Mysql to Servicelist
chkconfig --add mysqld
chkconfigmysqld off
#Init mysql database
#scripts/mysql_install_db --user=mysql --datadir=/mydata/data
#Start mysql
#service mysqld start
# export PATH
cat >/etc/profile.d/mysql.sh << EOF
exportPATH=/usr/local/mysql/bin:$PATH
EOF
source/etc/profile.d/mysql.sh
# export lib files
cat >/etc/ld.so.conf.d/mysql.conf << EOF
/usr/local/mysql/lib
EOF
ldconfig
# export .h files
ln -sv/usr/local/mysql/include /usr/include/mysql
NFS节点配置:
在node1和node2上安装mysql,注意:在初始化数据库时,先挂载NFS,注意NFS的mysqldata目录的权限属主和属组是mysql,但是初始化数据库是以root用户来初始的,要让root具有读写权限;
# mkdir/mysqldata/data -pv
# vi /etc/exports
/mysqldata 172.16.0.0/16(rw,no_root_squash)
#exportfs -arv
# useradd-r -u 306 mysql
# chown-R mysql.mysql /mysqldata
# setfacl-m u:root:rx- /mysqldata/data
在集群节点上事先挂载NFS,对数据库进行初始化:初始化一次即可
# mount-t nfs 172.16.1.3:/mysqldata /mydata
# cd/usr/local/mysql
# scripts/mysql_install_db --user=mysql --datadir=/mydata/data
# service mysqld start 测试
然后
# servicemysqld stop
配置高可用资源等
#serviceheartbeat start
hb_gui&
定义资源:
将所有资源添加一个组,或添加几个独立的资源,然后定义资源的约束条件;下面以添加组为例:
定义组内资源,设置集群的VIP:
添加myservice,添加一个主资源
设置资源名称myservice,资源代理使用lsb的mysqld,也就是/etc/init.d/下的mysqld脚本
添加存储资源:
添加一个顺序约束:(资源启动顺序)
配置完成,测试:
[root@node1 mysql]# mysql -uroot -h172.16.1.100 -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.33-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
总结:此拓扑中节点故障的转移没有障碍,但是存在NFS的单点故障,如果NFS服务停止,那么整个集群将无法工作。