heartbeat + http 高可用
一,试验拓扑:
heartbeat + http/lvs 高可用实例
二,两节点基本配置:
(这里我先配置的node1,node2也是一样的)
1、修改主机名
# vim /etc/sysconfig/network
HOSTNAME=node1
2、修改hosts,这里没做DNS所以写hosts
# vim /etc/hosts
192.168.80.141  node1
192.168.80.138  node2
3、配置http服务相关信息
# yum -y install httpd
# echo "node1" > /var/www/html/index.html
# chkconfig httpd off (这里设置成不启动,因为要使用heartbeat启动)
4、配置ssh双机互信
# ssh-****** -t rsa
# ssh-copy-id -i .ssh/id_rsa.pub  [email protected]
注:需要注意2节点的时间不要相差太多

三,安装heartbeat
这里使用的rpm安装的:

  1. # yum -y --nogpgcheck localinstall heartbeat-2.1.4-9.el5.i386.rpm heartbeat-pils-2.1.4-10.el5.i386.rpm heartbeat-stonith-2.1.4-10.el5.i386.rpm libnet-1.1.4-3.el5.i386.rpm  
  2.  
  3. # cd /usr/share/doc/heartbeat-2.1.4/   
  4. # cp ha.cf authkeys haresources /etc/ha.d/  
  5. # chmod 600 authkeys  
  6.  
  7. # vim authkeys (添加如下内容md5后面的是个加密的随机数通过dd if=/dev/urandom count=512 bs=1 | md5sum最后一行产生的)  
  8. auth 1  
  9. 1 md5 3c41810e230a997444836b164ddb7978  
  10.  
  11. # egrep -v "^#|^$" /etc/ha.d/ha.cf   
  12. logfacility local0  
  13. keepalive 2     心跳检查时间  
  14. deadtime 30     防止分裂  
  15. bcast eth1  # Linux   指定网卡  
  16. auto_failback on    是重新抢回资源  
  17. node node1     节点名称与hosts对称  
  18. node node2  
  19. ping 192.168.80.1   指定仲裁  
  20. compression bz2    指定压缩  
  21. compression_threshold 2   2K以上压缩  
  22.  
  23. # vim /etc/ha.d/haresources   最后添加  
  24. node1  192.168.80.100/24/eth1/192.168.80.255 httpd  
  25.  
  26. # scp -p  authkeys ha.cf haresources node2:/etc/ha.d  
  27. # service heartbeat start  
  28. # ssh node2 '/etc/rc.d/init.d/heartbeat start'  
  29.  
下面访问下:
 
 heartbeat + http/lvs 高可用实例 
 

之后可以通过执行cd /usr/share/heartbeat/下的
# ./hb_standby
2012/08/03_00:41:33 Going standby [all].
进行手动切换,在访问下,而且也可以可能到80的进程
heartbeat + http/lvs 高可用实例
heartbeat + http/lvs 高可用实例
 

heartbeat + lvs  高可用
一:试验拓扑如下:
heartbeat + http/lvs 高可用实例
二:配置RS
这里为了方便直接使用脚本操作,RS1和RS2的配置一样:
 

  1. # cat /etc/rc.d/init.d/lvsdrrip   
  2. #!/bin/bash  
  3. #DR server  
  4. VIP=192.168.80.100  
  5. case "$1" in  
  6. start)  
  7.         echo "start LVS of DR"  
  8.         /sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up  
  9.         /sbin/route add -host $VIP dev lo:0  
  10.         echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore  
  11.         echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce  
  12.         echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore  
  13.         echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce  
  14.         ;;  
  15. stop)  
  16.         echo "stop LVS of DR"  
  17.         /sbin/ifconfig lo:0 down  
  18.         echo "0" > /proc/sys/net/ipv4/conf/lo/arp_ignore  
  19.         echo "0" > /proc/sys/net/ipv4/conf/lo/arp_announce  
  20.         echo "0" > /proc/sys/net/ipv4/conf/all/arp_ignore  
  21.         echo "0" > /proc/sys/net/ipv4/conf/all/arp_announce  
  22.         ;;  
  23. *)  
  24.         echo "Usage:$0 {start|stop}"  
  25.         exit 1  
  26. esac  
  27.  
  28. # chmod +x /etc/rc.d/init.d/lvsdrrip  
  29.  
  30. # yum -y install httpd  
  31. # echo "RS1" > /var/www/html/index.html  
  32.  
  33. # service httpd start  
  34. # service lvsdrrip start  
  35.  
三:配置nod1和node2
(这里在上个试验基础上操作,这次先用图形的操作)
1、首先关闭2节点的heartbeat服务
2、2节点安装图形软件包
# yum -y --nogpgcheck  localinstall perl-MailTools-1.77-1.el5.noarch.rpm  heartbeat-gui-2.1.4-9.el5.i386.rpm
3、2节点修改配置:
在/etc/ha.d/ha.cf最后添加
crm on
启动服务

  1. # service heartbeat start  
  2. # ssh node2 '/etc/rc.d/init.d/heartbeat start'  
  3. # passwd hacluster (这里在那台登录,在那个上设置密码即可)  
  4. # hb_gui & (进入图形设置) 
4、配置:
点连接,输入密码
heartbeat + http/lvs 高可用实例
右键,新建资源
 heartbeat + http/lvs 高可用实例
默认即可
 heartbeat + http/lvs 高可用实例
添加VIP
 heartbeat + http/lvs 高可用实例
在添加ipvsadm命令的
 heartbeat + http/lvs 高可用实例
之后添加排序约束
 heartbeat + http/lvs 高可用实例
默认即可
 heartbeat + http/lvs 高可用实例
添加信息
heartbeat + http/lvs 高可用实例
之后启动2个资源即可
 heartbeat + http/lvs 高可用实例

 
heartbeat + http/lvs 高可用实例
访问下看看,并且在node2上可以看到VIP信息
 heartbeat + http/lvs 高可用实例heartbeat + http/lvs 高可用实例
heartbeat + http/lvs 高可用实例

下面切换下,可以看到都在node1上了,并且ip addr show也有显示VIP信息,访问依旧正常,有轮询效果
   heartbeat + http/lvs 高可用实例
 
heartbeat + http/lvs 高可用实例

转载于:https://blog.51cto.com/peaceweb/951984

分类:

技术点:

相关文章: