免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3219 | 回复: 4
打印 上一主题 下一主题

双机lvs-ha 问题请教! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-03-25 17:58 |只看该作者 |倒序浏览
30可用积分
参考的
http://linux.chinaunix.net/bbs/thread-1014393-1-1.html
双机lvs-ha
主服务器+真实的web服务器 :192.168.2.25 一台主机
备服务器+ 真实的web服务器:192.168.2.39 一台主机
Lvs director 配置在主服务器上,根据源地址分配服务器。
集群的虚拟ip为60.*.184,初始分配在主服务器的eth0, 主服务器宕机后,ip由备份服务器接管,分配在备份服务器的eth0.
现在的问题是
[root@wangchangling ~]# ipvsadm
IP Virtual Server version 1.2.0 (size=4096)
Prot LocalAddressort Scheduler Flags
  -> RemoteAddressort           Forward Weight ActiveConn InActConn
TCP  60.*.184:http sh
  -> 60.*.168:http           Local   1      0          0      
只能负载到这一台主机!
配置文件如下:主
[root@wangchangling ~]# cat /etc/hosts
192.168.2.25            wangchangling
192.168.2.39            yanshu
127.0.0.1                wangchangling localhost.localdomain localhost
[root@wangchangling ha.d]# cat ha.cf |sed '/^#/d'
debugfile /var/log/ha-debug
logfile        /var/log/ha-log
logfacility        local0
keepalive 2
deadtime 30
warntime 10
initdead 40
ucast eth1 192.168.2.39
auto_failback on
node    wangchangling
node    yanshu
ping_group group1 192.168.2.25 192.168.2.39
respawn root /usr/lib/heartbeat/ipfail     
apiauth ipfail gid=root uid=root
# cat authkeys 这个权限是600
auth 1
1 crc
说明test.html内容为Test且都能访问http://real1/test.html http://real2/test.html
[root@wangchangling ha.d]# cat ldirectord.cf
checktimeout=3
checkinterval=2
fallback=127.0.0.1:80
autoreload=no
logfile="/var/log/ldirectord.log"
quiescent=no
virtual=60.*184:80
        real=60.*:80 gate
        real=60.*:80 gate
        service=http                       
        request="test.html"   
        receive="Test"        
        scheduler=sh                       
        protocol=tcp
        checktype=negotiate
        checkport=80       
[root@wangchangling ha.d]# cat haresources
wangchangling IPaddr::60.*.184 lvsdr-basic ldirectord
[root@wangchangling ha.d]# cat /etc/init.d/lvsdr-basic
#!/bin/sh
VIP=60.*.184
RIP1=60.*.168
RIP2=60.*.178
###########################
# ifconfig a
#
#/sbin/ifconfig eth0:0 $VIP broadcast $VIP netmask 255.255.255.255 up
#
############################
/sbin/route add -host $VIP dev eth0:0
echo "1" > /proc/sys/net/ipv4/ip_forward
[root@wangchangling ha.d]# cat ha.cf |sed '/^#/d'
debugfile /var/log/ha-debug
logfile        /var/log/ha-log
logfacility        local0
keepalive 2
deadtime 30
warntime 10
initdead 40
ucast eth1 192.168.2.39
auto_failback on
node    wangchangling
node    yanshu
ping_group group1 192.168.2.25 192.168.2.39
respawn root /usr/lib/heartbeat/ipfail     
apiauth ipfail gid=root uid=root


[root@yanshu ha.d]# cat ha.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility     local0
keepalive 2
deadtime 30
warntime 10
initdead 40
ucast eth1 192.168.2.25 #这里是区别
auto_failback on
node    wangchangling
node    yanshu
ping_group group1 192.168.2.25 192.168.2.29
respawn root /usr/lib/heartbeat/ipfail
apiauth ipfail gid=root uid=root
[root@yanshu ha.d]# cat haresources
wangchangling switchdr IPaddr::60.*.184
[root@yanshu ha.d]# cat /etc/init.d/switchdr
#!/bin/sh
# description: close lo0 and arp_ignore
VIP=60.*.184

. /etc/rc.d/init.d/functions

case "$1" in
    start)
        echo "************* start director server and close tunl ***********"
        ifconfig lo:0 down
        echo 0>/proc/sys/net/ipv4/conf/all/arp_announce
        ;;
    stop)
        echo "start Real Server"
        ifconfig eth0:0 down
        ifconfig lo:0  $VIP netmask 255.255.255.255 broadcast $VIP up
        /sbin/route add -host $VIP dev lo:0

        echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
        echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
        echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
        echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
        sysctl -p
        ;;
    *)
        echo "Usage: switchdr {start|stop}"
        exit 1
esac
日志如下:启动主LVS的heartbeat
Mar 25 17:52:53 wangchangling heartbeat: [8455]: info: Version 2 support: false
Mar 25 17:52:53 wangchangling heartbeat: [8455]: WARN: Logging daemon is disabled --enabling logging daemon is recommended
Mar 25 17:52:53 wangchangling heartbeat: [8455]: info: **************************
Mar 25 17:52:53 wangchangling heartbeat: [8455]: info: Configuration validated. Starting heartbeat 2.1.3
Mar 25 17:52:53 wangchangling heartbeat: [8456]: info: heartbeat: version 2.1.3
Mar 25 17:52:54 wangchangling heartbeat: [8456]: info: Heartbeat generation: 1237807394
Mar 25 17:52:54 wangchangling heartbeat: [8456]: info: glib: ucast: write socket priority set to IPTOS_LOWDELAY on eth1
Mar 25 17:52:54 wangchangling heartbeat: [8456]: info: glib: ucast: bound send socket to device: eth1
Mar 25 17:52:54 wangchangling heartbeat: [8456]: info: glib: ucast: bound receive socket to device: eth1
Mar 25 17:52:54 wangchangling heartbeat: [8456]: info: glib: ucast: started on port 694 interface eth1 to 192.168.2.39
Mar 25 17:52:54 wangchangling heartbeat: [8456]: info: glib: ping group heartbeat started.
Mar 25 17:52:54 wangchangling heartbeat: [8456]: info: G_main_add_TriggerHandler: Added signal manual handler
Mar 25 17:52:54 wangchangling heartbeat: [8456]: info: G_main_add_TriggerHandler: Added signal manual handler
Mar 25 17:52:54 wangchangling heartbeat: [8456]: info: G_main_add_SignalHandler: Added signal handler for signal 17
Mar 25 17:52:54 wangchangling heartbeat: [8456]: info: Local status now set to: 'up'
Mar 25 17:52:55 wangchangling heartbeat: [8456]: info: Link yanshu:eth1 up.
Mar 25 17:52:55 wangchangling heartbeat: [8456]: info: Status update for node yanshu: status active
Mar 25 17:52:55 wangchangling harc[8465]: info: Running /etc/ha.d/rc.d/status status
Mar 25 17:52:55 wangchangling heartbeat: [8456]: info: Link group1:group1 up.
Mar 25 17:52:55 wangchangling heartbeat: [8456]: info: Status update for node group1: status ping
Mar 25 17:52:55 wangchangling heartbeat: [8456]: info: Comm_now_up(): updating status to active
Mar 25 17:52:55 wangchangling heartbeat: [8456]: info: Local status now set to: 'active'
Mar 25 17:52:55 wangchangling heartbeat: [8456]: info: Starting child client "/usr/lib/heartbeat/ipfail     " (0,0)
Mar 25 17:52:55 wangchangling heartbeat: [8482]: info: Starting "/usr/lib/heartbeat/ipfail     " as uid 0  gid 0 (pid 8482)
Mar 25 17:52:56 wangchangling heartbeat: [8456]: info: remote resource transition completed.
Mar 25 17:52:56 wangchangling heartbeat: [8456]: info: remote resource transition completed.
Mar 25 17:52:56 wangchangling heartbeat: [8456]: info: Local Resource acquisition completed. (none)
Mar 25 17:52:56 wangchangling heartbeat: [8456]: info: yanshu wants to go standby [foreign]
Mar 25 17:52:57 wangchangling heartbeat: [8456]: info: standby: acquire [foreign] resources from yanshu
Mar 25 17:52:57 wangchangling heartbeat: [8486]: info: acquire local HA resources (standby).
Mar 25 17:52:57 wangchangling ResourceManager[8499]: info: Acquiring resource group: wangchangling IPaddr::60.28.211.184 lvsdr-basic ldirectord
Mar 25 17:52:57 wangchangling IPaddr[8526]: INFO:  Resource is stopped
Mar 25 17:52:57 wangchangling ResourceManager[8499]: info: Running /etc/ha.d/resource.d/IPaddr 60.*.184 start
Mar 25 17:52:57 wangchangling IPaddr[8600]: INFO: Using calculated nic for 60.*.184: eth0
Mar 25 17:52:57 wangchangling IPaddr[8600]: INFO: Using calculated netmask for 60.*.184: 255.255.255.224
Mar 25 17:52:57 wangchangling IPaddr[8600]: INFO: eval ifconfig eth0:0 60.*.184 netmask 255.255.255.224 broadcast 60.28.211.191
Mar 25 17:52:57 wangchangling IPaddr[8583]: INFO:  Success
Mar 25 17:52:57 wangchangling ResourceManager[8499]: info: Running /etc/init.d/lvsdr-basic  start
Mar 25 17:52:57 wangchangling ResourceManager[8499]: info: Running /etc/ha.d/resource.d/ldirectord  start
Mar 25 17:52:58 wangchangling heartbeat: [8486]: info: local HA resource acquisition completed (standby).
Mar 25 17:52:58 wangchangling heartbeat: [8456]: info: Standby resource acquisition done [foreign].
Mar 25 17:52:58 wangchangling heartbeat: [8456]: info: Initial resource acquisition complete (auto_failback)
Mar 25 17:52:58 wangchangling heartbeat: [8456]: info: remote resource transition completed.
Mar 25 17:53:03 wangchangling ipfail: [8482]: info: Ping node count is balanced.
Mar 25 17:53:03 wangchangling ipfail: [8482]: info: Giving up foreign resources (auto_failback).
Mar 25 17:53:03 wangchangling ipfail: [8482]: info: Delayed giveup in 4 seconds.
Mar 25 17:53:07 wangchangling ipfail: [8482]: info: giveup() called (timeout worked)
Mar 25 17:53:08 wangchangling heartbeat: [8456]: info: wangchangling wants to go standby [foreign]
Mar 25 17:53:08 wangchangling heartbeat: [8456]: info: standby: yanshu can take our foreign resources
Mar 25 17:53:08 wangchangling heartbeat: [8773]: info: give up foreign HA resources (standby).
Mar 25 17:53:08 wangchangling heartbeat: [8773]: info: foreign HA resource release completed (standby).
Mar 25 17:53:08 wangchangling heartbeat: [8456]: info: Local standby process completed [foreign].
Mar 25 17:53:09 wangchangling heartbeat: [8456]: WARN: 1 lost packet(s) for [yanshu] [1518:1520]
Mar 25 17:53:09 wangchangling heartbeat: [8456]: info: remote resource transition completed.
Mar 25 17:53:09 wangchangling heartbeat: [8456]: info: No pkts missing from yanshu!
Mar 25 17:53:09 wangchangling heartbeat: [8456]: info: Other node completed standby takeover of foreign resources.

[ 本帖最后由 xuledw 于 2009-3-25 18:00 编辑 ]

最佳答案

查看完整内容

直接配置 ldirectord ldirectord 需要你在真实服务器内启用apache服务器,并在每台真实服务器web服务器的根目录下建立你在配置文件所指定的文件与内容,然后ldirectord 通过循环检查此文件来确定真实服务器是否存活,如果不存活,则自动将其权重设为0,以确保后面客户的连接不会再导向失效的真实服务器,如果真实服务修复上线后,则其又将它的权重设为以使它能够继续为客端连接提供服务。ldirectord主要是通过调用ipvsadm来创建ipv ...

论坛徽章:
0
2 [报告]
发表于 2009-03-25 17:58 |只看该作者

回复 #1 xuledw 的帖子

直接配置 ldirectord ldirectord 需要你在真实服务器内启用apache服务器,并在每台真实服务器web服务器的根目录下建立你在配置文件所指定的文件与内容,然后ldirectord 通过循环检查此文件来确定真实服务器是否存活,如果不存活,则自动将其权重设为0,以确保后面客户的连接不会再导向失效的真实服务器,如果真实服务修复上线后,则其又将它的权重设为以使它能够继续为客端连接提供服务。
ldirectord主要是通过调用ipvsadm来创建ipvs虚拟服务器表。

