系统:centos6.4最小化

heartbeat-3.0.4-2.el6.x86_64.rpm,heartbeat-libs-3.0.4-2.el6.x86_64.rpm

搭建高可用集群之前,首要前提条件:

1、节点之间必须能够ssh互信通信

2、节点间需传递集群事务信息,网段选择

3、节点名称与hostname(uname -n)一致,不要使用dns解析

4、各节点之间保持时间上的同步

######################################################################

节点选择:

node1:192.168.31.115

node2:192.168.31.116

VIP:192.168.31.117

######################################################################

node1:192.168.31.115

1、ssh互信通信

ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ''

ssh-copy-id .ssh/id_rsa.pub root@192.168.31.116


node2:192.168.31.116同步此操作


2、节点名称与hostname

vim /ets/hosts

192.168.31.115 node1

192.168.31.116 node2


hostname node1

vim /etc/sysconfig/network

HOSTNAME=node1


node2:192.168.31.116同步以上操作


3、时间同步

# rdate -s time-b.nist.gov

启动例行计划任务

crontab -e

*/5 * * * * /usr/bin/rdate -s time-b.nist.gov

node2:192.168.31.116同步以上操作

#######################################################

准备工作已就绪,开始下载需要的工具

heartbeat-3.0.4-2.el6.x86_64.rpm,heartbeat-libs-3.0.4-2.el6.x86_64.rpm

下载网址:https://dl.fedoraproject.org/pub/epel/6/x86_64/repoview/

安装:

yum -y --nogpgcheck localinstall heartbeat-3.0.4-2.el6.x86_64.rpm,heartbeat-libs-3.0.4-2.el6.x86_64.rpm

cd /etc/ha.d/

复制heartbeat需要的三个配置文件:

cp -a /usr/share/doc/heartbeat-3.0.4/{authkeys,ha.cf,haresources} /etc/ha.d/

cd /etc/ha.d/

1、配置authkeys

auth 1

1 md5 hhhkkloooo:后接一段随机密码

生成随机数:

dd if=/dev/random bs=512 count=1|md5sum

[root@node1 heartbeat-3.0.4]# dd if=/dev/random bs=512 count=1|md5sum

记录了0+1 的读入

记录了0+1 的写出

19字节(19 B)已复制,0.000102463 秒,185 kB/秒

1b3b81cba0cb16a43195af2508a48ff8

注意:修改密钥文件为600的权限最好


2、配置主配置文件ha.cf

debugfile:调试文件

logfile:日志文件

logfacility:日志的设施,两者取其一

keepalive n:几秒发一次心跳信息

deadtime n:死亡时间

warntime n:警告时长

initdead n:第一个节点启动之后,等多久到第二个节点启动

udpport:udp监听的端口

baud n:串行

bcast:广播

mcast:多播,组播(生产环境建议使用多播)

ucast:单播(两个节点才能单播,最好不要使用这个),后接各自对方地址

auto_failback on:节点上来了,节点要不要转移回去

node:几个节点,当前集群

node hostname1

node hostnam2

ping:ping网关ip

hbaping fc-card-name

respawn hacluster /usr/lib/heartbeat/ipfail

msgfmt:信息管理格式

compression:是否启用压缩,启用什么压缩方式

一般配置节点名称与节点间集群事务信息传递就行,所以最简单的配置:(最好定义一个日志文件方便观察)

bcast:广播(启用广播)

node:几个节点,当前集群(定义当前集群间的节点)

node hostname1

node hostnam2

bcast   eth0

#node   ken3

node    node1

#node   kathy

node    node2

注意:启用logfile日志文件方便观察出错


3、配置资源

vi haresources

添加如下一行:

node1 IPaddr::192.168.31.117/24/eth0 httpd:定义主节点以及VIP以及服务

将配置完的三个文件一并复制到node2:192.168.31.116

scp ha.cf authkeys haresources node2:/etc/ha.d/

注意:检查下authkeys的权限


各节点安装httpd服务:

node1:

yum -y install httpd

echo "node1.my.com" >> /var/www/html/index.html

service iptables stop

setenforce 0

sed -i 's#SELINUX=enforcing#SELINUX=permissive#g' /etc/selinux/config


node2:

yum -y install httpd

echo "node2.my.com" >> /var/www/html/index.html

service iptables stop

setenforce 0

sed -i 's#SELINUX=enforcing#SELINUX=permissive#g' /etc/selinux/config


启动heartbeat服务

node1:

service heartbeat start

启动node2,在node1上远程启动node2

ssh node2 'service heartbeat start'


浏览器输入:http://192.168.31.117即可观察到node1.my.com

在/usr/share/heartbeat下有个hb_standby脚本可以转换主备节点

执行该脚本,刷新浏览器,即可观察到node2.myc.om


另:

将httpd服务运用上nfs服务:

nfs server:192.168.31.113

安装nfs-utils rpcbind:

yum -y install nfs-utils rpcbind

mkdir /www/html -pv

echo "nfs.server.com" >> /www/html/index.html

vim /etc/exports

/www/html    192.168.31.0/24(rw,all_squash)

service rpcbind start

service nfs start


于是改变node1的配置文件haresources

vim haresources

将node1 IPaddr::192.168.31.117/24/eth0 httpd

改为:

node1 IPaddr::192.168.31.117/24/eth0 Filesystem::192.168.31.113:/www/html::/var/www/html::nfs httpd

然后复制到node2中

停掉heartbeat服务再启动

自行观察浏览器的效果