[ 作者: 加入时间:2007-10-19 12:40:54 来自:Linux联盟收集整理 ]
www.xxlinux.com
第一次接触集群,用了快三天的时间了还没真正实现点什么,在CU上也相对比较少这方面的资料,但为了你我方便还是记下点东西来。下面是我从网上收集的一些相关资料。RPCLinux联盟
RPCLinux联盟
首先说下集群的概念吧.RPCLinux联盟
可以把Linux集群分为三类。一类是高可用性集群,运行于两个或多个节点上,目的是在系统出现某些故障的情况下,仍能继续对外提供服务。高可用性集群的设计思想就是要最大限度地减少服务中断时间。这类集群中比较著名的有Turbolinux TurboHA、Heartbeat、Kimberlite等。第二类是负载均衡集群,目的是提供和节点个数成正比的负载能力,这种集群很适合提供大访问量的Web服务。负载均衡集群往往也具有一定的高可用性特点。Turbolinux Cluster Server、Linux Virtual Server都属于负载均衡集群。另一类是超级计算集群,按照计算关联程度的不同,又可以分为两种。一种是任务片方式,要把计算任务分成任务片,再把任务片分配给各节点,在各节点上分别计算后再把结果汇总,生成最终计算结果。另一种是并行计算方式,节点之间在计算过程中大量地交换数据,可以进行具有强耦合关系的计算。这两种超级计算集群分别适用于不同类型的数据处理工作。有了超级计算集群软件,企业利用若干台PC机就可以完成通常只有超级计算机才能完成的计算任务。这类软件有Turbolinux EnFusion、SCore等。 RPCLinux联盟
RPCLinux联盟
到网上找了找相关软件,于是觉得heartbeat挺不错的,配置有简单方便。那介绍下heartbeat吧。RPCLinux联盟
heartbeat 自动把ip 服务 通过心跳监测 主服务器瘫痪时 自动切到备用机器 做高可用性集群用。RPCLinux联盟
大致阐述一下heartbeat的工作原理:heartbeat最核心的包括两个部分,心跳监测部分和资源接管部分,心跳监测可以通过网络链路和串口进行,而且支持冗余链路,它们之间相互发送报文来告诉对方自己当前的状态,如果在指定的时间内未受到对方发送的报文,那么就认为对方失效,这时需启动资源接管模块来接管运行在对方主机上的资源或者服务。RPCLinux联盟
RPCLinux联盟
软件准备:RPCLinux联盟
heartbeat-2.0.6.tar.gz 下载地址:http://download.chinaunix.net/download.php?id=24742&ResourceID=67RPCLinux联盟
我在rh环境下编译过程中缺少libnet库,翻遍光盘网上也找了好多好久都没有合适的最后发现软来用FC里边的RPM包libnet-devel- 1.1.2.1-6.fc4.i386.rpm挺管用!下载地址:http: //rpmfind.net/linux/rpm2html/search.php?query=libnet-develRPCLinux联盟
RPCLinux联盟
编译完成后需要找到三个主配置文件,复制到/etc/ha.d/ha.cf、/etc/ha.d/haresources、/etc/ha.d/authkeys。RPCLinux联盟
RPCLinux联盟
三个文件的主要配置如下: RPCLinux联盟
/etc/ha.d/ha.cf RPCLinux联盟
# If any of debugfile, logfile and logfacility are defined then they RPCLinux联盟
# will be used. If debugfile and/or logfile are not defined and RPCLinux联盟
# logfacility is defined then the respective logging and debug RPCLinux联盟
# messages will be loged to syslog. If logfacility is not defined RPCLinux联盟
# then debugfile and logfile will be used to log messges. If RPCLinux联盟
# logfacility is not defined and debugfile and/or logfile are not RPCLinux联盟
# defined then defaults will be used for debugfile and logfile as RPCLinux联盟
# required and messages will be sent there. RPCLinux联盟
# RPCLinux联盟
# File to wirte debug messages to RPCLinux联盟
debugfile /var/log/ha-debug RPCLinux联盟
# RPCLinux联盟
# RPCLinux联盟
# File to write other messages to RPCLinux联盟
# RPCLinux联盟
logfile /var/log/ha-log RPCLinux联盟
# RPCLinux联盟
# RPCLinux联盟
# Facility to use for syslog()/logger RPCLinux联盟
# RPCLinux联盟
logfacility local0 RPCLinux联盟
# RPCLinux联盟
# RPCLinux联盟
# keepalive: how many seconds between heartbeats RPCLinux联盟
# RPCLinux联盟
keepalive 2 RPCLinux联盟
# RPCLinux联盟
# deadtime: seconds-to-declare-host-dead RPCLinux联盟
# RPCLinux联盟
deadtime 10 RPCLinux联盟
# RPCLinux联盟
# RPCLinux联盟
# Very first dead time (initdead) RPCLinux联盟
# RPCLinux联盟
# On some machines/OSes, etc. the network takes a while to come up RPCLinux联盟
# and start working right after you've been rebooted. As a result RPCLinux联盟
# we have a separate dead time for when things first come up. RPCLinux联盟
# It should be at least twice the normal dead time. RPCLinux联盟
# RPCLinux联盟
initdead 120 RPCLinux联盟
# RPCLinux联盟
# hopfudge maximum hop count minus number of nodes in config RPCLinux联盟
#hopfudge 1 RPCLinux联盟
# RPCLinux联盟
# serial serialportname ... RPCLinux联盟
serial /dev/ttyS0 RPCLinux联盟
# RPCLinux联盟
# RPCLinux联盟
# Baud rate for serial ports... RPCLinux联盟
# RPCLinux联盟
baud 19200 RPCLinux联盟
# RPCLinux联盟
# What UDP port to use for communication? RPCLinux联盟
# RPCLinux联盟
udpport 694 RPCLinux联盟
# RPCLinux联盟
# What interfaces to heartbeat over? RPCLinux联盟
# RPCLinux联盟
udp eth1 RPCLinux联盟
# RPCLinux联盟
# Set up a multicast heartbeat medium RPCLinux联盟
# mcast [dev] [mcast group] [port] [ttl] [loop] RPCLinux联盟
# RPCLinux联盟
# [dev] device to send/rcv heartbeats on RPCLinux联盟
# [mcast group] multicast group to join (class D multicast address RPCLinux联盟
# 224.0.0.0 - 239.255.255.255) RPCLinux联盟
# [port] udp port to sendto/rcvfrom (no real reason to differ RPCLinux联盟
# from the port used for broadcast heartbeats) RPCLinux联盟
# [ttl] the ttl value for outbound heartbeats. this effects RPCLinux联盟
# how far the multicast packet will propagate. (0-255) RPCLinux联盟
# [loop] toggles loopback for outbound multicast heartbeats. RPCLinux联盟
# if enabled, an outbound packet will be looped back and RPCLinux联盟
# received by the interface it was sent on. (0 or 1) RPCLinux联盟
# RPCLinux联盟
# RPCLinux联盟
mcast eth1 225.0.0.1 694 1 1 RPCLinux联盟
# RPCLinux联盟
# Watchdog is the watchdog timer. If our own heart doesn't beat for RPCLinux联盟
# a minute, then our machine will reboot. RPCLinux联盟
# RPCLinux联盟
watchdog /dev/watchdog RPCLinux联盟
# RPCLinux联盟
# "Legacy" STONITH support RPCLinux联盟
# Using this directive assumes that there is one stonith RPCLinux联盟
# device in the cluster. Parameters to this device are RPCLinux联盟
# read from a configuration file. The format of this line is: RPCLinux联盟
# RPCLinux联盟
# stonith
#333 RPCLinux联盟
# NOTE: it is up to you to maintain this file on each node in the RPCLinux联盟
# cluster! RPCLinux联盟
# RPCLinux联盟
#stonith baytech /etc/ha.d/conf/stonith.baytech RPCLinux联盟
# RPCLinux联盟
# STONITH support RPCLinux联盟
# You can configure multiple stonith devices using this directive. RPCLinux联盟
# The format of the line is: RPCLinux联盟
# stonith_host
#
# to or * to mean it is accessible from any host. RPCLinux联盟
#
# supported drives is in /usr/lib/stonith.) RPCLinux联盟
#
# format for a particular device, run: RPCLinux联盟
# stonith -l -t
# RPCLinux联盟
# RPCLinux联盟
# Note that if you put your stonith device access information in RPCLinux联盟
# here, and you make this file publically readable, you're asking RPCLinux联盟
# for a denial of service attack ;-) RPCLinux联盟
# RPCLinux联盟
# RPCLinux联盟
#stonith_host * baytech 10.0.0.3 mylogin mysecretpassword RPCLinux联盟
#stonith_host ken3 rps10 /dev/ttyS1 kathy 0 RPCLinux联盟
#stonith_host kathy rps10 /dev/ttyS1 ken3 0 RPCLinux联盟
# RPCLinux联盟
# Tell what machines are in the cluster RPCLinux联盟
# node nodename ... -- must match uname -n RPCLinux联盟
node xuanfei1-server RPCLinux联盟
node xuanfei2-server RPCLinux联盟
RPCLinux联盟
/etc/ha.d/haresources RPCLinux联盟
# RPCLinux联盟
#just.linux-ha.org 135.9.216.110 RPCLinux联盟
# RPCLinux联盟
#------------------------------------------------------------------- RPCLinux联盟
# RPCLinux联盟
# Assuming the adminstrative addresses are on the same subnet... RPCLinux联盟
# A little more complex case: One service address, default subnet RPCLinux联盟
# and netmask, and you want to start and stop http when you get RPCLinux联盟
# the IP address... RPCLinux联盟
# RPCLinux联盟
#just.linux-ha.org 135.9.216.110 http RPCLinux联盟
#------------------------------------------------------------------- RPCLinux联盟
# RPCLinux联盟
# A little more complex case: Three service addresses, default subnet RPCLinux联盟
# and netmask, and you want to start and stop http when you get RPCLinux联盟
# the IP address... RPCLinux联盟
# RPCLinux联盟
#just.linux-ha.org 135.9.216.110 135.9.215.111 135.9.216.112 httpd RPCLinux联盟
#------------------------------------------------------------------- RPCLinux联盟
# RPCLinux联盟
# One service address, with funny subnet and bcast addr RPCLinux联盟
# Stop and start httpd service with the subnet address RPCLinux联盟
# RPCLinux联盟
#just.linux-ha.org 135.9.216.3/4/135.9.216.12 httpd RPCLinux联盟
# RPCLinux联盟
#------------------------------------------------------------------- RPCLinux联盟
# RPCLinux联盟
# An example where a shared filesystem is to be used. RPCLinux联盟
# Note that multiple aguments are passed to this script using RPCLinux联盟
# the delimiter '::' to separate each argument. RPCLinux联盟
# RPCLinux联盟
#node1 10.0.0.170 Filesystem::/dev/sda1::/data1::ext2 RPCLinux联盟
RPCLinux联盟
RPCLinux联盟
xuanfei.com 10.0.0.10 httpd smb RPCLinux联盟
RPCLinux联盟
RPCLinux联盟
/etc/ha.d/authkeys RPCLinux联盟
# Authentication file. Must be mode 600 RPCLinux联盟
# RPCLinux联盟
# RPCLinux联盟
# Must have exactly one auth directive at the front. RPCLinux联盟
# auth send authentication using this method-id RPCLinux联盟
# RPCLinux联盟
# Then, list the method and key that go with that method-id RPCLinux联盟
# RPCLinux联盟
# Available methods: crc sha1, md5. Crc doesn't need/want a key. RPCLinux联盟
# RPCLinux联盟
# You normally only have one authentication method-id listed in this file RPCLinux联盟
# RPCLinux联盟
# Put more than one to make a smooth transition when changing auth RPCLinux联盟
# methods and/or keys. RPCLinux联盟
# RPCLinux联盟
# RPCLinux联盟
# sha1 is believed to be the "best", md5 next best. RPCLinux联盟
# RPCLinux联盟
# crc adds no security, except from packet corruption. RPCLinux联盟
# Use only on physically secure networks. RPCLinux联盟
# RPCLinux联盟
auth 1 RPCLinux联盟
1 crc RPCLinux联盟
#2 sha1 HI! RPCLinux联盟
#3 md5 Hello! RPCLinux联盟
记得修改文件authkeys的属性为600 chmod 600 /etc/ha.d/authkeysRPCLinux联盟
RPCLinux联盟
copy配置文件到其它节点:RPCLinux联盟
scp /etc/ha.d/ha.cf /etc/ha.d/haresources /etc/ha.d/authkeys root@xuanfei2:/etc/ha.d/RPCLinux联盟
RPCLinux联盟
#vi /etc/hostsRPCLinux联盟
node1的hosts内容如下:RPCLinux联盟
127.0.0.1 localhost.localdomain localhostRPCLinux联盟
10.0.0.1 xuanfei1 HA01RPCLinux联盟
192.168.0.1 HA01RPCLinux联盟
192.168.0.2 HA02RPCLinux联盟
10.0.0.2 xuanfei2
node2的hosts内容如下:RPCLinux联盟
127.0.0.1 localhost.localdomain localhostRPCLinux联盟
10.0.0.2 xuanfei2 HA02RPCLinux联盟
192.168.0.2 HA02RPCLinux联盟
192.168.0.1 HA01RPCLinux联盟
10.0.0.1 xuanfei1RPCLinux联盟
RPCLinux联盟
RPCLinux联盟
设置ipvsadm的巡回监测RPCLinux联盟
---------------------------RPCLinux联盟
ipvsadm -A -t 10.0.0.10:80 -s rrRPCLinux联盟
ipvsadm -a -t 10.0.0.10:80 -r 10.0.0.1:80 -mRPCLinux联盟
ipvsadm -a -t 10.0.0.10:80 -r 10.0.0.2:80 -m
执行后进行监测:RPCLinux联盟
#ipvsadm --listRPCLinux联盟
如果返回结果与下相同,则设置正确。RPCLinux联盟
IP Virtual Server version 1.2.0 (size=4096)RPCLinux联盟
Prot LocalAddress:Port Scheduler FlagsRPCLinux联盟
-> RemoteAddress:Port Forward Weight ActiveConn InActConnRPCLinux联盟
TCP 10.0.0.10:http rrRPCLinux联盟
-> xuanfei2:http Local 1 0 0RPCLinux联盟
-> xuanfei1:http Masq 1 0 0
RPCLinux联盟
RPCLinux联盟
HA服务的启动、关闭RPCLinux联盟
首先关闭两台机器需要集群的服务,因为heartbeat 启动时会自动服务打开(测试的时候会有几秒钟的滞后)RPCLinux联盟
/etc/rc.d/init.d/httpd stop RPCLinux联盟
/etc/rc.d/init.d/smb stop RPCLinux联盟
启动HA: service heartbeat startRPCLinux联盟
关闭HA; service heartbeat stopRPCLinux联盟
防火墙设置RPCLinux联盟
/bin/iptables -A RH-Firewall-1-INPUT -p udp -m udp --dport 694 -d 10.0.0.201 -j ACCEPTRPCLinux联盟
测试RPCLinux联盟
在别的机器里输入:http://10.0.0.10 (虚拟的地址) RPCLinux联盟
可以看到xuanfei1-server ,想办法让xuanfei1-server死机,大概3-5秒,可以看到页面变成xuanfei2-server,服务成功的转换了,等xuanfei1-server服务起来后,页面又切换到 RPCLinux联盟
xuanfei1-server,几乎没有延时。这样就提高了系统的高可用性。
www.xxlinux.com
Linux联盟收集整理 ,转贴请标明原始链接,如有任何疑问欢迎来本站Linux论坛讨论
没有评论:
发表评论