参考示例如下
lvs-primary和lvs-backup服务配置
VIP=192.168.1.88
lvs-primary=>192.168.1.99
lvs-backup=>192.168.1.99
real-server1=>192.168.1.97
real-server2=>192.168.1.188


1、/etc/init.d/lvs
#!/bin/sh
# chkconfig: 2345 90 10
# description: Preparing for Load Balancer and Real Server switching
VIP=192.168.1.88
. /etc/rc.d/init.d/functions
case "$1" in
    start)
        echo "Preparing for Load Balancer"
        ifconfig eth0:1 down
        echo 1 > /proc/sys/net/ipv4/ip_forward
        echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
        echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
        echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
        echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
        ;;
    stop)
        echo "Preparing for Real Server"
        ifconfig eth0:1 $VIP netmask 255.255.255.255 broadcast $VIP up
        echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
        echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
        echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
        echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
        ;;
    *)
        echo "Usage: lvs {start|stop}"
        exit 1
esac


2、/etc/sysconfig/ipvsadm
-A -t 192.168.1.88:80 -s rr
-a -t 192.168.1.88:80 -r 192.168.1.97:80 -g
-a -t 192.168.1.88:80 -r 192.168.1.188:80 -g


3、/etc/ha.d/ha.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 120
udpport 694
baud 19200
#serial /dev/ttyS0
#mcast eth0 225.0.0.1 694 1 0
auto_failback on
node lvs-primary
node lvs-backup
ping_group 192.168.1.1 192.168.1.51
respawn root /usr/lib/heartbeat/ipfail
apiauth ipfail gid=root uid=root
bcast eth0


4、/etc/ha.d/haresources
lvs-primary lvs IPaddr::192.168.1.88/24/eth0:0 ipvsadm ldirectord

5、/etc/ha.d/ldirectord.cf
checktimeout=3
checkinterval=1
autoreload=yes
quiescent=yes
# Sample for an http virtual service
virtual=192.168.1.88:80
        real=192.168.1.97:80 gate
        real=192.168.1.188:80 gate
        fallback=127.0.0.1:80 gate
        service=http
        request="test.html"
        receive="Test Page"
        scheduler=rr
        protocol=tcp

6、/etc/sysconfig/network
HOSTNAME=lvs-primary(备份服务器HOSTNAME=lvs-backup)

[ 本帖最后由 kns1024wh 于 2009-3-25 20:33 编辑 ]

论坛徽章:
0
3 [报告]
发表于 2009-03-26 09:47 |只看该作者
原帖由 kns1024wh 于 2009-3-25 18:13 发表
直接配置 ldirectord ldirectord 需要你在真实服务器内启用apache服务器,并在每台真实服务器web服务器的根目录下建立你在配置文件所指定的文件与内容,然后ldirectord 通过循环检查此文件来确定真实服务器是否 ...

感谢你的回帖!问题现在基本确认了 是我配置文件的问题。我直接从/usr/share/doc/heartbeat-2.1.3/拷贝文件到/etc/ha.d然后按照我需要的参数更改就没有问题!难道配置中会存在空格和换行?这个是个疑问!

论坛徽章:
1
数据库技术版块每日发帖之星
日期:2016-03-10 06:20:00
4 [报告]
发表于 2009-03-26 12:18 |只看该作者
127.0.0.1                wangchangling localhost.localdomain localhost



你的hosts文件有问题,应该改为:127.0.0.1               localhost.localdomain localhost

论坛徽章:
0
5 [报告]
发表于 2009-03-31 13:18 |只看该作者
原帖由 kns1024wh 于 2009-3-25 17:58 发表
直接配置 ldirectord ldirectord 需要你在真实服务器内启用apache服务器,并在每台真实服务器web服务器的根目录下建立你在配置文件所指定的文件与内容,然后ldirectord 通过循环检查此文件来确定真实服务器是否 ...

我的问题解决了 不过还是把分评给你了 呵呵
不是配置问题 是环境问题 apache侦听端口问题1
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP