LINUX HA基础

使用Heartbeat在Linux搭建高可用(High-Availability)的集群服务
本文的最后更新时间: 2005年10月19日 23:12
在互连网高速发展的今天,尤其是电子商务的发展,要求服务器要能够提供不间断服务。在电子商务中,如果服务器宕机,造成的损失是不可估量的。要保证服务器不间断服务,就需要对服务器实现冗余。在众多的实现服务器容易的解决方案中,heartbeat为我们提供了廉价的、可伸缩的高可用集群方案。下面我们将通过heartbeat在Linux下创建一个高可用的web服务器集群服务器。 本文中的系统环境为:RedHat Linux9.0

1. 目的和环境
* 硬件条件和环境

两台计算机(两个节点),一个共享SCSI硬盘盒(用于存储共享)。每个节点都安装支持共享总线的SCSI卡;每个节点有自己的系统磁盘;每个分别带有两块以太网卡,(其中一块用于网络通讯,另一块用于心跳功能。)。两个节点的网络设置如下:

节点1: 主机名为:node1.clusting.com,第一块网卡(eth0)的IP地址:192.168.100.7 (用于网络通讯) 。第二块网卡(eth1)的IP地址:10.0.0.1 (用于心跳通讯) 。

节点2: 主机名为:node2.clusting.com,第一块网卡(eth0)的IP地址:192.168.100.8 (用于网络通讯) 。第二块网卡(eth1)的IP地址:10.0.0.2 (用于心跳通讯) 。

其网络拓扑如下图所示:

* 目的

用上面的硬件搭建一台高可用的web服务器,服务器的IP地址为192.168.100.10,netmask 为255.255.255.240,broadcast为192.168.100.15。 web服务器的页面数据存储到共享盘的第一个分区(sdb1)上。

2. 准备环境
* 对共享磁盘进行分区

先关闭节点2(node2.clusting.com)主机的电源,打开节点1(node1.clusting.com)主机的电源,在节点一上安装系统,并对共享磁盘分区。

* 下载软件

首先下载heartbeat软件:到http://linux-ha.org/download 下载最新的heartbeat软件。本文写作时下载的软件是:heartbeat-2.0.2.tar.gz

* 下载和安装其它所需的软件

安装heartbeat除必要的编译器之外,需要下面两个软件的开发包支持:e2fsprogs和libnet。

e2fsprogs可以从系统的安装光盘使用rpm来安装: rpm -ivh /mnt/cdrom/RedHat/RPMS/e2fsprogs-devel-1.32-6.i386.rpm

libnet只能下载源代码进行安装。下载地址:http://www.packetfactory.net/libnet/。我下载的稳定版本是:1.1.2.1

接下来就是安装libnet:
tar -zxvf libnet.tar.gz
cd libnet
./configure
make
make install
3. 安装heartbeat

tar -zxvf heartbeat-2.0.2.tar.gz

cd heartbeat-2.0.2

./ConfigureMe configure

make

make install
4. 配置heartbeat

heartbeat的主配置文件为:/etc/ha.d/ha.cf。我们需要配置该文件,针对我们前面的规划,/etc/ha.d/ha.cf文件的主要内容如下:

logfile /var/log/ha-log #指名heartbeat的日志存放位置。

crm yes #支持ClusterResourceManager(集群资源管理)功能。

bcast eth1 #指明心跳方式使用以太广播方式,并且是在eth1接口上进行广播。

keepalive 2 #指明心跳时间为2秒(即每两秒钟在eth1上发送一次广播)。

warntime 10 #指明心跳延迟的时间为十秒。当10秒钟内备份机不能联系上主机(当前活动的服务器,即无心跳信号),就会往日志中写入一个警告日志,但此时不会切换服务。

deadtime 30 #指定在30秒内没有心跳信号,则立即切换服务。

initdead 120 #With some configurations, the network takes some time to start working after a reboot. This is a separate "deadtime" to handle that case. It should be at least twice the normal deadtime.

udpport 694 #Use port number 694 for bcast or ucast communication. This is the default, and the official IANA registered port number.

auto_failback on #

node node1.clusting.com #Mandatory. Hostname of machine in cluster as described by uname -n.

node node2.clusting.com #

respawn hacluster /usr/lib/heartbeat/ccm

respawn hacluster /usr/lib/heartbeat/ipfail

ping ping1.clusting.com ping2.clusting.com #Specify ping nodes. These nodes are not considered as cluster nodes. They are used to check network connectivity for modules like ipfail.
5. 配置HA资源

当切换资源时应该切换哪些资源,例如IP、磁盘……等。在heartbeat中,通过/etc/ha.d/haresources文件来配置共享的资源,在我们的案例中,/etc/ha.d/haresources文件的主要内容如下:

node1.clusting.com 192.168.100.10/28/192.168.100.15 Filesystem::/dev/sdb1::/ha::ext3 httpd
#设置node1.clusting.com为主节点,集群服务器的ip地址为192.168.100.10,netmask 为255.255.255.240,broadcast为192.168.100.15,集群的服务有httpd,还有共享磁盘/dev/sdb1。

该文件只有一行,其含义就是,当主节点node1.clusting.com宕机时,自动启用备用节点node2.clusting.com来提供服务,在却换到node2.clusting.com上时,自动启动httpd和smb服务,同时,将/dev/sdb1挂接到/ha。
6. 配置Authkeys
/etc/ha.d/authkeys文件的内容如下:
auth 1
1 sha1 key-for-sha1-any-text-you-want

更改文件的权限:
chmod 600 /etc/ha.d/authkeys


7. 使用同样的方法配置节点2

在节点2(node2.clusting.com)上执行步骤3-6(当然同样必须先安装heartbeat所需要的软件),节点2 上的heartbeat和apache的配置与节点1要完全相同。


8. 测试

* 在主节点(node1.clusting.com)上启动heartbeat服务:/etc/init.d/heartbeat start。 如果不出现错误,web服务应该被heartbeat启动,同时heartbeat为主节点设置IP地址192.168.100.10。使用ifconfig eth0:0可以看到如下信息:

eth0:0 Link encap:Ethernet HWaddr 00:0C:29:D8:FD:EB
inet addr:192.168.100.10 Bcast:192.168.100.15 Mask:255.255.255.240
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:14970 errors:0 dropped:0 overruns:0 frame:0
TX packets:14977 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:3624073 (3.4 Mb) TX bytes:3626223 (3.4 Mb)
Interrupt:19 Base address:0x10a0

同时/dev/sdb1,应该被挂接。使用df -h,可以看到的信息包含下面的行:

/dev/sdb1 485M 8.1M 452M 2% /ha

* 在node2(node2.clusting.com)上启动heartbeat:/etc/init.d/heartbeat start。 使用ifconfig eth0:0可以看到如下信息:

eth0:0 Link encap:Ethernet HWaddr 00:0C:29:E4:1E:F7
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:19 Base address:0x10a0

表明现在node2节点没有被启用。

使用df -h,看到的信息不包含下面的行:

/dev/sdb1 485M 8.1M 452M 2% /ha

表明/dev/sdb1没有被加载。

* [color=red]直接关闭节点1的电源(模拟故障)。 30秒后,在节点2(node2.clusting.com) 上执行ifconfig eth0:0,可以看到eth0:0已经被设置为192.168.100.10 [/color]

Copyright© 2005 Clusting.com All Rights Reserved

联系:
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Title: CentOS High Availability Author: Mitja Resman Length: 156 pages Edition: 1 Language: English Publisher: Packt Publishing Publication Date: 2015-04-30 ISBN-10: 1785282484 ISBN-13: 9781785282485 Leverage the power of high availability clusters on CentOS Linux, the enterprise-class, open source operating system About This Book Install, configure, and manage a multi-node cluster running on CentOS Linux Manage your cluster resources and learn how to start, stop, and migrate resources from one host to another Designed as a step-by-step guide, this book will help you become a master of cluster nodes, cluster resources, and cluster services on CentOS 6 and CentOS 7 Who This Book Is For This book is targeted at system engineers and system administrators who want to upgrade their knowledge and skills in high availability and want to learn practically how to achieve high availability with CentOS Linux. You are expected to have good CentOS Linux knowledge and basic networking experience. In Detail The high performance and stability of CentOS Linux are the key factors that make CentOS Linux the right Linux distribution to build high availability solutions on. This book introduces you to high availability before briefly walking you through the cluster stack and its layers. The book is then divided into two parts, part A and part B, based on CentOS versions 6 and 7 respectively. Each part begins with the installation and configuration of the Corosync cluster messaging software with CMAN or with the Pacemaker cluster resource management software. You will also be introduced to cluster service configuration and cluster service management before you configure fencing or STONITH on CentOS 6 and CentOS 7. By the end of this book, you will have the skills required to independently design, implement, and maintain a CentOS high availability multinode cluster environment. Table of Contents Chapter 1: Getting Started with High Availability Chapter 2: Meet the Cluster Stack on CentOS Chapter 3: Cluster Stack Software on CentOS 6 Chapter 4: Resource Manager on CentOS 6 Chapter 5: Playing with Cluster Nodes on CentOS 6 Chapter 6: Fencing on CentOS 6 Chapter 7: Testing Failover on CentOS 6 Chapter 8: Two-node Cluster Considerations in CentOS 6 Chapter 9: Cluster Stack Software on CentOS 7 Chapter 10: Resource Manager on CentOS 7 Chapter 11: Playing with Cluster Nodes on CentOS 7 Chapter 12: STONITH on CentOS 7 Chapter 13: Testing Failover on CentOS 7 Chapter 14: Two-node Cluster Considerations on CentOS 7

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值