<!–
/*! normalize.css v3.0.1 | MIT License | git.io/normalize */

/**
* 1. Set default font family to sans-serif.
* 2. Prevent iOS text size adjust after orientation change, without disabling
* user zoom.
*/

html {
font-family: sans-serif; /* 1 */
-ms-text-size-adjust: 100%; /* 2 */
-webkit-text-size-adjust: 100%; /* 2 */
}

/**
* Remove default margin.
*/

body {
margin: 0;
}

/* HTML5 display definitions
========================================================================== */

/**
* Correct `block` display not defined for any HTML5 element in IE 8/9.
* Correct `block` display not defined for `details` or `summary` in IE 10/11 and Firefox.
* Correct `block` display not defined for `main` in IE 11.
*/

article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
main,
nav,
section,
summary {
display: block;
}

/**
* 1. Correct `inline-block` display not defined in IE 8/9.
* 2. Normalize vertical alignment of `progress` in Chrome, Firefox, and Opera.
*/

audio,
canvas,
progress,
video {
display: inline-block; /* 1 */
vertical-align: baseline; /* 2 */
}

/**
* Prevent modern browsers from displaying `audio` without controls.
* Remove excess height in iOS 5 devices.
*/

audio:not([controls]) {
display: none;
height: 0;
}

/**
* Address `[hidden]` styling not present in IE 8/9/10.
* Hide the `template` element in IE 8/9/11, Safari, and Firefox < 22.
*/

[hidden],
template {
display: none;
}

/* Links
========================================================================== */

/**
* Remove the gray background color from active links in IE 10.
*/

a {
background: transparent;
}

/**
* Improve readability when focused and also mouse hovered in all browsers.
*/

a:active,
a:hover {
outline: 0;
}

/* Text-level semantics
========================================================================== */

/**
* Address styling not present in IE 8/9/10/11, Safari, and Chrome.
*/

abbr[title] {
border-bottom: 1px dotted;
}

/**
* Address style set to `bolder` in Firefox 4+, Safari, and Chrome.
*/

b,
strong {
font-weight: bold;
}

/**
* Address styling not present in Safari and Chrome.
*/

dfn {
font-style: italic;
}

/**
* Address variable `h1` font-size and margin within `section` and `article`
* contexts in Firefox 4+, Safari, and Chrome.
*/

h1 {
font-size: 2em;
margin: 0.67em 0;
}

/**
* Address styling not present in IE 8/9.
*/

mark {
background: #ff0;
color: #000;
}

/**
* Address inconsistent and variable font size in all browsers.
*/

small {
font-size: 80%;
}

/**
* Prevent `sub` and `sup` affecting `line-height` in all browsers.
*/

sub,
sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline;
}

sup {
top: -0.5em;
}

sub {
bottom: -0.25em;
}

/* Embedded content
========================================================================== */

/**
* Remove border when inside `a` element in IE 8/9/10.
*/

img {
border: 0;
}

/**
* Correct overflow not hidden in IE 9/10/11.
*/

svg:not(:root) {
overflow: hidden;
}

/* Grouping content
========================================================================== */

/**
* Address margin not present in IE 8/9 and Safari.
*/

figure {
margin: 1em 40px;
}

/**
* Address differences between Firefox and other browsers.
*/

hr {
-moz-box-sizing: content-box;
box-sizing: content-box;
height: 0;
}

/**
* Contain overflow in all browsers.
*/

pre {
overflow: auto;
}

/**
* Address odd `em`-unit font size rendering in all browsers.
*/

code,
kbd,
pre,
samp {
font-family: monospace, monospace;
font-size: 1em;
}

/* Forms
========================================================================== */

/**
* Known limitation: by default, Chrome and Safari on OS X allow very limited
* styling of `select`, unless a `border` property is set.
*/

/**
* 1. Correct color not being inherited.
* Known issue: affects color of disabled elements.
* 2. Correct font properties not being inherited.
* 3. Address margins set differently in Firefox 4+, Safari, and Chrome.
*/

button,
input,
optgroup,
select,
textarea {
color: inherit; /* 1 */
font: inherit; /* 2 */
margin: 0; /* 3 */
}

/**
* Address `overflow` set to `hidden` in IE 8/9/10/11.
*/

button {
overflow: visible;
}

