URN Logo
UNIX Resources » Linux » China Linux Forum » Linux 集群技术 » 12 » 基于Linux的两节点高可用服务器
announcement 声明: 本页内容为中国Linux论坛的内容镜像,文章的版权以及其他所有的相关权利属于中国Linux论坛和相应文章的作者,如果转载,请注明文章来源及相关版权信息。
Resources
China Linux Forum(finished)
Linux Forum(finished)
FreeBSD China(finished)
linuxforum.net
  业界新闻与评论
  自由软件杂谈
  IT 人生
  Linux软件快递
  翻译作坊
  Linux图书与评论
  GNU Emacs/XEmacs
  Linux 中文环境和中文化
  Linux桌面与办公软件
  Linux 多媒体与娱乐版
  自由之窗Mozilla
  笔记本电脑上的Linux
  Gentoo
  Debian 一族
  网络管理技术
  Linux 安装与入门
  WEB服务器和FTP服务器
  域名服务器和邮件服务器
  Linux防火墙和代理服务器应用
  文件及打印服务器
  技术培训与认证
  TI专版
  Linux内核技术
  Linux 嵌入技术
  Linux设备驱动程序
  Linux 集群技术
  LINUX平台数据库
  系统和网络安全
  CPU 与 编译器
  系统计算研究所专栏
  Linux下的GUI软件开发
  C/C++编程版
  PHP 技 术
  Java&jsp技术
  Shell编程技术
  Perl 编 程
  Python 编 程
  XML/Web Service 技术
  永远的Unix
  FreeBSD世界
   
基于Linux的两节点高可用服务器
基于Linux的两节点高可用服务器 - acon [2002-07-07 10:46 | 10,555 byte(s)]
 
acon大哥,有问题请教,请进 - leftatrium2 [2002-07-10 16:52 | 799 byte(s)]
 
Subject: 基于Linux的两节点高可用服务器
Author: acon    Posted: 2002-07-07 10:46    Length: 10,555 byte(s)
[Original] [Print] [Top]
基于Linux的两节点高可用服务器
――Heartbeat 的安装和设置
Linux作为类Unix,本身就具备很好的稳定性。然而,在实际应用中,往往要求系统具备更高的稳定性。高可用集群技术利用通用的硬件和成熟的网络技术,花费相对较小的代价,就可大大提高系统的稳定性,保证系统能提供不间断的服务。
目前,Linux上常用的集群软件是Heartbeat,它由Alan Robertson <alanr@unix.sh>等人开发和维护。出于兴趣,我在安装了该软件,建立了由两台PC机构成的Linux集群。下面是安装和测试过程。
硬件平台:
PC机: 双P3 500 CPU,内存256MB,40G硬盘,两片百兆以太网卡。
16口交换机一台。
串口数据线一条。
软件:Red Hat Linux 7.1 ,heartbeat 0.4.9.1 。

安装过程:
用串口线连接两台PC的串口1。
分别为两台PC机安装Red Hat Linux 7.1操作系统,其他的Linux 发行版本也可以。我们把两台PC的主机名分别设置为node1和node2。
每台PC机的两块网卡分别用来作为私有网网络络接口和公共网网络络接口,heartbeat使用私有网络用来传输心跳,集群外部用户可以使用公共网络接口来访问集群提供的服务,如http,nfs,samba等。我们将两块私有网络接口用直连线连接。公共网络接口通过HUB连接到公用网络中。
为node1和node2的网络接口分配如下的IP地址:
node 1 : 192.168.0.1 (公共网络接口)
10.0.0.1 (私有网络接口)
node 2 : 192.168.0.2 (公共网络接口)
10.0.0.2 (私有网络接口)

测试串口数据线是否正确:
在node1上使用命令 cat </dev/ttyS0
在node2上使用命令echo hello >/dev/ttyS0
在接收方node1上应该能够看到有hello输出。
调换接收方和发送方,作同样的测试,保证串口数据线正常。

从http://linux-ha.org/download下载heatbeat软件包,当前的版本是0.4.9.1。
tar –xvzf heatbeat-0.4.9.1 ,解包
make ,编译
make install ,安装

配置heartbeat需要配置三个文件:ha.cf,haresources,Authkeys。heartbeat源文件的doc目录中有这三个文件的样例文件。Heatbeat要求把这三个文件保存在/etc/ha.d目录中,我们把doc目录中的这三个拷贝到/etc/ha.d目录中来编辑。

配置这三个文件可以参照doc/GettingStarted.html文件来配置。
在我们的例子中,这三文件的内容分别是:
ha.cf文件
#
# There are lots of options in this file. All you have to have is a set
# of nodes listedJ {"node ...}
# and one of {serial, udp, or mcast}
#
#
# Note on logging:
# If any of debugfile, logfile and logfacility are defined then they
# will be used. If debugfile and/or logfile are not defined and
# logfacility is defined then the respective logging and debug
# messages will be loged to syslog. If logfacility is not defined
# then debugfile and logfile will be used to log messges. If
# logfacility is not defined and debugfile and/or logfile are not
# defined then defaults will be used for debugfile and logfile as
# required and messages will be sent there.
#
# File to wirte debug messages to
debugfile /var/log/ha-debug
#
#
# File to write other messages to
#
logfile /var/log/ha-log
#
#
# Facility to use for syslog()/logger
#
logfacility local0
#
#
# keepalive: how many seconds between heartbeats
#
keepalive 2
#
# deadtime: seconds-to-declare-host-dead
#
deadtime 10
#
#
# Very first dead time (initdead)
#
# On some machines/OSes, etc. the network takes a while to come up
# and start working right after you've been rebooted. As a result
# we have a separate dead time for when things first come up.
# It should be at least twice the normal dead time.
#
#initdead 120
#
# hopfudge maximum hop count minus number of nodes in config
#hopfudge 1
#
# serial serialportname ...
serial /dev/ttyS0
#
# Baud rate for serial ports...
#
baud 19200
#
# What UDP port to use for communication?
#
udpport 694
#
# What interfaces to heartbeat over?
#
udp eth0
#
# Set up a multicast heartbeat medium
# mcast [dev] [mcast group] [port] [ttl] [loop]
#
# [dev] device to send/rcv heartbeats on
# [mcast group] multicast group to join (class D multicast address
# 224.0.0.0 - 239.255.255.255)
# [port] udp port to sendto/rcvfrom (no real reason todiffer
# from the port used for broadcast heartbeats)
# [ttl] the ttl value for outbound heartbeats. this effects
# how far the multicast packet will propagate.(0-255)
# [loop] toggles loopback for outbound multicast heartbeats.
# if enabled, an outbound packet will be loopedback and
# received by the interface it was sent on. (0 r 1)
#
#
mcast eth0 225.0.0.1 694 1 1
#
# Watchdog is the watchdog timer. If our own heart doesn't beat for
# a minute, then our machine will reboot.
#
watchdog /dev/watchdog
#
# "Legacy" STONITH support
# Using this directive assumes that there is one stonith
# device in the cluster. Parameters to this device are
# read from a configuration file. The format of this line is:
#
# stonith <stonith_type> <configfile>
#
# NOTE: it is up to you to maintain this file on each node in the
# cluster!
#
#stonith baytech /etc/ha.d/conf/stonith.baytech
#
# STONITH support
# You can configure multiple stonith devices using this directive.
# The format of the line is:
# stonith_host <hostfrom> <stonith_type> <params...>
# <hostfrom> is the machine the stonith device is attached
# to or * to mean it is accessible from any host.
# <stonith_type> is the type of stonith device (a list of
# supported drives is in /usr/lib/stonith.)
# <params...> are driver specific parameters. To see the
# format for a particular device, run:
# stonith -l -t <stonith_type>
#
#
# Note that if you put your stonith device access information in
# here, and you make this file publically readable, you're askin
g
# for a denial of service attack ;-)
#
#
#stonith_host * baytech 10.0.0.3 mylogin mysecretpassword
#stonith_host ken3 rps10 /dev/ttyS1 kathy 0
#stonith_host kathy rps10 /dev/ttyS1 ken3 0
#
# Tell what machines are in the cluster
# node nodename ... -- must match uname -n
node Node1
node Node2

authkeys文件

