Chinaunix首页 | 论坛 | 博客
  • 博客访问: 102020618
  • 博文数量: 19283
  • 博客积分: 9968
  • 博客等级: 上将
  • 技术积分: 196062
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-07 14:28
文章分类

全部博文(19283)

文章存档

2011年(1)

2009年(125)

2008年(19094)

2007年(63)

分类: LINUX

2008-04-27 23:13:02

linux上的 heartbeat 双机热备服务架设(我现在在研究不知道好用不)
 
【一】 安装前
==========================================================
两台主机硬件(不必完全一致)
CPU: Xeon 3G *2 (EM64T)
MEM: 2G
NIC:  Intel 1G *2
eth0:
IP
eth1:
IP(HA)
两台主机的eth1使用双机对联线直接接。
分区方式:
Filesystem  
容量 
/dev/sda2    9.7G  /
/dev/sda6     45G  /Datas
/dev/sda1     99M  /boot
none2.0G  /dev/shm
/dev/sda3    9.7G  /opt
另外台主机应预500Mraw或者更多来作共用空HA使用。
操作系
RedHat Enterprise 4 Update2 (2.6.9-22 EL)
安装件:
@ X Window System
@ GNOME Desktop Environment
@ KDE Desktop Environment
@ Editors
@ Engineering and Scientific
@ Graphical Internet
@ Text-based Internet
@ Authoring and Publishing
@ Server Configuration Tools
@ Development Tools
@ Kernel Development
@ X Software Development
@ GNOME Software Development
@ KDE Software Development
@ Administration Tools
@ System Tools

 
【二】安装前网络环定:
===========================================================================
node1:
主机名:servers201 ( HA01 )
eth0:  192.168.10.201       //
IP地址
eth1:  10.0.0.201           //HA
心跳使用地址
node2: 主机名:servers202 ( HA02 )
eth0:  192.168.10.202       //
IP地址
eth1:  10.0.0.202           //HA
心跳使用地址
注意要检查以下几个文件:
/etc/hosts
/etc/host.conf
/etc/resolv.conf
/etc/sysconfig/network
/etc/sysconfig/network-scripts/ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-eth1
/etc/nsswitch.conf
#vi /etc/hosts
node1
hosts内容如下:
127.0.0.1        localhost.localdomain   localhost
192.168.10.201   servers201              HA01
10.0.0.201       HA01
10.0.0.202       HA02
192.168.10.202   server202
node2hosts内容如下:
127.0.0.1       localhost.localdomain   localhost
192.168.10.202  servers202              HA02
10.0.0.202      HA02
10.0.0.201      HA01
192.168.10.201  server201
#cat /etc/host.conf
order hosts,bind
#cat /etc/resolv.conf
nameserver 61.139.2.69    //DNS
地址
#cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=servers201           //
主机名
GATEWAY="192.168.10.1"    //

GATEWAY="eth0"           //
使用网卡
ONBOOT=YES               //
动时
FORWARD_IPV4="yes"       //
只允IPV4
#cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.10.201
NETMASK=255.255.255.0
GATEWAY=192.168.10.1
TYPE=Ethernet
IPV6INIT=no
#cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
ONBOOT=yes
BOOTPROTO=none
IPADDR=10.0.0.201
NETMASK=255.255.255.0
TYPE=Ethernet
[node1] [node2] 在上面的配置中,除了
/etc/hosts
/etc/sysconfig/network
/etc/sysconfig/network-scripts/ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-eth1
要各自修改外,其他一致。
配置完成后,试试在各自主机上ping方的主机名,应该可以ping:
/root#ping HA02
PING HA02 (10.0.0.202) 56(84) bytes of data.
64 bytes from HA02 (10.0.0.202): icmp_seq=0 ttl=64 time=0.198 ms
64 bytes from HA02 (10.0.0.202): icmp_seq=1 ttl=64 time=0.266 ms
64 bytes from HA02 (10.0.0.202): icmp_seq=2 ttl=64 time=0.148 ms
--- HA02 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 0.148/0.204/0.266/0.048 ms, pipe 2

 
【三】安装HA HA
===========================================================================
rpm -Uvh libnet-1.1.2.1-1.rh.el.um.1.i386.rpm  //
可以不装
rpm -Uvh heartbeat-pils-2.0.4-1.el4.i386.rpm
rpm -Uvh heartbeat-stonith-2.0.4-1.el4.i386.rpm
rpm -Uvh heartbeat-2.0.4-1.el4.i386.rpm
rpm -Uvh ipvsadm-1.24-5.i386.rpm

 
【四】 配置 HA的各配置文件
===========================================================================
---------------------------
配置心跳的加密方式:authkeys
---------------------------
#vi /etc/ha.d/authkeys
如果使用双机对联线(绞线),可以配置如下:
#vi /etc/hc.d/authkeys
auth 1
1 crc
退出,然后
#chmod 600 authkeys
---------------------------
配置心跳的控:haresources
---------------------------
#vi /etc/ha.d/haresources
各主机部分完全相同。
server201 IPaddr::192.168.10.200 ipvsadm httpd
指定 server201ipvsadmhttp,系附加一个虚IP 192.168.10.200 eth0:0
里如果server201宕机后,server202可以自http,并新分配IP 192.168.10.200server202eth0:0
---------------------------
配置心跳的配置文件:ha.cf
---------------------------
#vi /etc/ha.d/ha.cf
logfile /var/log/ha_log/ha-log.log   ## ha的日志文件记录位置。如没有需要手添加
bcast eth1     ##
使用eth1做心跳监测
keepalive 2    ##
定心跳(监测)时间时间为2
warntime 10
deadtime 30
initdead 120
hopfudge 1
udpport 694    ##
使用udp端口694 行心跳监测
auto_failback on
node server201  ##
1,必要与 uname -n 指令得到的果一致。
node server202  ##
2
ping 192.168.10.1   ##
ping 监测心跳是否正常。
respawn hacluster /usr/lib64/heartbeat/ipfail
apiauth ipfail gid=root uid=root
debugfile /Datas/logs/ha_log/ha-debug.log
---------------------------
ipvsadm的巡回监测
---------------------------
ipvsadm -A -t 192.168.10.200:80 -s rr
ipvsadm -a -t 192.168.10.200:80 -r 192.168.10.201:80 -m
ipvsadm -a -t 192.168.10.200:80 -r 192.168.10.202:80 -m
行后监测
#ipvsadm --list
如果返回果与下相同,则设置正确。
IP Virtual Server version 1.2.0 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.10.200:http rr
  -> server202:http               Local   1      0          0
  -> server201:http               Masq    1      0          0

 
【五】 HA的启关闭以及测试
===========================================================================
HA: service heartbeat start
关闭HA; service heartbeat stop
在启动时heartbeat 了。
使用http务测试 heartbeat
首先启httpd
#service httpd start
编辑各自主机的测试html文件,放到/var/www/html/下。
node1heartbeat,并个指令: heartbeat status

 
【六】 防火墙设
===========================================================================
heartbeat
使用udp 694端口行心跳监测 如果系有使用iptables 做防火应记住把个端口打
#vi /etc/sysconfig/iptables
加入以下内容
-A RH-Firewall-1-INPUT -p udp -m udp --dport 694 -d 10.0.0.201 -j ACCEPT
意思是udp 694端口 方的心跳网卡地址 10.0.0.201 放。
#service iptables restart
重新加iptables


阅读(281) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~