/**
* Address inconsistent `text-transform` inheritance for `button` and `select`.
* All other form control elements do not inherit `text-transform` values.
* Correct `button` style inheritance in Firefox, IE 8/9/10/11, and Opera.
* Correct `select` style inheritance in Firefox.
*/

button,
select {
text-transform: none;
}

/**
* 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio`
* and `video` controls.
* 2. Correct inability to style clickable `input` types in iOS.
* 3. Improve usability and consistency of cursor style between image-type
* `input` and others.
*/

button,
html input[type="button"], /* 1 */
input[type="reset"],
input[type="submit"] {
-webkit-appearance: button; /* 2 */
cursor: pointer; /* 3 */
}

/**
* Re-set default cursor for disabled elements.
*/

button[disabled],
html input[disabled] {
cursor: default;
}

/**
* Remove inner padding and border in Firefox 4+.
*/

button::-moz-focus-inner,
input::-moz-focus-inner {
border: 0;
padding: 0;
}

/**
* Address Firefox 4+ setting `line-height` on `input` using `!important` in
* the UA stylesheet.
*/

input {
line-height: normal;
}

/**
* It's recommended that you don't attempt to style these elements.
* Firefox's implementation doesn't respect box-sizing, padding, or width.
*
* 1. Address box sizing set to `content-box` in IE 8/9/10.
* 2. Remove excess padding in IE 8/9/10.
*/

input[type="checkbox"],
input[type="radio"] {
box-sizing: border-box; /* 1 */
padding: 0; /* 2 */
}

/**
* Fix the cursor style for Chrome's increment/decrement buttons. For certain
* `font-size` values of the `input`, it causes the cursor style of the
* decrement button to change from `default` to `text`.
*/

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
height: auto;
}

/**
* 1. Address `appearance` set to `searchfield` in Safari and Chrome.
* 2. Address `box-sizing` set to `border-box` in Safari and Chrome
* (include `-moz` to future-proof).
*/

input[type="search"] {
-webkit-appearance: textfield; /* 1 */
-moz-box-sizing: content-box;
-webkit-box-sizing: content-box; /* 2 */
box-sizing: content-box;
}

/**
* Remove inner padding and search cancel button in Safari and Chrome on OS X.
* Safari (but not Chrome) clips the cancel button when the search input has
* padding (and `textfield` appearance).
*/

input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-decoration {
-webkit-appearance: none;
}

/**
* Define consistent border, margin, and padding.
*/

fieldset {
border: 1px solid #c0c0c0;
margin: 0 2px;
padding: 0.35em 0.625em 0.75em;
}

/**
* 1. Correct `color` not being inherited in IE 8/9/10/11.
* 2. Remove padding so people aren't caught out if they zero out fieldsets.
*/

legend {
border: 0; /* 1 */
padding: 0; /* 2 */
}

/**
* Remove default vertical scrollbar in IE 8/9/10/11.
*/

textarea {
overflow: auto;
}

/**
* Don't inherit the `font-weight` (applied by a rule above).
* NOTE: the default cannot safely be changed in Chrome and Safari on OS X.
*/

optgroup {
font-weight: bold;
}

/* Tables
========================================================================== */

/**
* Remove most spacing between table cells.
*/

table {
border-collapse: collapse;
border-spacing: 0;
}

td,
th {
padding: 0;
}

/* mscore */
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
*:before,
*:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
html {
font-size: 62.5%;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
body {
/*font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;*/
font-family: 'Helvetica Neue', Helvetica, Arial, 'Microsoft Yahei', sans-serif;
font-size: 14px;
line-height: 1.42857143;
color: #333333;
}
input,
button,
select,
textarea {
font-family: inherit;
font-size: inherit;
line-height: inherit;
}
a {
color: #428bca;
text-decoration: none;
}
a:hover,
a:focus {
color: #2a6496;
text-decoration: underline;
}
a:focus {
outline: thin dotted;
outline: 5px auto -webkit-focus-ring-color;
outline-offset: -2px;
}
figure {
margin: 0;
}
img {
vertical-align: middle;
}

/*

github.com style (c) Vasily Polovnyov

*/

.hljs {
display: block;
overflow-x: auto;
padding: 0.5em;
color: #333;
background: #f8f8f8;
}

.hljs-comment,
.hljs-template_comment,
.diff .hljs-header,
.hljs-javadoc {
color: #998;
font-style: italic;
}

.hljs-keyword,
.css .rule .hljs-keyword,
.hljs-winutils,
.javascript .hljs-title,
.nginx .hljs-title,
.hljs-subst,
.hljs-request,
.hljs-status {
color: #333;
font-weight: bold;
}

.hljs-number,
.hljs-hexcolor,
.ruby .hljs-constant {
color: #099;
}

.hljs-string,
.hljs-tag .hljs-value,
.hljs-phpdoc,
.tex .hljs-formula {
color: #d14;
}

.hljs-title,
.hljs-id,
.coffeescript .hljs-params,
.scss .hljs-preprocessor {
color: #900;
font-weight: bold;
}

.javascript .hljs-title,
.lisp .hljs-title,
.clojure .hljs-title,
.hljs-subst {
font-weight: normal;
}

.hljs-class .hljs-title,
.haskell .hljs-type,
.vhdl .hljs-literal,
.tex .hljs-command {
color: #458;
font-weight: bold;
}

.hljs-tag,
.hljs-tag .hljs-title,
.hljs-rules .hljs-property,
.django .hljs-tag .hljs-keyword {
color: #000080;
font-weight: normal;
}

.hljs-attribute,
.hljs-variable,
.lisp .hljs-body {
color: #008080;
}

.hljs-regexp {
color: #009926;
}

.hljs-symbol,
.ruby .hljs-symbol .hljs-string,
.lisp .hljs-keyword,
.tex .hljs-special,
.hljs-prompt {
color: #990073;
}

.hljs-built_in,
.lisp .hljs-title,
.clojure .hljs-built_in {
color: #0086b3;
}

.hljs-preprocessor,
.hljs-pragma,
.hljs-pi,
.hljs-doctype,
.hljs-shebang,
.hljs-cdata {
color: #999;
font-weight: bold;
}

.hljs-deletion {
background: #fdd;
}

.hljs-addition {
background: #dfd;
}

.diff .hljs-change {
background: #0086b3;
}

.hljs-chunk {
color: #aaa;
}

#container {
padding: 15px;
}
pre {
border: 1px solid #ccc;
border-radius: 4px;
display: block;
background-color: #f8f8f8;
}
pre code {
white-space: pre-wrap;
}
.hljs,
code {
font-family: Monaco, Menlo, Consolas, ‘Courier New’, monospace;
}
:not(pre) > code {
padding: 2px 4px;
font-size: 90%;
color: #c7254e;
background-color: #f9f2f4;
white-space: nowrap;
border-radius: 4px;
}
–>

KeepAlived系列文章:http://www.cnblogs.com/f-ck-need-u/p/7576137.html


本文目录:
1. keepalived+lvs:健康状况检查示例
2. keepalived+lvs:高可用+健康检查示例
3. keepalived+lvs:多实例+高可用(双主)
4. 提供sorry server和local RS

 

本文只给出几个keepalived+lvs的配置示例,关于keepalived的配置文件说明见:高可用之KeepAlived(一):基本概念和配置文件分析

在实验开始前,需要说明几点:

  1. 使用keepalived配置lvs的VS/DR模式时,vip建议绑定在别名接口上。如果VIP使用单独的网卡,在lvs的高可用问题上就会出现问题:使用独立网卡配置VIP的vrrp实例将总是master角色,除非它完全死机。
  2. 既然VIP要绑定在某个接口别名上,那么VIP必须和这个接口在同一网段,否则无法正确配置VIP相关的路由。因此对于keepalived+lvs来说,VIP和rip应该设置在同一网段。除非已经考虑清楚不使用vrrp的高可用功能,这样VIP不用绑定在网卡别名上,也就可以和rip在不同网段。
  3. 既然VIP和RIP在同一网段,那么内网路由器上就无需设置rp_filter。

1.keepalived+lvs:健康状况检查示例

使用DR模式测试,实验环境如下:

RS上操作:

yum -y install httpd
echo "rs1:192.168.100.49" > /var/www/html/index.html  # RS1上操作
echo "rs1:192.168.100.50" > /var/www/html/index.html  # RS2上操作
service httpd start

echo 1 >/proc/sys/net/ipv4/conf/all/arp_ignore
echo 2 >/proc/sys/net/ipv4/conf/all/arp_announce

ifconfig lo:0 192.168.100.10/32 up
route add -host 192.168.100.10 dev lo

route add default gw 192.168.100.51

Router上操作:

echo 1 >/proc/sys/net/ipv4/ip_forward

Director上操作:

[root@xuexi ~]# route del default
[root@xuexi ~]# route add default gw 192.168.100.51
[root@xuexi ~]# cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
[root@xuexi ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   router_id LVS_1
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 12345678
    }
    virtual_ipaddress {
        192.168.100.10/32 dev eth0 label eth0:0
    }
}

virtual_server 192.168.100.10 80 {
        delay_loop 6
        lb_algo wrr
        lb_kind DR
        protocol TCP

        real_server 192.168.100.49 80 {
                weight 2
                TCP_CHECK {
                        connect_port 80
                        connect_timeout 1
                        nb_get_retry 2
                        delay_before_retry 1
                }
        }

        real_server 192.168.100.50 80 {
                weight 1
                TCP_CHECK {
                        connect_port 80
                        connect_timeout 1
                        nb_get_retry 2
                        delay_before_retry 1
                }
        }
}

测试是否能实现连接的负载均衡。

2.keepalived+lvs:高可用+健康检查示例

KeepAlived通过vrrp的冗余路由切换协议实现高可用功能,主要用于lvs Director的高可用。

在配置KeepAlived高可用功能时,需要注意以下几点:

  1. 两台(或多台)Director上的vrrp实例名称要一致,vrid(virtual_router_id)要一致,认证机制以及认证密码要一致,global定义的服务器标识router_id不能一致。
  2. 不同机器上的优先级priority的值不能一致。priority直接决定谁是master,谁是backup,而无论vrrp实例的state值是MASTER还是BACKUP。
  3. VIP不能使用独立的网卡,而应该绑定在别名接口上。如果使用独立的网卡地址作为VIP,则这个vrrp实例将总是master角色,直至它死机或者该网卡down掉。
  4. keepalived的vrrp组件不依赖于lvs,它可以独立提供高可用服务。

实验环境如下:

RS1、RS2、Router、director_lvs(master)和前文实验的配置一致,不需修改。因此,只需提供director_lvs(backup)的配置文件即可。

以下是master上的操作。

[root@xuexi ~]# route del default
[root@xuexi ~]# route add default gw 192.168.100.51
[root@xuexi ~]# cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
[root@xuexi ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   router_id LVS_2           # 和master不同
}

vrrp_instance VI_1 {         # 和master相同
    state BACKUP             # 和master不同
    interface eth0
    virtual_router_id 51     # 和master相同
    priority 50              # 和maste不同
    advert_int 1
    authentication {
        auth_type PASS       # 和master相同
        auth_pass 12345678   # 和master相同
    }
    virtual_ipaddress {
        192.168.100.10/32 dev eth0 label eth0:0
    }
}

virtual_server 192.168.100.10 80 {
        delay_loop 6
        lb_algo wrr
        lb_kind DR
        protocol TCP

        real_server 192.168.100.49 80 {
                weight 2
                TCP_CHECK {
                        connect_port 80
                        connect_timeout 1
                        nb_get_retry 2
                        delay_before_retry 1
                }
        }

        real_server 192.168.100.50 80 {
                weight 1
                TCP_CHECK {
                        connect_port 80
                        connect_timeout 1
                        nb_get_retry 2
                        delay_before_retry 1
                }
        }
}

启动两Director,查看是否只有master上设置了VIP。注意:ipvs规则在master和backup上都设置了,但由于backup没有VIP,因此backup设置的ipvs规则暂时是没有意义的。当backup切换为master状态时,只会设置VIP。

然后查看master是否已经生效。生效后,将master断开。观察原来的backup切换为master的日志:

Mar  1 20:52:19 xuexi Keepalived_vrrp[4709]: VRRP_Instance(VI_1) Transition to MASTER STATE
Mar  1 20:52:20 xuexi Keepalived_vrrp[4709]: VRRP_Instance(VI_1) Entering MASTER STATE
Mar  1 20:52:20 xuexi Keepalived_vrrp[4709]: VRRP_Instance(VI_1) setting protocol VIPs.
Mar  1 20:52:20 xuexi Keepalived_vrrp[4709]: Sending gratuitous ARP on eth0 for 192.168.100.10
Mar  1 20:52:20 xuexi Keepalived_vrrp[4709]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on eth0 for 192.168.100.10
Mar  1 20:52:20 xuexi Keepalived_vrrp[4709]: Sending gratuitous ARP on eth0 for 192.168.100.10
Mar  1 20:52:20 xuexi Keepalived_vrrp[4709]: Sending gratuitous ARP on eth0 for 192.168.100.10
Mar  1 20:52:20 xuexi Keepalived_vrrp[4709]: Sending gratuitous ARP on eth0 for 192.168.100.10
Mar  1 20:52:20 xuexi Keepalived_vrrp[4709]: Sending gratuitous ARP on eth0 for 192.168.100.10
Mar  1 20:52:25 xuexi Keepalived_vrrp[4709]: Sending gratuitous ARP on eth0 for 192.168.100.10
Mar  1 20:52:25 xuexi Keepalived_vrrp[4709]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on eth0 for 192.168.100.10
Mar  1 20:52:25 xuexi Keepalived_vrrp[4709]: Sending gratuitous ARP on eth0 for 192.168.100.10
Mar  1 20:52:25 xuexi Keepalived_vrrp[4709]: Sending gratuitous ARP on eth0 for 192.168.100.10
Mar  1 20:52:25 xuexi Keepalived_vrrp[4709]: Sending gratuitous ARP on eth0 for 192.168.100.10
Mar  1 20:52:25 xuexi Keepalived_vrrp[4709]: Sending gratuitous ARP on eth0 for 192.168.100.10

可以看到,切换速度极快(1秒以内)。

再测试将原来的master(高优先级)启动,发现它再次成为master,切换速度也是极快。

将RS1上的httpd停止。再查看主、备director上的ipvs规则。

[root@xuexi ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.100.10:80 wrr
  -> 192.168.100.50:80            Route   1      0          0

发现master和backup两边都把不健康的RealServer1节点给踢出去了。由此可以知道,健康检查是master和backup都会循环进行的,并不是只有master进行检查。

再将RS1上的httpd启动。然后查看ipvs规则。发现没过几秒钟就把规则添加回来了。

3.keepalived+lvs:多实例+高可用(双主)

keepalive的vrrp多实例可以管理多个director和vip,进而可以实现”双主模型”的高可用。

实验环境如下图:

其中Director1的vrrp实例1上是R1的master,vrrp实例2是R2的backup,Director2的vrrp实例1是R1的backup,vrrp实例2是R2的master。

这里略过4个RS的配置步骤(如有问题,参照前文配置RS1、RS2的过程)。

以下是Director1和Director2的keepalived.conf不同部分和相同部分的内容:

# 以下是两台Director上相同部分的内容
! Configuration File for keepalived                |! Configuration File for keepalived
                                                   |
global_defs {                                      |global_defs {
   router_id LVS_1                                 |   router_id LVS_2           
}                                                  |}
                                                   |
vrrp_instance VI_1 {                               |vrrp_instance VI_1 {         
    state MASTER                                   |    state BACKUP             
    interface eth0                                 |    interface eth0
    virtual_router_id 51                           |    virtual_router_id 51     
    priority 100                                   |    priority 50              
    advert_int 1                                   |    advert_int 1
    authentication {                               |    authentication {
        auth_type PASS                             |        auth_type PASS       
        auth_pass 12345678                         |        auth_pass 12345678   
    }                                              |    }
    virtual_ipaddress {                            |    virtual_ipaddress {
        192.168.100.10/32 dev eth0 label eth0:0    |        192.168.100.10/32 dev eth0 label eth0:0
    }                                              |    }
}                                                  |}
# 不同vrrp实例绑定在同一接口上,vrid必须不能相同        |# 不同vrrp实例绑定在同一接口上,vrid必须不能相同
vrrp_instance VI_2 {                               |vrrp_instance VI_2 {         
    state BACKUP                                   |    state MASTER             
    interface eth0                                 |    interface eth0
    virtual_router_id 55                           |    virtual_router_id 55     
    priority 50                                    |    priority 100              
    advert_int 1                                   |    advert_int 1
    authentication {                               |    authentication {
        auth_type PASS                             |        auth_type PASS       
        auth_pass 12345678                         |        auth_pass 12345678   
    }                                              |    }
    virtual_ipaddress {                            |    virtual_ipaddress {
        192.168.100.11/32 dev eth0 label eth0:1    |        192.168.100.11/32 dev eth0 label eth0:1
    }                                              |    }
}                                                  |}
#########################################################################################
# 以下是两台Director上相同部分的内容
virtual_server 192.168.100.10 80 {
        delay_loop 6
        lb_algo wrr
        lb_kind DR
        protocol TCP

        real_server 192.168.100.49 80 {
                weight 2
                TCP_CHECK {
                        connect_port 80
                        connect_timeout 1
                        nb_get_retry 2
                        delay_before_retry 1
                }
        }

        real_server 192.168.100.50 80 {
                weight 1
                TCP_CHECK {
                        connect_port 80
                        connect_timeout 1
                        nb_get_retry 2
                        delay_before_retry 1
                }
        }
}

virtual_server 192.168.100.11 80 {
        delay_loop 6
        lb_algo wrr
        lb_kind DR
        protocol TCP

        real_server 192.168.100.57 80 {
                weight 2
                TCP_CHECK {
                        connect_port 80
                        connect_timeout 1
                        nb_get_retry 2
                        delay_before_retry 1
                }
        }

        real_server 192.168.100.58 80 {
                weight 1
                TCP_CHECK {
                        connect_port 80
                        connect_timeout 1
                        nb_get_retry 2
                        delay_before_retry 1
                }
        }
}

分别测试访问两个VIP:http://192.168.100.10http://192.168.100.11。其中前者目前只能调度R1:RS1和R1:RS2,后者只能调度R2:RS1和R2:RS2。将任一Director断开,测试4个RS是否仍能继续提供服务。

4.提供sorry server和local RS

如果所有RS都宕了,对于外界来说就真的无法再访问网站了,这显然不适合。这时可以通过keepalived来配置一个服务页面。例如告诉外界客户端网站正在维护状态,或者只提供一个网站的一个主页面。

一般来说,因为是在所有RS都宕机的情况下sorry server提供的临时服务才生效,因此通常将sorry server配置在virtual_server中而非real_server中。

配置时,只需在keepalived配置文件的virtual_server段落中添加sorry_server指令即可。并且,如果启用了vrrp的高可用,应该在master和backup节点上都加上sorry server。

virtual_server 192.168.100.10 80 {
        delay_loop 6
        lb_algo wrr
        lb_kind DR
        protocol TCP

        sorry_server 127.0.0.1 80

重启keepalived后,再在每个vrrp机器上配置好httpd。

yum -y install httpd
echo "web Maintenancing" >/var/www/html/index.html
service httpd start

然后将所有的RS节点的httpd服务停掉。再看keepalived上的ipvs规则,发现已经将VIP作为规则添加进来了,于是下次访问VIP时将调度这台sorry server。当某一台RS恢复的时候,ipvs规则又会变更为RS的节点。

对于集群系统不大的情况下,LVS Director一般会比较空闲,这样就比较浪费资源。这时通常会将LVS Director自身也作为一个RS,一边提供web服务,一边提供调度功能,不过应该将它的调度权重设置低一点,以免影响负载均衡的性能。这称为local RS,local RS的RIP可以写Director上的任意地址(127.0.0.1都可以)。例如:

real_server 127.0.0.1 80 {
        weight 1
        TCP_CHECK {
                connect_port 80
                connect_timeout 1
                nb_get_retry 2
                delay_before_retry 1
        }
}

local RS和sorry server不应该同时设置,因为如果local RS坏了,sorry server肯定无法被调度到。

 

回到Linux系列文章大纲:http://www.cnblogs.com/f-ck-need-u/p/7048359.html

回到网站架构系列文章大纲:http://www.cnblogs.com/f-ck-need-u/p/7576137.html


回到数据库系列文章大纲:http://www.cnblogs.com/f-ck-need-u/p/7586194.html


转载请注明出处:http://www.cnblogs.com/f-ck-need-u/p/8492298.html

注:若您觉得这篇文章还不错请点击右下角推荐,您的支持能激发作者更大的写作热情,非常感谢!

版权声明:本文为f-ck-need-u原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/f-ck-need-u/p/8492298.html