#
# Authentication file. Must be mode 600
#
#
# Must have exactly one auth directive at the front.
# auth send authentication using this method-id
#
# Then, list the method and key that go with that method-id
#
# Available methods: crc sha1, md5. Crc doesn't need/want a key
.
#
# You normally only have one authentication method-id listed in this file
#
# Put more than one to make a smooth transition when changing auth
# methods and/or keys.
#
#
# sha1 is believed to be the "best", md5 next best.
#
# crc adds no security, except from packet corruption.
# Use only on physically secure networks.
#
#auth 1
#1 crc
#2 sha1 HI!
#3 md5 Hello!
auth 1
1 crc

haresouces:
node2 192.168.0.99 httpd

测试一:
1. 在两台机器上启动heartbeat:
/etc/init.d/heartbeat start
2. 在node2上使用命令:ifconfig,可以看到有:
eth0:0 192.168.0.99 ,同时使用ps –x 命令也可以看到httpd已经启动,这表明集群已经能够向公共网络提供http服务。此时,在node1上使用ifconfig命令无法看到eth0:0 192.168.0.99。
3. 重新启动node2,十几秒种后,在node1上使用命令ifconfig,则可以看到eth0:0 192.168.0.99,同时httpd服务在node1上也启动起来了。
4. 当node2重新启动后,在node1上使用命令ifconfig,将无法看到eth0:0 192.168.0.99,node1上的httpd服务在也停止了。此时,在node2上使用ifconfig命令,可以看到eth0:0 192.168.0.99,httpd服务也启动起来了。
这是因为我们在haresouces文件中,已经把node2定义成主节点。在主节点正常时,主节点上会把高可用服务从备份节点接管到主节点上。

测试二:
1. 在node1上使用命令:ifdown eth0, 禁止私有网络接口。我们知道私有网络接口和串口是用来传输心跳信号的,禁止私有网络接口意味着无法从网络接口传输心跳信号。
2. 重新启动node2,十几秒钟后,在node1上使用命令ifconfig,我们能看到IP地址192.168.0.99。http服务也启动起来了。
3. 之所以同时使用私有网络接口和串口线来传输心跳信号,是为了去除单一故障点(SPOF single point of failure)保证心跳信号不会因为网络接口或串口的故障而消失,提高系统的可靠性。

测试三:
1. 测试watchdog。
2. Watchdog能够在心跳消失一分钟后,使系统重启。
3. insmod softdog //插入softdog模块
4. mknod /dev/watchdog c 10 130
5. ifdown eth0
6. /etc/init.d/heartbeat stop //停止heartbeat
7. 系统没有重新启动,为什么???




[Original] [Print] [Top]
Subject: acon大哥,有问题请教,请进
Author: leftatrium2    Posted: 2002-07-10 16:52    Length: 799 byte(s)
[Original] [Print] [Top]
我做的HeartBeat是基于lvs集群的,但在配置完后,发现,启动heartbeart的时候出现下列错误:
Starting High-Availability services: mknod: wrong number of arguments
Try `mknod --help' for more information.
[FAILED]
另外,我的uname -n是这样的:
[root@lvs ha.d]# uname -n
lvs
我的系统是架构在单网卡结构里的,两台主机分别是:
lvs 10.64.162.250
lvsbackup 10.64.162.241
lvs的虚拟服务器ip是:10.64.162.253(eth0:0)
两台的heartbeat配置文件相同,分别是:
/etc/ha.d/ha.cf:
node lvs
node lvsbackup
/etc/ha.d/haresources :
lvs 10.64.162.253 lvs mon
/etc/ha.d/authkeys:
auth 1
1 crc
其余部分跟你的配置相同,不知道到底是怎么回事,帮我!
----
hello everyfriends.
[Original] [Print] [Top]
« Previous thread
如何shadow一个Xsession?就像win2k终端的shadow命令一样。
Linux 集群技术
12
Next thread »
关于主机的迁移
     

Copyright © 2007~2009 UNIX Resources Network, All Rights Reserved.      About URN | Privacy & Legal | Help | Contact us
webmaster: webmaster@unixresources.net
This page created on 2009-09-07 16:37:53, cost 0.020133972168 ms.