免费注册 查看新帖 |

Chinaunix

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

急问,LVS的rear server如何设成主备模式? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-11-16 11:28 |只看该作者 |倒序浏览
现有keepalived + LVS
real server有两台,keepalived 设置为:
vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 61
    priority 200
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.240.1.100/22
    }
}

virtual_server 10.240.1.100 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    protocol TCP

    real_server 10.240.1.1 80 {
        weight 1
        TCP_CHECK {
                connect_timeout 3
        }
    }

    real_server 10.240.1.2 80 {
        weight 1
        TCP_CHECK {
                connect_timeout 3
        }
    }
}

两台real server同时工作正常

现需要将real server的模式改为主备,
    real_server 10.240.1.1 80 {
        weight 100
        TCP_CHECK {
                connect_timeout 3
        }
    }

    real_server 10.240.1.2 80 {
        weight 0
        TCP_CHECK {
                connect_timeout 3
        }
    }

正常情况下,LVS连接都指向real server1
但是将real server关机后,继续访问VIP无效,不会指向real server2

请问是什么原因啊?非常感谢

论坛徽章:
0
2 [报告]
发表于 2011-11-16 13:22 |只看该作者
日志中Transition to MASTER STATE    Entering MASTER STATE 是否可以看到

论坛徽章:
0
3 [报告]
发表于 2011-11-16 14:07 |只看该作者
回复 2# kns1024wh


    关闭real server1后,日志里只有:
Keepalived_healthcheckers: TCP connection to [10.240.1.1:80] failed !!!
Keepalived_healthcheckers: Removing service [10.240.1.1:80] from VS [10.240.1.100:80]

可能我没表达清楚,VIP是没问题的,只是对VIP:80的访问不会指向real server2

论坛徽章:
0
4 [报告]
发表于 2011-11-17 10:19 |只看该作者
rear server还设置成主备? 由前面的调试算法完成就好了,rear server挂了,就踢出去

论坛徽章:
0
5 [报告]
发表于 2011-11-17 12:57 |只看该作者
回复  kns1024wh


    关闭real server1后,日志里只有:
Keepalived_healthcheckers: TCP connectio ...
ragecf 发表于 2011-11-16 14:07



    还是首先来解决网络连接的问题好了

论坛徽章:
0
6 [报告]
发表于 2011-11-17 17:36 |只看该作者
回复 5# kns1024wh


查到了,跟网络连接没关系,man ipvsadm,明确说明了weight为0就是不接新连接请求的。

评分

参与人数 1可用积分 +2 收起 理由
kns1024wh + 2 感谢分享

查看全部评分

论坛徽章:
0
7 [报告]
发表于 2011-11-17 17:49 |只看该作者
回复 6# ragecf


在主服务器上priority 100    那 备份服务上将100改为90或者50,搞成0 ?

在keepalived.conf的手册里面
# for electing MASTER, highest priority wins. # to be MASTER, make 50 more than other machines. priority 100
已经说明了,这个手册你要要看
  1. Name

  2. /etc/keepalived/keepalived.conf - configuration file for keepalived
  3. Description

  4. keepalived.conf is the configuration file which describes all the keepalived keywords. keywords are placed in hierachies of blocks (and subblocks), each layer being delimited by '{' and '}' pairs.

  5. Comments start with '#' or '!' to the end of the line and can start anywhere in a line.
  6. Top Hierachy

  7. GLOBAL CONFIGURATION

  8. VRRPD CONFIGURATION

  9. LVS CONFIGURATION
  10. Global Configuration

  11. contains subblocks of Global definitions and Static routes
  12. Global definitions

  13. global_defs # Block id { notification_email # To: { admin@example1.com ... } # From: from address that will be in header notification_email_from admin@example.com smtp_server 127.0.0.1 # IP smtp_connect_timeout 30 # integer, seconds router_id my_hostname # string identifying the machine, # (doesn't have to be hostname). }
  14. Static routes/addresses

  15. keepalived can configure static addresses and routes with ip (ie if addresses are not already on the machine). These addresses are NOT moved by vrrpd, they stay on the machine. If you already have IPs and routes on your machines and your machines can ping each other, you don't need this section.

  16. The whole string is fed to ip addr add. You can truncate the string anywhere you like and let ip addr add use defaults for the rest of the string. If you just feed the string "192.168.1.1", the IP will be 192.168.1.1/32, which you probably don't want. This is different to ifconfig which will configure the IP with the standard class, here 192.168.1.1/24. The minimum string then would be the IP/netmask, eg 192.168.1.1/24

  17. static_ipaddress { 192.168.1.1/24 brd + dev eth0 scope global ... }

  18. The whole string is fed to ip route add. You can truncate the string allowing ip route add to use defaults.

  19. static_routes { src $SRC_IP to $DST_IP dev $SRC_DEVICE ... src $SRC_IP to $DST_IP via $GW dev $SRC_DEVICE }
  20. Vrrpd Configuration

  21. contains subblocks of VRRP synchronization group(s) and VRRP instance(s)
  22. VRRP synchronization group(s)

  23. #string, name of group of IPs that failover together vrrp_sync_group VG_1 { group { inside_network # name of vrrp_instance (below) outside_network # One for each moveable IP. ... }

  24. # notify scripts and alerts are optional # # filenames of scripts to run on transitions # can be unquoted (if just filename) # or quoted (if has parameters) # to MASTER transition notify_master /path/to_master.sh # to BACKUP transition notify_backup /path/to_backup.sh # FAULT transition notify_fault "/path/fault.sh VG_1"

  25. # for ANY state transition. # "notify" script is called AFTER the # notify_* script(s) and is executed # with 3 arguments provided by keepalived # (ie don't include parameters in the notify line). # arguments # $1 = "GROUP"|"INSTANCE" # $2 = name of group or instance # $3 = target state of transition # ("MASTER"|"BACKUP"|"FAULT") notify /path/notify.sh

  26. # Send email notifcation during state transition, # using addresses in global_defs above. smtp_alert }
  27. VRRP instance(s)

  28. describes the moveable IP for each instance of a group in vrrp_sync_group. Here are described two IPs (on inside_network and on outside_network), on machine "my_hostname", which belong to the group VG_1 and which will transition together on any state change. #You will need to write another block for outside_network. vrrp_instance inside_network { # Initial state, MASTER|BACKUP # As soon as the other machine(s) come up, # an election will be held and the machine # with the highest "priority" will become MASTER. # So the entry here doesn't matter a whole lot. state MASTER

  29. # interface for inside_network, bound by vrrp interface eth0

  30. # Ignore VRRP interface faults (default unset) dont_track_primary

  31. # optional, monitor these as well. # go to FAULT state if any of these go down. track_interface { eth0 eth1 ... }

  32. #default IP for binding vrrpd is the primary IP #on interface. If you want to hide location of vrrpd, #use this IP as src_addr for multicast vrrp packets. #(since it's multicast, vrrpd will get the reply #packet no matter what src_addr is used). #optional mcast_src_ip <IPADDR>

  33. # Binding interface for lvs syncd lvs_sync_daemon_interface eth1

  34. # delay for gratuitous ARP after transition to MASTER garp_master_delay 10 # secs, default 5

  35. # arbitary unique number 0..255 # used to differentiate multiple instances of vrrpd # running on the same NIC (and hence same socket). virtual_router_id 51

  36. # for electing MASTER, highest priority wins. # to be MASTER, make 50 more than other machines. priority 100

  37. # VRRP Advert interval, secs (use default) advert_int 1 authentication { # Authentication block # PASS||AH # PASS - Simple Passwd (suggested) # AH - IPSEC (not recommended)) auth_type PASS # Password for accessing vrrpd. # should be the same for all machines. auth_pass 1234

  38. #addresses add|del on change to MASTER, to BACKUP. #With the same entries on other machines, #the opposite transition will be occuring. virtual_ipaddress { <IPADDR>/<MASK> brd <IPADDR> dev <STRING> scope <SCOPE> label <LABEL> 192.168.200.17/24 dev eth1 192.168.200.18/24 dev eth2 label eth2:1 }

  39. #VRRP IP excluded from VRRP #optional. #For cases with large numbers (eg 200) of IPs #on the same interface. To decrease the number #of packets sent in adverts, you can exclude #most IPs from adverts. #The IPs are add|del as for virtual_ipaddress. virtual_ipaddress_excluded { <IPADDR>/<MASK> brd <IPADDR> dev <STRING> scope <SCOPE> <IPADDR>/<MASK> brd <IPADDR> dev <STRING> scope <SCOPE> ... } # routes add|del when changing to MASTER, to BACKUP virtual_routes { # src <IPADDR> [to] <IPADDR>/<MASK> via|gw <IPADDR> dev <STRING> scope <SCOPE> tab src 192.168.100.1 to 192.168.109.0/24 via 192.168.200.254 dev eth1 192.168.110.0/24 via 192.168.200.254 dev eth1 192.168.111.0/24 dev eth2 192.168.112.0/24 via 192.168.100.254 }

  40. # VRRP will normally preempt a lower priority # machine when a higher priority machine comes # online. "nopreempt" allows the lower priority # machine to maintain the master role, even when # a higher priority machine comes back online. # NOTE: For this to work, the initial state of this # entry must be BACKUP. nopreempt

  41. # Seconds after startup until preemption # (if not disabled by "nopreempt"). # Range: 0 (default) to 1,000 # NOTE: For this to work, the initial state of this # entry must be BACKUP. preempt_delay 300 # waits 5 minutes

  42. # Debug level, not implemented yet. debug

  43. # notify scripts, alert as above notify_master <STRING>|<QUOTED-STRING> notify_backup <STRING>|<QUOTED-STRING> notify_fault <STRING>|<QUOTED-STRING> notify <STRING>|<QUOTED-STRING> smtp_alert }
  44. Lvs Configuration

  45. contains subblocks of Virtual server group(s) and Virtual server(s)

  46. The subblocks contain arguments for ipvsadm(8). A knowlege of ipvsadm(8) will be helpful here.
  47. Virtual server group(s)

  48. # optional # this groups allows a service on a real_server # to belong to multiple virtual services # and to be only health checked once. # Only for very large LVSs. virtual_server_group <STRING> { #VIP port <IPADDR> <PORT> <IPADDR> <PORT> ... # # <IPADDR RANGE> has the form # XXX.YYY.ZZZ.WWW-VVV eg 192.168.200.1-10 # range includes both .1 and .10 address <IPADDR RANGE> <PORT># VIP range VPORT <IPADDR RANGE> <PORT> ... fwmark <INT> # fwmark fwmark <INT> ... }
  49. Virtual server(s)

  50. A virtual_server can be a declaration of one of

  51. vip vport (IPADDR PORT pair)
  52. fwmark <INT>
  53. (virtual server) group <STRING>
  54.     #setup service virtual_server IP port | virtual_server fwmark int | virtual_server group string { # delay timer for service polling delay_loop <INT>

  55.     # LVS scheduler lb_algo rr|wrr|lc|wlc|lblc|sh|dh # LVS forwarding method lb_kind NAT|DR|TUN # LVS persistence timeout, sec persistence_timeout <INT> # LVS granularity mask (-M in ipvsadm) persistence_granularity <NETMASK> # Only TCP is implemented protocol TCP # If VS IP address is not set, # suspend healthchecker's activity ha_suspend

  56.     # VirtualHost string for HTTP_GET or SSL_GET # eg virtualhost www.firewall.loc virtualhost <STRING>

  57.     # Assume silently all RSs down and healthchecks # failed on start. This helps preventing false # positive actions on startup. Alpha mode is # disabled by default. alpha

  58.     # On daemon shutdown, consider quorum and RS # down notifiers for execution, where appropriate. # Omega mode is disabled by default. omega

  59.     # Minimum total weight of all live servers in # the pool necessary to operate VS with no # quality regression. Defaults to 1. quorum <INT>

  60.     # Tolerate this much weight units compared to the # nominal quorum, when considering quorum gain # or loss. A flap dampener. Defaults to 0. hysteresis <INT>

  61.     # Script to launch when quorum is gained. quorum_up <STRING>|<QUOTED-STRING>

  62.     # Script to launch when quorum is lost. quorum_down <STRING>|<QUOTED-STRING>

  63.     # setup realserver(s)

  64.     # RS to add when all realservers are down sorry_server <IPADDR> <PORT>

  65. # one entry for each realserver

  66.     real_server <IPADDR> <PORT> { # relative weight to use, default: 1 weight <INT> # Set weight to 0 # when healthchecker detects failure inhibit_on_failure
  67.     # Script to launch when healthchecker # considers service as up. notify_up <STRING>|<QUOTED-STRING> # Script to launch when healthchecker # considers service as down. notify_down <STRING>|<QUOTED-STRING>

  68.     # pick one healthchecker # HTTP_GET|SSL_GET|TCP_CHECK|SMTP_CHECK|MISC_CHECK

  69.     # HTTP and SSL healthcheckers HTTP_GET|SSL_GET { # A url to test # can have multiple entries here url { #eg path / , or path /mrtg2/ path <STRING> # healthcheck needs status_code # or status_code and digest # Digest computed with genhash # eg digest 9b3a0c85a887a256d6939da88aabd8cd digest <STRING> # status code returned in the HTTP header # eg status_code 200 status_code <INT> } #IP, tcp port for service on realserver connect_port <PORT> bindto <IPADDR> # Timeout connection, sec connect_timeout <INT> # number of get retry nb_get_retry <INT> # delay before retry delay_before_retry <INT> } #HTTP_GET|SSL_GET

  70.     #TCP healthchecker (bind to IP port) TCP_CHECK { connect_port <PORT> bindto <IPADDR> connect_timeout <INT> } #TCP_CHECK

  71.     # SMTP healthchecker SMTP_CHECK { # An optional host interface to check. # If no host directives are present, only # the ip address of the real server will # be checked. host { # IP address to connect to connect_ip <IP ADDRESS> # Optional port to connect to if not # the default of 25 connect_port <PORT> # Optional interface to use to # originate the connection bindto <IP ADDRESS> } # Connection and read/write timeout # in seconds connect_timeout <INTEGER> # Number of times to retry a failed check retry <INTEGER> # Delay in seconds before retrying delay_before_retry <INTEGER> # Optional string to use for the smtp HELO request helo_name <STRING>|<QUOTED-STRING> } #SMTP_CHECK

  72.     #MISC healthchecker, run a program MISC_CHECK { # External system script or program misc_path <STRING>|<QUOTED-STRING> # Script execution timeout misc_timeout <INT>

  73.     # If set, exit code from healthchecker is used # to dynamically adjust the weight as follows: # exit status 0: svc check success, weight # unchanged. # exit status 1: svc check failed. # exit status 2-255: svc check success, weight # changed to 2 less than exit status. # (for example: exit status of 255 would set # weight to 253) misc_dynamic } } # realserver defn } # virtual service

  74. Author

  75. Joseph Mack.
  76. Information derived from doc/keepalived.conf.SYNOPSIS, doc/samples/keepalived.conf.* and Changelog by Alexandre Cassen for keepalived-1.1.4, and from HOWTOs by Adam Fletcher and Vince Worthington.
  77. See Also

  78. ipvsadm(8), ip --help.
  79. Referenced By
  80. genhash(1), keepalived(8)
复制代码

论坛徽章:
0
8 [报告]
发表于 2011-11-18 13:27 |只看该作者
回复  ragecf


在主服务器上priority 100    那 备份服务上将100改为90或者50,搞成0 ?

在keepali ...
kns1024wh 发表于 2011-11-17 17:49


哥们,我一直说的是要求real server分主备,是靠weight设置的
您说的priority是用于direct server分主备的

论坛徽章:
0
9 [报告]
发表于 2011-11-18 14:09 |只看该作者
回复 8# ragecf


    realserver 一共几台要做主备。
   
  前段是lvs 的一个作用就是 realserver的健康检查 监控移除问题节点。
  
  如果要做realsever的主备 ,可以根据需要使用heartbeat,并且要发布浮动IP用作lvs的调度节点调用的realserver
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP